[PATCHv2] devicetree: bindings: document lsi,zevio-usb

2014-03-05 Thread dt . tangr
From: Daniel Tang 


Signed-off-by: Daniel Tang 
---
 .../devicetree/bindings/usb/ci-hdrc-zevio.txt |   17 +
 1 file changed, 17 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/usb/ci-hdrc-zevio.txt

diff --git a/Documentation/devicetree/bindings/usb/ci-hdrc-zevio.txt 
b/Documentation/devicetree/bindings/usb/ci-hdrc-zevio.txt
new file mode 100644
index 000..abbcb2a
--- /dev/null
+++ b/Documentation/devicetree/bindings/usb/ci-hdrc-zevio.txt
@@ -0,0 +1,17 @@
+* LSI Zevio USB OTG Controller
+
+Required properties:
+- compatible: Should be "lsi,zevio-usb"
+- reg: Should contain registers location and length
+- interrupts: Should contain controller interrupt
+
+Optional properties:
+- vbus-supply: regulator for vbus
+
+Examples:
+   usb0: usb@b000 {
+   reg = <0xb000 0x1000>;
+   compatible = "lsi,zevio-usb";
+   interrupts = <8>;
+   vbus-supply = <&vbus_reg>;
+   };
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH RESEND] arm: nspire: modify device tree to use the lsi,zevio-usb driver

2014-03-05 Thread dt . tangr
From: Daniel Tang 


Signed-off-by: Daniel Tang 
---
 arch/arm/boot/dts/nspire.dtsi |1 +
 1 file changed, 1 insertion(+)

diff --git a/arch/arm/boot/dts/nspire.dtsi b/arch/arm/boot/dts/nspire.dtsi
index a22ffe6..012c6d1 100644
--- a/arch/arm/boot/dts/nspire.dtsi
+++ b/arch/arm/boot/dts/nspire.dtsi
@@ -65,6 +65,7 @@
};
 
usb0: usb@B000 {
+   compatible = "lsi,zevio-usb";
reg = <0xB000 0x1000>;
interrupts = <8>;
};
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


RE: [PATCH v7 3/4] phy: Add new Exynos USB 2.0 PHY driver

2014-03-05 Thread Kamil Debski
Hi Sander,

> From: Kamil Debski [mailto:k.deb...@samsung.com]
> Sent: Tuesday, March 04, 2014 4:24 PM
> 
> Add a new driver for the Exynos USB 2.0 PHY. The new driver uses the
> generic PHY framework. The driver includes support for the Exynos 4210
> and 4x12 SoC families.
> 
> Signed-off-by: Kamil Debski 

Sander, you did test the v6 of this patch, thus I am adding your
"Tested-by".
Could you confirm that this version works as well?

Tested-by: Sander Hollaar 

Best wishes,
-- 
Kamil Debski
Samsung R&D Institute Poland

> ---
>  .../devicetree/bindings/phy/samsung-phy.txt|   53 
>  Documentation/phy/samsung-usb2.txt |  134 
>  drivers/phy/Kconfig|   29 ++
>  drivers/phy/Makefile   |3 +
>  drivers/phy/phy-exynos4210-usb2.c  |  262
> 
>  drivers/phy/phy-exynos4x12-usb2.c  |  330
> 
>  drivers/phy/phy-samsung-usb2.c |  223
> +
>  drivers/phy/phy-samsung-usb2.h |   67 
>  8 files changed, 1101 insertions(+)
>  create mode 100644 Documentation/phy/samsung-usb2.txt
>  create mode 100644 drivers/phy/phy-exynos4210-usb2.c  create mode
> 100644 drivers/phy/phy-exynos4x12-usb2.c  create mode 100644
> drivers/phy/phy-samsung-usb2.c  create mode 100644 drivers/phy/phy-
> samsung-usb2.h
> 
> diff --git a/Documentation/devicetree/bindings/phy/samsung-phy.txt
> b/Documentation/devicetree/bindings/phy/samsung-phy.txt
> index c0fccaa..bf955ab 100644
> --- a/Documentation/devicetree/bindings/phy/samsung-phy.txt
> +++ b/Documentation/devicetree/bindings/phy/samsung-phy.txt
> @@ -20,3 +20,56 @@ Required properties:
>  - compatible : should be "samsung,exynos5250-dp-video-phy";
>  - reg : offset and length of the Display Port PHY register set;
>  - #phy-cells : from the generic PHY bindings, must be 0;
> +
> +Samsung S5P/EXYNOS SoC series USB PHY
> +-
> +
> +Required properties:
> +- compatible : should be one of the listed compatibles:
> + - "samsung,exynos4210-usb2-phy"
> + - "samsung,exynos4x12-usb2-phy"
> +- reg : a list of registers used by phy driver
> + - first and obligatory is the location of phy modules registers
> +- samsung,sysreg-phandle - handle to syscon used to control the system
> +registers
> +- samsung,pmureg-phandle - handle to syscon used to control PMU
> +registers
> +- #phy-cells : from the generic phy bindings, must be 1;
> +- clocks and clock-names:
> + - the "phy" clock is required by the phy module, used as a gate
> + - the "ref" clock is used to get the rate of the clock provided
> to the
> +   PHY module
> +
> +The first phandle argument in the PHY specifier identifies the PHY,
> its
> +meaning is compatible dependent. For the currently supported SoCs
> +(Exynos 4210 and Exynos 4212) it is as follows:
> +  0 - USB device ("device"),
> +  1 - USB host ("host"),
> +  2 - HSIC0 ("hsic0"),
> +  3 - HSIC1 ("hsic1"),
> +
> +Exynos 4210 and Exynos 4212 use mode switching and require that mode
> +switch register is supplied.
> +
> +Example:
> +
> +For Exynos 4412 (compatible with Exynos 4212):
> +
> +usbphy: phy@125b {
> + compatible = "samsung,exynos4x12-usb2-phy";
> + reg = <0x125b 0x100>;
> + clocks = <&clock 305>, <&clock 2>;
> + clock-names = "phy", "ref";
> + status = "okay";
> + #phy-cells = <1>;
> + samsung,sysreg-phandle = <&sys_reg>;
> + samsung,pmureg-phandle = <&pmu_reg>;
> +};
> +
> +Then the PHY can be used in other nodes such as:
> +
> +phy-consumer@1234 {
> + phys = <&usbphy 2>;
> + phy-names = "phy";
> +};
> +
> +Refer to DT bindings documentation of particular PHY consumer devices
> +for more information about required PHYs and the way of specification.
> diff --git a/Documentation/phy/samsung-usb2.txt
> b/Documentation/phy/samsung-usb2.txt
> new file mode 100644
> index 000..0c8e260
> --- /dev/null
> +++ b/Documentation/phy/samsung-usb2.txt
> @@ -0,0 +1,134 @@
> +.-
> -
> ++
> +|Samsung USB 2.0 PHY adaptation layer
> |
> ++-
> +'
> +
> +| 1. Description
> ++
> +
> +The architecture of the USB 2.0 PHY module in Samsung SoCs is similar
> +among many SoCs. In spite of the similarities it proved difficult to
> +create a one driver that would fit all these PHY controllers. Often
> the
> +differences were minor and were found in particular bits of the
> +registers of the PHY. In some rare cases the order of register writes
> +or the PHY powering up process had to be altered. This adaptation
> layer
> +is a compromise between having separate drivers and having a single
> +driver with added support for many special cases.
> +
> +| 2. Files description
> ++

Re: [PATCH v3 07/13] usb: chipidea: add OTG fsm operation functions implemenation.

2014-03-05 Thread Peter Chen
On Thu, Feb 27, 2014 at 07:38:25AM +0800, Li Jun wrote:
> Add OTG HNP and SRP operation functions implementation:
> - charge vbus
> - drive vbus
> - connection signaling
> - drive sof
> - start data pulse
> - add fsm timer
> - delete fsm timer
> - start host
> - start gadget
> 
> Signed-off-by: Li Jun 
> ---
>  drivers/usb/chipidea/bits.h|   11 ++
>  drivers/usb/chipidea/ci.h  |1 +
>  drivers/usb/chipidea/otg_fsm.c |  231 
> 
>  drivers/usb/chipidea/otg_fsm.h |   23 
>  4 files changed, 266 insertions(+)
> 
> diff --git a/drivers/usb/chipidea/bits.h b/drivers/usb/chipidea/bits.h
> index 83d06c1..c42eb35 100644
> --- a/drivers/usb/chipidea/bits.h
> +++ b/drivers/usb/chipidea/bits.h
> @@ -44,9 +44,14 @@
>  #define DEVICEADDR_USBADR (0x7FUL << 25)
>  
>  /* PORTSC */
> +#define PORTSC_CCSBIT(0)
> +#define PORTSC_CSCBIT(1)
> +#define PORTSC_PECBIT(3)
> +#define PORTSC_OCCBIT(5)
>  #define PORTSC_FPRBIT(6)
>  #define PORTSC_SUSP   BIT(7)
>  #define PORTSC_HSPBIT(9)
> +#define PORTSC_PP BIT(12)
>  #define PORTSC_PTC(0x0FUL << 16)
>  #define PORTSC_PHCD(d) ((d) ? BIT(22) : BIT(23))
>  /* PTS and PTW for non lpm version only */
> @@ -56,6 +61,9 @@
>  #define PORTSC_PTWBIT(28)
>  #define PORTSC_STSBIT(29)
>  
> +#define PORTSC_W1C_BITS  \
> + (PORTSC_CSC | PORTSC_PEC | PORTSC_OCC)
> +
>  /* DEVLC */
>  #define DEVLC_PFSCBIT(23)
>  #define DEVLC_PSPD(0x03UL << 25)
> @@ -71,7 +79,10 @@
>  #define PTS_HSIC  4
>  
>  /* OTGSC */
> +#define OTGSC_VD   BIT(0)
> +#define OTGSC_VC   BIT(1)
>  #define OTGSC_IDPU BIT(5)
> +#define OTGSC_HADP BIT(6)
>  #define OTGSC_ID   BIT(8)
>  #define OTGSC_AVV  BIT(9)
>  #define OTGSC_ASV  BIT(10)
> diff --git a/drivers/usb/chipidea/ci.h b/drivers/usb/chipidea/ci.h
> index db6bf30..171b1d2 100644
> --- a/drivers/usb/chipidea/ci.h
> +++ b/drivers/usb/chipidea/ci.h
> @@ -175,6 +175,7 @@ struct ci_hdrc {
>   enum ci_rolerole;
>   boolis_otg;
>   struct otg_fsm  *fsm;
> + struct ci_otg_fsm_timer_list*fsm_timer;
>   struct work_struct  work;
>   struct workqueue_struct *wq;
>  
> diff --git a/drivers/usb/chipidea/otg_fsm.c b/drivers/usb/chipidea/otg_fsm.c
> index 904381e..aa24466 100644
> --- a/drivers/usb/chipidea/otg_fsm.c
> +++ b/drivers/usb/chipidea/otg_fsm.c
> @@ -18,12 +18,242 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  
>  #include "ci.h"
>  #include "bits.h"
>  #include "otg.h"
>  #include "otg_fsm.h"
>  
> +/* Add timer to active timer list */
> +static void ci_otg_add_timer(struct ci_hdrc *ci, enum ci_otg_fsm_timer_index 
> t)
> +{
> + struct ci_otg_fsm_timer *tmp_timer;
> + struct ci_otg_fsm_timer *timer = ci->fsm_timer->timer_list[t];
> + struct list_head *active_timers = &ci->fsm_timer->active_timers;
> +
> + if (t >= NUM_CI_OTG_FSM_TIMERS)
> + return;
> +
> + /*
> +  * Check if the timer is already in the active list,
> +  * if so update timer count
> +  */
> + list_for_each_entry(tmp_timer, active_timers, list)
> + if (tmp_timer == timer) {
> + timer->count = timer->expires;
> + return;
> + }
> +
> + timer->count = timer->expires;
> + list_add_tail(&timer->list, active_timers);
> +
> + /* Enable 1ms irq */
> + if (!(hw_read(ci, OP_OTGSC, OTGSC_1MSIE)))
> + ci_enable_otg_interrupt(ci, OTGSC_1MSIE);
> +}
> +
> +/* Remove timer from active timer list */
> +static void ci_otg_del_timer(struct ci_hdrc *ci, enum ci_otg_fsm_timer_index 
> t)
> +{
> + struct ci_otg_fsm_timer *tmp_timer, *del_tmp;
> + struct ci_otg_fsm_timer *timer = ci->fsm_timer->timer_list[t];
> + struct list_head *active_timers = &ci->fsm_timer->active_timers;
> + int flag = 0;
> +
> + if (t >= NUM_CI_OTG_FSM_TIMERS)
> + return;
> +
> + list_for_each_entry_safe(tmp_timer, del_tmp, active_timers, list)
> + if (tmp_timer == timer) {
> + list_del(&timer->list);
> + flag = 1;
> + }
> +
> + /* Disable 1ms irq if there is no any active timer */
> + if ((flag == 1) && list_empty(active_timers))
> + ci_disable_otg_interrupt(ci, OTGSC_1MSIE);
> +}

Why variable flag is needed?

> +
> +/* -*/
> +/* Operations that will be called from OTG Finite State Machine */
> +/* -*/
> +static void ci_otg_fsm_add_timer(struct otg_fsm *fsm, enum otg_fsm_timer t)
> +{
> + struct ci_hdrc  *ci = container_of(

RE: ax88179_178a problems on AMD platform with ASMedia xhci controller

2014-03-05 Thread David Laight
From: Of David Laight
> I've just installed the latest 3.14.0-rc5 kernel on an AMD box that
> has the ASMedia 1042 xhci controller and an ASX ax88179 USB3 Ge card.
> 
> This is still working as badly as it did last time I tried it.
> (When I added a lot of diagnostics to try to find out what was wrong.)
> 
> When I ran 'ifconfig eth1 192.168.x.x' the kernel message buffer
> is spammed with messages from the generic ethernet code reporting:
> "kevent 4 may have been missed".
> This is because ax88179_status(...) contains:
>   if (netif_carrier_ok() != link) {
>   usbnet_link_change(...);
>   ...
> but the corresponding netif_carrier_on() doesn't happen until
> much later (possibly for the same reason that transmits are delayed).

Actually I remember debugging that.
The problem seemed to be that the controller only actions one control
transfer each time the doorbell was rung.
I didn't get as far as re-ringing the bell in the completion routine.
Doing so might make it work a lot better.

> I think the hardware reports its status every 128ms.
> 
> If I ping the interface (from the only other system on that ethernet
> network), the ping times vary, but are typically larger than 20ms and
> anything upto 200ms (some outward ones are faster).
> I did add some diagnostics a while ago (rc2 ish) and thought the delays
> were in the transmit path.
> 
> dmesg also gets spammed with "ERROR Transfer event TRB DMA ptr not part of
> current TD". I don't remember looking at why (for this case).
> 
> I've just looked t the ping timings closely. The elapsed times (ms) are:
> 7, 30, 53, 76, 99, 122, 18, 41, 64, 87, 110, 5, 28 ...
> So each response is about 22ms later than the previous on - until the delay
> would exceed 128ms, when 128ms is removed.
> So something is only looking at something every 128ms.
> 
> This might be related to the status indications every 128ms, but I
> thought I'd determined that the delay was between the tx setup and
> end of tx interrupt.

It might be that the wrong doorbell is being rung.
Maybe the 'tx' doorbell is actually rung when the rx interrupt packet
is resupplied in response to the 128ms status poll.

David




--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


BUG: USB Reset-Resume Mechanism does not work for runtime resume

2014-03-05 Thread Poulain, Loic
Hi,

I think there is an issue with the reset-resume mechanism during USB runtime 
resume, leaving the interfaces suspended forever.

- Context:

Android platform, running a 3.13 + Google AOSP patches kernel.
I'm facing a USB issue with the bsusb driver. btusb driver has the USB runtime 
suspend enabled + remote wakeup.
However sometimes the USB runtime resume does not work as expected (we admit 
here that this can happen).

[ 3066.408413] usb 2-3: usb auto-resume
[ 3066.408433] hub 2-0:1.0: state 7 ports 9 chg  evt 0008
[ 3066.445465] usb 2-3: finish resume
[ 3071.447591] usb 2-3: bt_hc_worker timed out on ep0in len=0/2
[ 3071.447598] usb 2-3: retry with reset-resume

Then the usbcore tries a reset-resume, but btusb driver does not implement this 
callback.

[ 3071.619408] btusb 2-3:1.0: no reset_resume for driver btusb?
[ 3071.619413] btusb 2-3:1.1: no reset_resume for driver btusb?

However for driver which doesn't implement 'reset_resume' callback, usbcore 
plans to unbind/rebind it.
Here is the problem, because this never happens.


- What happens (in core/driver.c):

0. Need to wake-up the usb device for data transfer
1. 'usb_runtime_resume' is called  and calls 'usb_resume_both'
2.' usb_resume_both' calls 'usb_resume_device' then calls 
'usb_resume_interface' for each interface with the 'reset_resume' flag set 
(since resume failed).
3. 'usb_resume_interface' enters in the 'reset_resume' condition and sets the 
'needs_binding' interface flag.
4. At the end of this runtime resume, the interfaces stay suspended FOREVER.


- Why:

+ function 'do_rebind_interface' is in charge of unbind and rebind the 
interfaces with the 'need_binfind' flag set.
+ However this method is only called in 'usb_resume_complete'.
+ Problem is that 'usb_resume_complete' is a dev_pm_ops callback (core/usb.h) 
used by the System PM core which is never called in a runtime PM scenario.
+ So interfaces remain suspended forever (or until the next PM system 
suspend/resume), device is unusable.
(unbinding/rebinding manually the interface via sysfs recovers the device)

Could you please let me know if it's the expected behavior or a real issue. 
Should we not call 'do_rebind_interface' in the runtime resume sequence?

Thanks & Regards,
Loic Poulain
-
Intel Corporation SAS (French simplified joint stock company)
Registered headquarters: "Les Montalets"- 2, rue de Paris, 
92196 Meudon Cedex, France
Registration Number:  302 456 199 R.C.S. NANTERRE
Capital: 4,572,000 Euros

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: xhci-errors in combination with dm-crypt

2014-03-05 Thread Merlin Chlosta
On 04.03.2014 23:57, Sarah Sharp wrote:
> In a separate mail, you said 3.10.30-1-lts also works.  We do have one
> known regression for USB mass storage.  If you compile your own kernel,
> please retest with 3.14-rc4 with these two commits reverted:
> 
> 3804fad45411b48233b48003e33a78f290d227c8 "USBNET: ax88179_178a: enable tso if 
> usb host supports sg dma"
> 247bf557273dd775505fb9240d2d152f4f20d304 "xhci 1.0: Limit arbitrarily-aligned 
> scatter gather."
> 
> Please let me know if reverting those two commits worked.  If not, we'll
> dig deeper into exactly why your mass storage device is failing.
> 
> Sarah Sharp

It works with commit 247bf557273dd775505fb9240d2d152f4f20d304 reverted.

Thank you.

Merlin Chlosta
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 01/12] staging: usbip: userspace: migrate usbip_bind to libudev

2014-03-05 Thread Dan Carpenter
On Tue, Mar 04, 2014 at 09:10:41PM +0200, Valentina Manea wrote:
> diff --git a/drivers/staging/usbip/userspace/libsrc/usbip_common.h 
> b/drivers/staging/usbip/userspace/libsrc/usbip_common.h
> index 2cb81b3..565ac78 100644
> --- a/drivers/staging/usbip/userspace/libsrc/usbip_common.h
> +++ b/drivers/staging/usbip/userspace/libsrc/usbip_common.h
> @@ -29,6 +29,15 @@
>  #define USBIP_HOST_DRV_NAME  "usbip-host"
>  #define USBIP_VHCI_DRV_NAME  "vhci_hcd"
>  
> +/* sysfs constants */
> +#define SYSFS_MNT_PATH "/sys"
> +#define SYSFS_BUS_NAME "bus"
> +#define SYSFS_BUS_TYPE "usb"
> +#define SYSFS_DRIVERS_NAME "drivers"

What on earth???  I don't even want to review any further than this.

Groan  No.  no no no no no.

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 01/12] staging: usbip: userspace: migrate usbip_bind to libudev

2014-03-05 Thread Dan Carpenter
On Tue, Mar 04, 2014 at 09:10:41PM +0200, Valentina Manea wrote:

> +int write_sysfs_attribute(const char *attr_path, const char *new_value,
> +   size_t len)
> +{
> + int fd;
> + int length;
> +
> + if (attr_path == NULL || new_value == NULL || len == 0) {

Can any of these conditions be true?


> + dbg("Invalid values provided for attribute %s.", attr_path);
> + errno = EINVAL;
> + return -1;
> + }
> +
> + if ((fd = open(attr_path, O_WRONLY)) < 0) {

Move the assignment out of the condition.

> + dbg("Error opening attribute %s.", attr_path);
> + return -1;
> + }
> +
> + length = write(fd, new_value, len);
> + if (length < 0) {
> + dbg("Error writing to attribute %s.", attr_path);
> + close(fd);
> + return -1;
> + }
> +
> + close(fd);
> +
> + return 0;
> +}
> diff --git a/drivers/staging/usbip/userspace/src/sysfs_utils.h 
> b/drivers/staging/usbip/userspace/src/sysfs_utils.h
> new file mode 100644
> index 000..32ac1d1
> --- /dev/null
> +++ b/drivers/staging/usbip/userspace/src/sysfs_utils.h
> @@ -0,0 +1,8 @@
> +
> +#ifndef __SYSFS_UTILS_H
> +#define __SYSFS_UTILS_H
> +
> +int write_sysfs_attribute(const char *attr_path, const char *new_value,
> +   size_t len);
> +
> +#endif
> diff --git a/drivers/staging/usbip/userspace/src/usbip_bind.c 
> b/drivers/staging/usbip/userspace/src/usbip_bind.c
> index 8cfd2db..d122089 100644
> --- a/drivers/staging/usbip/userspace/src/usbip_bind.c
> +++ b/drivers/staging/usbip/userspace/src/usbip_bind.c
> @@ -16,7 +16,7 @@
>   * along with this program. If not, see .
>   */
>  
> -#include 
> +#include 
>  
>  #include 
>  #include 
> @@ -28,6 +28,7 @@
>  #include "usbip_common.h"
>  #include "utils.h"
>  #include "usbip.h"
> +#include "sysfs_utils.h"
>  
>  enum unbind_status {
>   UNBIND_ST_OK,
> @@ -48,135 +49,94 @@ void usbip_bind_usage(void)
>  /* call at unbound state */
>  static int bind_usbip(char *busid)
>  {
> - char bus_type[] = "usb";

Ok.  This code was already really stupid before this patch but now it's
even more idiotic.  Just put these things things directly into the
string instead of abstracting the abastractions of the abstract
abstractions.  Sheesh.

>   char attr_name[] = "bind";
> - char sysfs_mntpath[SYSFS_PATH_MAX];
>   char bind_attr_path[SYSFS_PATH_MAX];
> - struct sysfs_attribute *bind_attr;
> - int failed = 0;
> - int rc, ret = -1;
> -
> - rc = sysfs_get_mnt_path(sysfs_mntpath, SYSFS_PATH_MAX);
> - if (rc < 0) {
> - err("sysfs must be mounted: %s", strerror(errno));
> - return -1;
> - }
> + int rc = -1;

Don't do pointless assignments.  The compiler has builtin checks for
uninitialized variables but now you are turning the checks off and the
compiler can't do its job.

>  
>   snprintf(bind_attr_path, sizeof(bind_attr_path), "%s/%s/%s/%s/%s/%s",
> -  sysfs_mntpath, SYSFS_BUS_NAME, bus_type, SYSFS_DRIVERS_NAME,
> -  USBIP_HOST_DRV_NAME, attr_name);
> +  SYSFS_MNT_PATH, SYSFS_BUS_NAME, SYSFS_BUS_TYPE,
> +  SYSFS_DRIVERS_NAME, USBIP_HOST_DRV_NAME, attr_name);
> + dbg("bind attribute path: %s", bind_attr_path);

These dbg statements are totally pointless.  Just use strace.

>  
> - bind_attr = sysfs_open_attribute(bind_attr_path);
> - if (!bind_attr) {
> - dbg("problem getting bind attribute: %s", strerror(errno));
> - return -1;
> - }
> -
> - rc = sysfs_write_attribute(bind_attr, busid, SYSFS_BUS_ID_SIZE);
> + rc = write_sysfs_attribute(bind_attr_path, busid, strlen(busid));
>   if (rc < 0) {
> - dbg("bind driver at %s failed", busid);
> - failed = 1;
> + dbg("Error binding device %s to driver: %s", busid,
> + strerror(errno));

The temptation here would be to change the debug statement to an on by
default print statement.  The other option would be to just remove all
the debug statements.

Etc...  For the rest of this patch.  Remove abstraction levels and dead
code.

regards,
dan carpenter

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 04/14] usb: phy: msm: Fix checkpatch.pl warnings

2014-03-05 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

This fixes following:

WARNING: quoted string split across lines
WARNING: Prefer seq_puts to seq_printf

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c |   39 ++-
 1 file changed, 14 insertions(+), 25 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 4f4b0c6..beafe84 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -67,8 +67,7 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int 
init)
USB_PHY_VDD_DIG_VOL_MIN,
USB_PHY_VDD_DIG_VOL_MAX);
if (ret) {
-   dev_err(motg->phy.dev, "unable to set the voltage "
-   "for hsusb vddcx\n");
+   dev_err(motg->phy.dev, "Cannot set vddcx voltage\n");
return ret;
}

@@ -79,8 +78,7 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int 
init)
ret = regulator_set_voltage(motg->vddcx, 0,
USB_PHY_VDD_DIG_VOL_MAX);
if (ret)
-   dev_err(motg->phy.dev, "unable to set the voltage "
-   "for hsusb vddcx\n");
+   dev_err(motg->phy.dev, "Cannot set vddcx voltage\n");
ret = regulator_disable(motg->vddcx);
if (ret)
dev_err(motg->phy.dev, "unable to disable hsusb 
vddcx\n");
@@ -97,8 +95,7 @@ static int msm_hsusb_ldo_init(struct msm_otg *motg, int init)
rc = regulator_set_voltage(motg->v3p3, USB_PHY_3P3_VOL_MIN,
USB_PHY_3P3_VOL_MAX);
if (rc) {
-   dev_err(motg->phy.dev, "unable to set voltage level "
-   "for hsusb 3p3\n");
+   dev_err(motg->phy.dev, "Cannot set v3p3 voltage\n");
goto exit;
}
rc = regulator_enable(motg->v3p3);
@@ -109,8 +106,7 @@ static int msm_hsusb_ldo_init(struct msm_otg *motg, int 
init)
rc = regulator_set_voltage(motg->v1p8, USB_PHY_1P8_VOL_MIN,
USB_PHY_1P8_VOL_MAX);
if (rc) {
-   dev_err(motg->phy.dev, "unable to set voltage level "
-   "for hsusb 1p8\n");
+   dev_err(motg->phy.dev, "Cannot set v1p8 voltage\n");
goto disable_3p3;
}
rc = regulator_enable(motg->v1p8);
@@ -137,15 +133,13 @@ static int msm_hsusb_ldo_set_mode(struct msm_otg *motg, 
int on)
ret = regulator_set_optimum_mode(motg->v1p8,
USB_PHY_1P8_HPM_LOAD);
if (ret < 0) {
-   pr_err("%s: Unable to set HPM of the regulator "
-   "HSUSB_1p8\n", __func__);
+   pr_err("Could not set HPM for v1p8\n");
return ret;
}
ret = regulator_set_optimum_mode(motg->v3p3,
USB_PHY_3P3_HPM_LOAD);
if (ret < 0) {
-   pr_err("%s: Unable to set HPM of the regulator "
-   "HSUSB_3p3\n", __func__);
+   pr_err("Could not set HPM for v3p3\n");
regulator_set_optimum_mode(motg->v1p8,
USB_PHY_1P8_LPM_LOAD);
return ret;
@@ -154,13 +148,11 @@ static int msm_hsusb_ldo_set_mode(struct msm_otg *motg, 
int on)
ret = regulator_set_optimum_mode(motg->v1p8,
USB_PHY_1P8_LPM_LOAD);
if (ret < 0)
-   pr_err("%s: Unable to set LPM of the regulator "
-   "HSUSB_1p8\n", __func__);
+   pr_err("Could not set LPM for v1p8\n");
ret = regulator_set_optimum_mode(motg->v3p3,
USB_PHY_3P3_LPM_LOAD);
if (ret < 0)
-   pr_err("%s: Unable to set LPM of the regulator "
-   "HSUSB_3p3\n", __func__);
+   pr_err("Could not set LPM for v3p3\n");
}

pr_debug("reg (%s)\n", on ? "HPM" : "LPM");
@@ -390,8 +382,7 @@ static int msm_hsusb_config_vddcx(struct msm_otg *motg, int 
high)

ret = regulator_set_voltage(motg->vddcx, min_vol, max_vol);
if (ret) {
-   pr_err("%s: unable to set the voltage for regulator "
-   "HSUSB_VDDCX\n", __func__);
+   dev_err(motg->phy.dev, "Cannot set vddcx voltage\n");
return ret;
}

@@ -546,8 +537,7 @@ static int msm_otg_resume(struct msm_otg *motg)
 * PHY. USB sta

[PATCH v5 01/14] usb: phy: msm: Move global regulators variables to driver state

2014-03-05 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c |   82 -
 include/linux/usb/msm_hsusb.h |3 ++
 2 files changed, 42 insertions(+), 43 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index d204f74..410ef99 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -58,47 +58,43 @@
 #define USB_PHY_VDD_DIG_VOL_MIN100 /* uV */
 #define USB_PHY_VDD_DIG_VOL_MAX132 /* uV */

-static struct regulator *hsusb_3p3;
-static struct regulator *hsusb_1p8;
-static struct regulator *hsusb_vddcx;
-
 static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init)
 {
int ret = 0;

if (init) {
-   hsusb_vddcx = regulator_get(motg->phy.dev, "HSUSB_VDDCX");
-   if (IS_ERR(hsusb_vddcx)) {
+   motg->vddcx = regulator_get(motg->phy.dev, "HSUSB_VDDCX");
+   if (IS_ERR(motg->vddcx)) {
dev_err(motg->phy.dev, "unable to get hsusb vddcx\n");
-   return PTR_ERR(hsusb_vddcx);
+   return PTR_ERR(motg->vddcx);
}

-   ret = regulator_set_voltage(hsusb_vddcx,
+   ret = regulator_set_voltage(motg->vddcx,
USB_PHY_VDD_DIG_VOL_MIN,
USB_PHY_VDD_DIG_VOL_MAX);
if (ret) {
dev_err(motg->phy.dev, "unable to set the voltage "
"for hsusb vddcx\n");
-   regulator_put(hsusb_vddcx);
+   regulator_put(motg->vddcx);
return ret;
}

-   ret = regulator_enable(hsusb_vddcx);
+   ret = regulator_enable(motg->vddcx);
if (ret) {
dev_err(motg->phy.dev, "unable to enable hsusb 
vddcx\n");
-   regulator_put(hsusb_vddcx);
+   regulator_put(motg->vddcx);
}
} else {
-   ret = regulator_set_voltage(hsusb_vddcx, 0,
+   ret = regulator_set_voltage(motg->vddcx, 0,
USB_PHY_VDD_DIG_VOL_MAX);
if (ret)
dev_err(motg->phy.dev, "unable to set the voltage "
"for hsusb vddcx\n");
-   ret = regulator_disable(hsusb_vddcx);
+   ret = regulator_disable(motg->vddcx);
if (ret)
dev_err(motg->phy.dev, "unable to disable hsusb 
vddcx\n");

-   regulator_put(hsusb_vddcx);
+   regulator_put(motg->vddcx);
}

return ret;
@@ -109,38 +105,38 @@ static int msm_hsusb_ldo_init(struct msm_otg *motg, int 
init)
int rc = 0;

if (init) {
-   hsusb_3p3 = regulator_get(motg->phy.dev, "HSUSB_3p3");
-   if (IS_ERR(hsusb_3p3)) {
+   motg->v3p3 = regulator_get(motg->phy.dev, "HSUSB_3p3");
+   if (IS_ERR(motg->v3p3)) {
dev_err(motg->phy.dev, "unable to get hsusb 3p3\n");
-   return PTR_ERR(hsusb_3p3);
+   return PTR_ERR(motg->v3p3);
}

-   rc = regulator_set_voltage(hsusb_3p3, USB_PHY_3P3_VOL_MIN,
+   rc = regulator_set_voltage(motg->v3p3, USB_PHY_3P3_VOL_MIN,
USB_PHY_3P3_VOL_MAX);
if (rc) {
dev_err(motg->phy.dev, "unable to set voltage level "
"for hsusb 3p3\n");
goto put_3p3;
}
-   rc = regulator_enable(hsusb_3p3);
+   rc = regulator_enable(motg->v3p3);
if (rc) {
dev_err(motg->phy.dev, "unable to enable the hsusb 
3p3\n");
goto put_3p3;
}
-   hsusb_1p8 = regulator_get(motg->phy.dev, "HSUSB_1p8");
-   if (IS_ERR(hsusb_1p8)) {
+   motg->v1p8 = regulator_get(motg->phy.dev, "HSUSB_1p8");
+   if (IS_ERR(motg->v1p8)) {
dev_err(motg->phy.dev, "unable to get hsusb 1p8\n");
-   rc = PTR_ERR(hsusb_1p8);
+   rc = PTR_ERR(motg->v1p8);
goto disable_3p3;
}
-   rc = regulator_set_voltage(hsusb_1p8, USB_PHY_1P8_VOL_MIN,
+   rc = regulator_set_voltage(motg->v1p8, USB_PHY_1P8_VOL_MIN,
USB_PHY_1P8_VOL_MAX);
if (rc) {
dev_err(motg->phy.dev, "unable to set voltage level "
"for hsusb 1p8\n");
goto put_1p8;
}
-   rc = regulator_enable(hsusb_1p8);
+   rc = regulato

[PATCH v5 13/14] usb: phy: msm: Handle disconnect events

2014-03-05 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Put the transceiver in non-driving mode. Otherwise host
may not detect soft-disconnection.

Signed-off-by: Ivan T. Ivanov 
Cc: Pavankumar Kondeti 
---
 drivers/usb/phy/phy-msm-usb.c |   18 ++
 1 file changed, 18 insertions(+)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 8068555..f1e74a7 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -235,6 +235,23 @@ static void ulpi_init(struct msm_otg *motg)
}
 }

+static int msm_phy_notify_disconnect(struct usb_phy *phy,
+  enum usb_device_speed speed)
+{
+   int val;
+
+   /*
+* Put the transceiver in non-driving mode. Otherwise host
+* may not detect soft-disconnection.
+*/
+   val = ulpi_read(phy, ULPI_FUNC_CTRL);
+   val &= ~ULPI_FUNC_CTRL_OPMODE_MASK;
+   val |= ULPI_FUNC_CTRL_OPMODE_NONDRIVING;
+   ulpi_write(phy, val, ULPI_FUNC_CTRL);
+
+   return 0;
+}
+
 static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert)
 {
int ret;
@@ -1609,6 +1626,7 @@ static int __init msm_otg_probe(struct platform_device 
*pdev)

phy->init = msm_phy_init;
phy->set_power = msm_otg_set_power;
+   phy->notify_disconnect = msm_phy_notify_disconnect;

phy->io_ops = &msm_otg_io_ops;

--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 06/12] staging: usbip: userspace: add new list API

2014-03-05 Thread Dan Carpenter
On Tue, Mar 04, 2014 at 10:35:39PM -0800, Greg KH wrote:
> On Tue, Mar 04, 2014 at 09:10:46PM +0200, Valentina Manea wrote:
> > Add a new list API from CCAN.
> 
> Why can't you just take the one from the kernel, as userspace is GPLv2
> code, right?
> 
> And are you sure CC0 is a "valid" license that you can mix with GPLv2
> code?  I ask this seriously, as I have heard that CC0 really isn't even
> a valid license at all, and if I was to accept this patch, I'm going to
> have to go talk to some lawyers, which isn't going to be fun...
> 

GNU people say it's compitable.
https://www.gnu.org/licenses/license-list.html#CC0

It's not a good license because it doesn't say anything about that there
is no warranties.  Maybe other reasons as well.

regards,
dan carpenter
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 14/14] usb: phy: msm: Vote for corner of VDD CX instead of voltage of VDD CX

2014-03-05 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

New platform uses RBCPR hardware feature, with that voting for
absolute voltage of VDD CX is not required. Hence vote for corner of
VDD CX which uses nominal corner voltage on VDD CX.

Signed-off-by: Ivan T. Ivanov 
Cc: Mayank Rana 
---
 .../devicetree/bindings/usb/msm-hsusb.txt  |5 +++
 drivers/usb/phy/phy-msm-usb.c  |   35 +++-
 include/linux/usb/msm_hsusb.h  |1 +
 3 files changed, 33 insertions(+), 8 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/msm-hsusb.txt 
b/Documentation/devicetree/bindings/usb/msm-hsusb.txt
index 0669667..2826f2a 100644
--- a/Documentation/devicetree/bindings/usb/msm-hsusb.txt
+++ b/Documentation/devicetree/bindings/usb/msm-hsusb.txt
@@ -65,6 +65,10 @@ Optional properties:
 Some platforms may have configuration to allow USB
 controller work with any of the two HSPHYs present.

+- qcom,vdd-levels: This property must be a list of three integer values
+(no, min, max) where each value represents either a voltage
+in microvolts or a value corresponding to voltage corner.
+
 Example HSUSB OTG controller device node:

 usb@f9a55000 {
@@ -87,4 +91,5 @@ Example HSUSB OTG controller device node:

 qcom,otg-control = <1>;
 qcom,phy-init-sequence = < -1 0x63 >;
+qcom,vdd-levels = <1 5 7>;
};
diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index f1e74a7..574f560 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -62,6 +62,13 @@

 #define USB_PHY_VDD_DIG_VOL_MIN100 /* uV */
 #define USB_PHY_VDD_DIG_VOL_MAX132 /* uV */
+#define USB_PHY_SUSP_DIG_VOL   50  /* uV */
+
+enum vdd_levels {
+   VDD_LEVEL_NONE = 0,
+   VDD_LEVEL_MIN,
+   VDD_LEVEL_MAX,
+};

 static int msm_hsusb_init_vddcx(struct msm_otg *motg, int init)
 {
@@ -69,8 +76,8 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int 
init)

if (init) {
ret = regulator_set_voltage(motg->vddcx,
-   USB_PHY_VDD_DIG_VOL_MIN,
-   USB_PHY_VDD_DIG_VOL_MAX);
+   motg->vdd_levels[VDD_LEVEL_MIN],
+   motg->vdd_levels[VDD_LEVEL_MAX]);
if (ret) {
dev_err(motg->phy.dev, "Cannot set vddcx voltage\n");
return ret;
@@ -81,7 +88,7 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int 
init)
dev_err(motg->phy.dev, "unable to enable hsusb 
vddcx\n");
} else {
ret = regulator_set_voltage(motg->vddcx, 0,
-   USB_PHY_VDD_DIG_VOL_MAX);
+   motg->vdd_levels[VDD_LEVEL_MAX]);
if (ret)
dev_err(motg->phy.dev, "Cannot set vddcx voltage\n");
ret = regulator_disable(motg->vddcx);
@@ -435,17 +442,16 @@ static int msm_phy_init(struct usb_phy *phy)

 #ifdef CONFIG_PM

-#define USB_PHY_SUSP_DIG_VOL  50
 static int msm_hsusb_config_vddcx(struct msm_otg *motg, int high)
 {
-   int max_vol = USB_PHY_VDD_DIG_VOL_MAX;
+   int max_vol = motg->vdd_levels[VDD_LEVEL_MAX];
int min_vol;
int ret;

if (high)
-   min_vol = USB_PHY_VDD_DIG_VOL_MIN;
+   min_vol = motg->vdd_levels[VDD_LEVEL_MIN];
else
-   min_vol = USB_PHY_SUSP_DIG_VOL;
+   min_vol = motg->vdd_levels[VDD_LEVEL_NONE];

ret = regulator_set_voltage(motg->vddcx, min_vol, max_vol);
if (ret) {
@@ -1438,7 +1444,7 @@ static int msm_otg_read_dt(struct platform_device *pdev, 
struct msm_otg *motg)
struct device_node *node = pdev->dev.of_node;
struct property *prop;
int len, ret;
-   u32 val;
+   u32 val, tmp[3];

pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
if (!pdata)
@@ -1469,6 +1475,19 @@ static int msm_otg_read_dt(struct platform_device *pdev, 
struct msm_otg *motg)
if (!of_property_read_u32(node, "qcom,phy-num", &val) && val < 2)
motg->phy_number = val;

+   motg->vdd_levels[VDD_LEVEL_NONE] = USB_PHY_SUSP_DIG_VOL;
+   motg->vdd_levels[VDD_LEVEL_MIN] = USB_PHY_VDD_DIG_VOL_MIN;
+   motg->vdd_levels[VDD_LEVEL_MAX] = USB_PHY_VDD_DIG_VOL_MAX;
+
+   if (of_get_property(node, "qcom,vdd-levels", &len) &&
+   len == sizeof(tmp)) {
+   of_property_read_u32_array(node, "qcom,vdd-levels",
+  tmp, len / sizeof(*tmp));
+   motg->vdd_levels[VDD_LEVEL_NONE] = tmp[VDD_LEVEL_NONE];
+   motg->vdd_levels[VDD_LEVEL_MIN] = tmp[VDD_LEVEL_MIN];
+   motg->vdd_levels[VDD_LEVEL_MAX] = tmp[VDD_LEVEL_MAX];
+   }
+
prop = of_find_property(node, "qcom,phy-init-sequence", &len);

Re: [PATCH 01/12] staging: usbip: userspace: migrate usbip_bind to libudev

2014-03-05 Thread Dan Carpenter
On Wed, Mar 05, 2014 at 12:42:59PM +0300, Dan Carpenter wrote:
> On Tue, Mar 04, 2014 at 09:10:41PM +0200, Valentina Manea wrote:
> > diff --git a/drivers/staging/usbip/userspace/libsrc/usbip_common.h 
> > b/drivers/staging/usbip/userspace/libsrc/usbip_common.h
> > index 2cb81b3..565ac78 100644
> > --- a/drivers/staging/usbip/userspace/libsrc/usbip_common.h
> > +++ b/drivers/staging/usbip/userspace/libsrc/usbip_common.h
> > @@ -29,6 +29,15 @@
> >  #define USBIP_HOST_DRV_NAME"usbip-host"
> >  #define USBIP_VHCI_DRV_NAME"vhci_hcd"
> >  
> > +/* sysfs constants */
> > +#define SYSFS_MNT_PATH "/sys"
> > +#define SYSFS_BUS_NAME "bus"
> > +#define SYSFS_BUS_TYPE "usb"
> > +#define SYSFS_DRIVERS_NAME "drivers"
> 
> What on earth???  I don't even want to review any further than this.
> 
> Groan  No.  no no no no no.
> 

I overreacted.  This stuff was already in the original code, and this
change just moves it around.

Fine fine.  These patch set seem ok with me.

regards,
dan carpenter


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 03/14] usb: phy: msm: Remove unnecessarily check for valid regulators.

2014-03-05 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Whether regulators are available or not is checked at driver
probe. If they are not available driver will refuse to load,
so no need to check them again.

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c |   10 --
 1 file changed, 10 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 3f8d3bc..4f4b0c6 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -133,16 +133,6 @@ static int msm_hsusb_ldo_set_mode(struct msm_otg *motg, 
int on)
 {
int ret = 0;

-   if (!motg->v1p8 || IS_ERR(motg->v1p8)) {
-   pr_err("%s: HSUSB_1p8 is not initialized\n", __func__);
-   return -ENODEV;
-   }
-
-   if (!motg->v3p3 || IS_ERR(motg->v3p3)) {
-   pr_err("%s: HSUSB_3p3 is not initialized\n", __func__);
-   return -ENODEV;
-   }
-
if (on) {
ret = regulator_set_optimum_mode(motg->v1p8,
USB_PHY_1P8_HPM_LOAD);
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 09/14] usb: phy: msm: Add device tree support and binding information

2014-03-05 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Allows MSM OTG controller to be specified via device tree.

Signed-off-by: Ivan T. Ivanov 
---
 .../devicetree/bindings/usb/msm-hsusb.txt  |   67 
 drivers/usb/phy/phy-msm-usb.c  |  108 
 include/linux/usb/msm_hsusb.h  |6 +-
 3 files changed, 159 insertions(+), 22 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/msm-hsusb.txt 
b/Documentation/devicetree/bindings/usb/msm-hsusb.txt
index 5ea26c6..ee4123d 100644
--- a/Documentation/devicetree/bindings/usb/msm-hsusb.txt
+++ b/Documentation/devicetree/bindings/usb/msm-hsusb.txt
@@ -15,3 +15,70 @@ Example EHCI controller device node:
usb-phy = <&usb_otg>;
};

+USB PHY with optional OTG:
+
+Required properties:
+- compatible:   Should contain:
+  "qcom,usb-otg-ci" for chipsets with ChipIdea 45nm PHY
+  "qcom,usb-otg-snps" for chipsets with Synopsys 28nm PHY
+
+- regs: Offset and length of the register set in the memory map
+- interrupts:   interrupt-specifier for the OTG interrupt.
+
+- clocks:   A list of phandle + clock-specifier pairs for the
+clocks listed in clock-names
+- clock-names:  Should contain the following:
+  "phy" USB PHY reference clock
+  "core"Protocol engine clock
+  "iface"   Interface bus clock
+  "alt_core"Protocol engine clock for targets with asynchronous
+reset methodology. (optional)
+
+- vdccx-supply: phandle to the regulator for the vdd supply for
+digital circuit operation.
+- v1p8-supply:  phandle to the regulator for the 1.8V supply
+- v3p3-supply:  phandle to the regulator for the 3.3V supply
+
+- resets:   A list of phandle + reset-specifier pairs for the
+resets listed in reset-names
+- reset-names:  Should contain the following:
+  "phy" USB PHY controller reset
+  "link"USB LINK controller reset
+
+- qcom,otg-control: OTG control (VBUS and ID notifications) can be one of
+1 - PHY control
+2 - PMIC control
+
+Optional properties:
+- dr_mode:  One of "host", "peripheral" or "otg". Defaults to "otg"
+
+- qcom,phy-init-sequence: PHY configuration sequence values. This is related 
to Device
+Mode Eye Diagram test. Start address at which these values 
will be
+written is ULPI_EXT_VENDOR_SPECIFIC. Value of -1 is reserved as
+"do not overwrite default value at this address".
+For example: qcom,phy-init-sequence = < -1 0x63 >;
+Will update only value at address ULPI_EXT_VENDOR_SPECIFIC + 1.
+
+Example HSUSB OTG controller device node:
+
+usb@f9a55000 {
+compatible = "qcom,usb-otg-snps";
+reg = <0xf9a55000 0x400>;
+interrupts = <0 134 0>;
+dr_mode = "peripheral";
+
+clocks = <&gcc GCC_XO_CLK>, <&gcc GCC_USB_HS_SYSTEM_CLK>,
+<&gcc GCC_USB_HS_AHB_CLK>;
+
+clock-names = "phy", "core", "iface";
+
+vddcx-supply = <&pm8841_s2_corner>;
+v1p8-supply = <&pm8941_l6>;
+v3p3-supply = <&pm8941_l24>;
+
+resets = <&gcc GCC_USB2A_PHY_BCR>, <&gcc GCC_USB_HS_BCR>;
+reset-names = "phy", "link";
+
+qcom,otg-control = <1>;
+qcom,phy-init-sequence = < -1 0x63 >;
+   };
diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 31fb916..298820f 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -30,9 +30,12 @@
 #include 
 #include 
 #include 
+#include 
+#include 

 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -217,16 +220,16 @@ static struct usb_phy_io_ops msm_otg_io_ops = {
 static void ulpi_init(struct msm_otg *motg)
 {
struct msm_otg_platform_data *pdata = motg->pdata;
-   int *seq = pdata->phy_init_seq;
+   int *seq = pdata->phy_init_seq, idx;
+   u32 addr = ULPI_EXT_VENDOR_SPECIFIC;

-   if (!seq)
-   return;
+   for (idx = 0; idx < pdata->phy_init_sz; idx++) {
+   if (seq[idx] == -1)
+   continue;

-   while (seq[0] >= 0) {
dev_vdbg(motg->phy.dev, "ulpi: write 0x%02x to 0x%02x\n",
-   seq[0], seq[1]);
-   ulpi_write(&motg->phy, seq[0], seq[1]);
-   seq += 2;
+   seq[idx], addr + idx);
+   ulpi_write(&motg->phy, seq[idx], addr + idx);
}
 }

@@ -1343,25 +1346,87 @@ static void msm_otg_debugfs_cleanup(void)
debugfs_remove(msm_otg_dbg_root);
 }

+static struct of_device_id msm_otg_dt_match[] = {
+   {
+   .compatible = "qcom,usb-otg-ci",
+   .data = (void *) CI_45NM_INTEGRATED_PHY
+   }, {
+   .compatible = "qcom,usb-otg-snps",
+   .data = (void *) SNPS_28NM_INTEGRATED_PHY
+   }, {}
+};
+
+static int msm_otg_read_dt(struct 

[PATCH v5 12/14] usb: phy: msm: Correct USB PHY Reset sequence for newer platform

2014-03-05 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

On few legacy platforms, USB PHY is having dedicated reset clk.
It is used to reset USB PHY after putting USB PHY into low power
mode and for calibration of USB PHY. Putting USB PHY into low
power mode is causing ulpi read/write timeout as expected. USB PHY
reset clk is not available on newer platform.

For 28nm PHY, reset USB PHY after resestting USB LINK.
Also reset USB PHY using USB_PHY_PON bit with USB_OTG_HS_PHY_CTRL
register after programming USB PHY Override registers as suggested
with hardware programming guidelines.

Signed-off-by: Ivan T. Ivanov 
Cc: Mayank Rana 
---
 drivers/usb/phy/phy-msm-usb.c|  141 --
 include/linux/usb/msm_hsusb_hw.h |5 ++
 2 files changed, 94 insertions(+), 52 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index f3e9389..8068555 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -48,6 +48,7 @@
 #define DRIVER_NAME"msm_otg"

 #define ULPI_IO_TIMEOUT_USEC   (10 * 1000)
+#define LINK_RESET_TIMEOUT_USEC(250 * 1000)

 #define USB_PHY_3P3_VOL_MIN305 /* uV */
 #define USB_PHY_3P3_VOL_MAX330 /* uV */
@@ -268,77 +269,35 @@ static int msm_otg_phy_clk_reset(struct msm_otg *motg)
return ret;
 }

-static int msm_otg_phy_reset(struct msm_otg *motg)
+static int msm_link_reset(struct msm_otg *motg)
 {
u32 val;
int ret;
-   int retries;

ret = msm_otg_link_clk_reset(motg, 1);
if (ret)
return ret;
-   ret = msm_otg_phy_clk_reset(motg);
-   if (ret)
-   return ret;
-   ret = msm_otg_link_clk_reset(motg, 0);
-   if (ret)
-   return ret;

-   val = readl(USB_PORTSC) & ~PORTSC_PTS_MASK;
-   writel(val | PORTSC_PTS_ULPI, USB_PORTSC);
-
-   for (retries = 3; retries > 0; retries--) {
-   ret = ulpi_write(&motg->phy, ULPI_FUNC_CTRL_SUSPENDM,
-   ULPI_CLR(ULPI_FUNC_CTRL));
-   if (!ret)
-   break;
-   ret = msm_otg_phy_clk_reset(motg);
-   if (ret)
-   return ret;
-   }
-   if (!retries)
-   return -ETIMEDOUT;
+   /* wait for 1ms delay as suggested in HPG. */
+   usleep_range(1000, 1200);

-   /* This reset calibrates the phy, if the above write succeeded */
-   ret = msm_otg_phy_clk_reset(motg);
+   ret = msm_otg_link_clk_reset(motg, 0);
if (ret)
return ret;

-   for (retries = 3; retries > 0; retries--) {
-   ret = ulpi_read(&motg->phy, ULPI_DEBUG);
-   if (ret != -ETIMEDOUT)
-   break;
-   ret = msm_otg_phy_clk_reset(motg);
-   if (ret)
-   return ret;
-   }
-   if (!retries)
-   return -ETIMEDOUT;
-
if (motg->phy_number)
writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2);

-   dev_info(motg->phy.dev, "phy_reset: success\n");
+   val = readl(USB_PORTSC) & ~PORTSC_PTS_MASK;
+   writel(val | PORTSC_PTS_ULPI, USB_PORTSC);
+
return 0;
 }

-#define LINK_RESET_TIMEOUT_USEC(250 * 1000)
 static int msm_otg_reset(struct usb_phy *phy)
 {
struct msm_otg *motg = container_of(phy, struct msm_otg, phy);
-   struct msm_otg_platform_data *pdata = motg->pdata;
int cnt = 0;
-   int ret;
-   u32 val = 0;
-   u32 ulpi_val = 0;
-
-   ret = msm_otg_phy_reset(motg);
-   if (ret) {
-   dev_err(phy->dev, "phy_reset failed\n");
-   return ret;
-   }
-
-   ulpi_init(motg);

writel(USBCMD_RESET, USB_USBCMD);
while (cnt < LINK_RESET_TIMEOUT_USEC) {
@@ -352,11 +311,87 @@ static int msm_otg_reset(struct usb_phy *phy)

/* select ULPI phy */
writel(0x8000, USB_PORTSC);
+   writel(0x0, USB_AHBBURST);
+   writel(0x08, USB_AHBMODE);
+
+   if (motg->phy_number)
+   writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2);
+   return 0;
+}
+
+static void msm_phy_reset(struct msm_otg *motg)
+{
+   void __iomem *addr;
+   u32 val;
+
+   if (motg->pdata->phy_type != SNPS_28NM_INTEGRATED_PHY) {
+   msm_otg_phy_clk_reset(motg);
+   return;
+   }
+
+   addr = USB_PHY_CTRL;
+   if (motg->phy_number)
+   addr = USB_PHY_CTRL2;
+
+   /* Assert USB PHY_PON */
+   val =  readl(addr);
+   val |= PHY_POR_ASSERT;
+   writel(val, addr);
+
+   /* wait for minimum 10 microseconds as suggested in HPG. */
+   usleep_range(10, 15);
+
+   /* Deassert USB PHY_PON */
+   val =  readl(addr);
+   val &= ~PHY_POR_ASSERT;
+   writel(val, addr);
+}
+
+static int msm_usb_reset(struct usb_phy *phy)
+{
+   struct msm_otg *motg = container_of(phy, struct msm_otg, phy);
+   int ret;
+
+   if (!IS_ERR(

[PATCH v5 11/14] usb: phy: msm: Add support for secondary PHY control

2014-03-05 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Allow support to use 2nd HSPHY with USB2 Core.
Some platforms may have configuration to allow USB controller
work with any of the two HSPHYs present. By default driver
configures USB core to use primary HSPHY. Add support to allow
user select 2nd HSPHY using DT parameter.

Signed-off-by: Ivan T. Ivanov 
Cc: Manu Gautam 
---
 .../devicetree/bindings/usb/msm-hsusb.txt  |6 +
 drivers/usb/phy/phy-msm-usb.c  |   24 ++--
 include/linux/usb/msm_hsusb.h  |1 +
 include/linux/usb/msm_hsusb_hw.h   |1 +
 4 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/msm-hsusb.txt 
b/Documentation/devicetree/bindings/usb/msm-hsusb.txt
index ee4123d..0669667 100644
--- a/Documentation/devicetree/bindings/usb/msm-hsusb.txt
+++ b/Documentation/devicetree/bindings/usb/msm-hsusb.txt
@@ -59,6 +59,12 @@ Optional properties:
 For example: qcom,phy-init-sequence = < -1 0x63 >;
 Will update only value at address ULPI_EXT_VENDOR_SPECIFIC + 1.

+- qcom,phy-num: Select number of pyco-phy to use, can be one of
+0 - PHY one, default
+1 - Second PHY
+Some platforms may have configuration to allow USB
+controller work with any of the two HSPHYs present.
+
 Example HSUSB OTG controller device node:

 usb@f9a55000 {
diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 7e5c4ab..f3e9389 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -315,6 +315,9 @@ static int msm_otg_phy_reset(struct msm_otg *motg)
if (!retries)
return -ETIMEDOUT;

+   if (motg->phy_number)
+   writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2);
+
dev_info(motg->phy.dev, "phy_reset: success\n");
return 0;
 }
@@ -369,6 +372,9 @@ static int msm_otg_reset(struct usb_phy *phy)
ulpi_write(phy, ulpi_val, ULPI_USB_INT_EN_FALL);
}

+   if (motg->phy_number)
+   writel(readl(USB_PHY_CTRL2) | BIT(16), USB_PHY_CTRL2);
+
return 0;
 }

@@ -405,6 +411,7 @@ static int msm_otg_suspend(struct msm_otg *motg)
struct usb_phy *phy = &motg->phy;
struct usb_bus *bus = phy->otg->host;
struct msm_otg_platform_data *pdata = motg->pdata;
+   void __iomem *addr;
int cnt = 0;

if (atomic_read(&motg->in_lpm))
@@ -464,9 +471,13 @@ static int msm_otg_suspend(struct msm_otg *motg)
 */
writel(readl(USB_USBCMD) | ASYNC_INTR_CTRL | ULPI_STP_CTRL, USB_USBCMD);

+   addr = USB_PHY_CTRL;
+   if (motg->phy_number)
+   addr = USB_PHY_CTRL2;
+
if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY &&
motg->pdata->otg_control == OTG_PMIC_CONTROL)
-   writel(readl(USB_PHY_CTRL) | PHY_RETEN, USB_PHY_CTRL);
+   writel(readl(addr) | PHY_RETEN, addr);

clk_disable_unprepare(motg->pclk);
clk_disable_unprepare(motg->clk);
@@ -496,6 +507,7 @@ static int msm_otg_resume(struct msm_otg *motg)
 {
struct usb_phy *phy = &motg->phy;
struct usb_bus *bus = phy->otg->host;
+   void __iomem *addr;
int cnt = 0;
unsigned temp;

@@ -509,9 +521,14 @@ static int msm_otg_resume(struct msm_otg *motg)

if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY &&
motg->pdata->otg_control == OTG_PMIC_CONTROL) {
+
+   addr = USB_PHY_CTRL;
+   if (motg->phy_number)
+   addr = USB_PHY_CTRL2;
+
msm_hsusb_ldo_set_mode(motg, 1);
msm_hsusb_config_vddcx(motg, 1);
-   writel(readl(USB_PHY_CTRL) & ~PHY_RETEN, USB_PHY_CTRL);
+   writel(readl(addr) & ~PHY_RETEN, addr);
}

temp = readl(USB_USBCMD);
@@ -1397,6 +1414,9 @@ static int msm_otg_read_dt(struct platform_device *pdev, 
struct msm_otg *motg)
if (val == OTG_PMIC_CONTROL)
pdata->otg_control = val;

+   if (!of_property_read_u32(node, "qcom,phy-num", &val) && val < 2)
+   motg->phy_number = val;
+
prop = of_find_property(node, "qcom,phy-init-sequence", &len);
if (!prop || !len)
return 0;
diff --git a/include/linux/usb/msm_hsusb.h b/include/linux/usb/msm_hsusb.h
index 4e5d916..4628f1a 100644
--- a/include/linux/usb/msm_hsusb.h
+++ b/include/linux/usb/msm_hsusb.h
@@ -158,6 +158,7 @@ struct msm_otg {
atomic_t in_lpm;
int async_int;
unsigned cur_power;
+   int phy_number;
struct delayed_work chg_work;
enum usb_chg_state chg_state;
enum usb_chg_type chg_type;
diff --git a/include/linux/usb/msm_hsusb_hw.h b/include/linux/usb/msm_hsusb_hw.h
index 6e97a2d..e6d7035 100644
--- a/include/linux/usb/msm_hsusb_hw.h
+++ b/include/li

[PATCH v5 00/14] usb: phy: msm: Fixes, cleanups and DT support

2014-03-05 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Hi,

This is a fifth version of patches posted earlier here [1].

They have been tested on AP8074 DragonBoard. Only gadget
mode utilized for now.

CV Test Suite engine "Chapter 9 tests" are passing except
"Halt Endpoint Test".

usbtest driver report following failure:
test 13 --> 32 (Broken pipe)ep 81 couldn't set halt, -32

Changes since v4:
 - Drop patch [1/15] usb: phy: msm: Move mach dependent code to platform data
   it is already merged.
 - Address comments regarding devicetree bindings.

[1] https://lkml.org/lkml/2013/11/12/298

Ivan T. Ivanov (14):
  usb: phy: msm: Move global regulators variables to driver state
  usb: phy: msm: Migrate to Managed Device Resource allocation
  usb: phy: msm: Remove unnecessarily check for valid regulators.
  usb: phy: msm: Fix checkpatch.pl warnings
  usb: phy: msm: Replace custom enum usb_mode_type with enum
usb_dr_mode
  usb: phy: msm: Remove unused pclk_src_name
  usb: phy: msm: Remove HSUSB prefix from regulator names
  usb: phy: msm: Properly check result from platform_get_irq()
  usb: phy: msm: Add device tree support and binding information
  usb: phy: msm: Use reset framework for LINK and PHY resets
  usb: phy: msm: Add support for secondary PHY control
  usb: phy: msm: Correct USB PHY Reset sequence for newer platform
  usb: phy: msm: Handle disconnect events
  usb: phy: msm: Vote for corner of VDD CX instead of voltage of VDD CX

 .../devicetree/bindings/usb/msm-hsusb.txt  |   78 +++
 arch/arm/mach-msm/board-msm7x30.c  |2 +-
 arch/arm/mach-msm/board-qsd8x50.c  |2 +-
 drivers/usb/phy/phy-msm-usb.c  |  674 +++-
 include/linux/usb/msm_hsusb.h  |   39 +-
 include/linux/usb/msm_hsusb_hw.h   |6 +
 6 files changed, 474 insertions(+), 327 deletions(-)

--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 10/14] usb: phy: msm: Use reset framework for LINK and PHY resets

2014-03-05 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c |   30 ++
 include/linux/usb/msm_hsusb.h |3 +++
 2 files changed, 25 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 298820f..7e5c4ab 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -32,6 +32,7 @@
 #include 
 #include 
 #include 
+#include 

 #include 
 #include 
@@ -235,12 +236,16 @@ static void ulpi_init(struct msm_otg *motg)

 static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert)
 {
-   int ret = 0;
+   int ret;

-   if (!motg->pdata->link_clk_reset)
-   return ret;
+   if (motg->pdata->link_clk_reset)
+   ret = motg->pdata->link_clk_reset(motg->clk, assert);
+   else
+   if (assert)
+   ret = reset_control_assert(motg->link_rst);
+   else
+   ret = reset_control_deassert(motg->link_rst);

-   ret = motg->pdata->link_clk_reset(motg->clk, assert);
if (ret)
dev_err(motg->phy.dev, "usb link clk reset %s failed\n",
assert ? "assert" : "deassert");
@@ -250,12 +255,13 @@ static int msm_otg_link_clk_reset(struct msm_otg *motg, 
bool assert)

 static int msm_otg_phy_clk_reset(struct msm_otg *motg)
 {
-   int ret = 0;
+   int ret;

-   if (!motg->pdata->phy_clk_reset)
-   return ret;
+   if (motg->pdata->phy_clk_reset)
+   ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk);
+   else
+   ret = reset_control_reset(motg->phy_rst);

-   ret = motg->pdata->phy_clk_reset(motg->phy_reset_clk);
if (ret)
dev_err(motg->phy.dev, "usb phy clk reset failed\n");

@@ -1374,6 +1380,14 @@ static int msm_otg_read_dt(struct platform_device *pdev, 
struct msm_otg *motg)
id = of_match_device(msm_otg_dt_match, &pdev->dev);
pdata->phy_type = (int) id->data;

+   motg->link_rst = devm_reset_control_get(&pdev->dev, "link");
+   if (IS_ERR(motg->link_rst))
+   return PTR_ERR(motg->link_rst);
+
+   motg->phy_rst = devm_reset_control_get(&pdev->dev, "phy");
+   if (IS_ERR(motg->phy_rst))
+   return PTR_ERR(motg->phy_rst);
+
pdata->mode = of_usb_get_dr_mode(node);
if (pdata->mode == USB_DR_MODE_UNKNOWN)
pdata->mode = USB_DR_MODE_OTG;
diff --git a/include/linux/usb/msm_hsusb.h b/include/linux/usb/msm_hsusb.h
index bd68299..4e5d916 100644
--- a/include/linux/usb/msm_hsusb.h
+++ b/include/linux/usb/msm_hsusb.h
@@ -165,6 +165,9 @@ struct msm_otg {
struct regulator *v3p3;
struct regulator *v1p8;
struct regulator *vddcx;
+
+   struct reset_control *phy_rst;
+   struct reset_control *link_rst;
 };

 #endif
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 02/14] usb: phy: msm: Migrate to Managed Device Resource allocation

2014-03-05 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Move memory, regulators, clocks and irq allocation to
devm_* variants. Properly check for valid clk handles.

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c |  192 -
 1 file changed, 74 insertions(+), 118 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 410ef99..3f8d3bc 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -63,27 +63,18 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int 
init)
int ret = 0;

if (init) {
-   motg->vddcx = regulator_get(motg->phy.dev, "HSUSB_VDDCX");
-   if (IS_ERR(motg->vddcx)) {
-   dev_err(motg->phy.dev, "unable to get hsusb vddcx\n");
-   return PTR_ERR(motg->vddcx);
-   }
-
ret = regulator_set_voltage(motg->vddcx,
USB_PHY_VDD_DIG_VOL_MIN,
USB_PHY_VDD_DIG_VOL_MAX);
if (ret) {
dev_err(motg->phy.dev, "unable to set the voltage "
"for hsusb vddcx\n");
-   regulator_put(motg->vddcx);
return ret;
}

ret = regulator_enable(motg->vddcx);
-   if (ret) {
+   if (ret)
dev_err(motg->phy.dev, "unable to enable hsusb 
vddcx\n");
-   regulator_put(motg->vddcx);
-   }
} else {
ret = regulator_set_voltage(motg->vddcx, 0,
USB_PHY_VDD_DIG_VOL_MAX);
@@ -93,8 +84,6 @@ static int msm_hsusb_init_vddcx(struct msm_otg *motg, int 
init)
ret = regulator_disable(motg->vddcx);
if (ret)
dev_err(motg->phy.dev, "unable to disable hsusb 
vddcx\n");
-
-   regulator_put(motg->vddcx);
}

return ret;
@@ -105,53 +94,38 @@ static int msm_hsusb_ldo_init(struct msm_otg *motg, int 
init)
int rc = 0;

if (init) {
-   motg->v3p3 = regulator_get(motg->phy.dev, "HSUSB_3p3");
-   if (IS_ERR(motg->v3p3)) {
-   dev_err(motg->phy.dev, "unable to get hsusb 3p3\n");
-   return PTR_ERR(motg->v3p3);
-   }
-
rc = regulator_set_voltage(motg->v3p3, USB_PHY_3P3_VOL_MIN,
USB_PHY_3P3_VOL_MAX);
if (rc) {
dev_err(motg->phy.dev, "unable to set voltage level "
"for hsusb 3p3\n");
-   goto put_3p3;
+   goto exit;
}
rc = regulator_enable(motg->v3p3);
if (rc) {
dev_err(motg->phy.dev, "unable to enable the hsusb 
3p3\n");
-   goto put_3p3;
-   }
-   motg->v1p8 = regulator_get(motg->phy.dev, "HSUSB_1p8");
-   if (IS_ERR(motg->v1p8)) {
-   dev_err(motg->phy.dev, "unable to get hsusb 1p8\n");
-   rc = PTR_ERR(motg->v1p8);
-   goto disable_3p3;
+   goto exit;
}
rc = regulator_set_voltage(motg->v1p8, USB_PHY_1P8_VOL_MIN,
USB_PHY_1P8_VOL_MAX);
if (rc) {
dev_err(motg->phy.dev, "unable to set voltage level "
"for hsusb 1p8\n");
-   goto put_1p8;
+   goto disable_3p3;
}
rc = regulator_enable(motg->v1p8);
if (rc) {
dev_err(motg->phy.dev, "unable to enable the hsusb 
1p8\n");
-   goto put_1p8;
+   goto disable_3p3;
}

return 0;
}

regulator_disable(motg->v1p8);
-put_1p8:
-   regulator_put(motg->v1p8);
 disable_3p3:
regulator_disable(motg->v3p3);
-put_3p3:
-   regulator_put(motg->v3p3);
+exit:
return rc;
 }

@@ -506,7 +480,7 @@ static int msm_otg_suspend(struct msm_otg *motg)

clk_disable_unprepare(motg->pclk);
clk_disable_unprepare(motg->clk);
-   if (motg->core_clk)
+   if (!IS_ERR(motg->core_clk))
clk_disable_unprepare(motg->core_clk);

if (!IS_ERR(motg->pclk_src))
@@ -546,7 +520,7 @@ static int msm_otg_resume(struct msm_otg *motg)

clk_prepare_enable(motg->pclk);
clk_prepare_enable(motg->clk);
-   if (motg->core_clk)
+   if (!IS_ERR(motg->core_clk))
clk_prepare_enable(motg->core_clk);

if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY &&
@@ -1415,13 +1389,14 @@ static int __init msm_otg_probe(struct platform_device 
*pdev)
  

[PATCH v5 05/14] usb: phy: msm: Replace custom enum usb_mode_type with enum usb_dr_mode

2014-03-05 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Use enum usb_dr_mode and drop default usb_dr_mode from platform data.

USB DT bindings states: dr_mode: "...In case this attribute isn't
passed via DT, USB DRD controllers should default to OTG...",
so remove redundand field.

Signed-off-by: Ivan T. Ivanov 
Acked-by: David Brown 
---
 arch/arm/mach-msm/board-msm7x30.c |2 +-
 arch/arm/mach-msm/board-qsd8x50.c |2 +-
 drivers/usb/phy/phy-msm-usb.c |   41 +++--
 include/linux/usb/msm_hsusb.h |   20 +-
 4 files changed, 20 insertions(+), 45 deletions(-)

diff --git a/arch/arm/mach-msm/board-msm7x30.c 
b/arch/arm/mach-msm/board-msm7x30.c
index 46de789..0c4c200 100644
--- a/arch/arm/mach-msm/board-msm7x30.c
+++ b/arch/arm/mach-msm/board-msm7x30.c
@@ -95,7 +95,7 @@ static int hsusb_phy_clk_reset(struct clk *phy_clk)
 
 static struct msm_otg_platform_data msm_otg_pdata = {
.phy_init_seq   = hsusb_phy_init_seq,
-   .mode   = USB_PERIPHERAL,
+   .mode   = USB_DR_MODE_PERIPHERAL,
.otg_control= OTG_PHY_CONTROL,
.link_clk_reset = hsusb_link_clk_reset,
.phy_clk_reset  = hsusb_phy_clk_reset,
diff --git a/arch/arm/mach-msm/board-qsd8x50.c 
b/arch/arm/mach-msm/board-qsd8x50.c
index 9169ec3..4c74861 100644
--- a/arch/arm/mach-msm/board-qsd8x50.c
+++ b/arch/arm/mach-msm/board-qsd8x50.c
@@ -116,7 +116,7 @@ static int hsusb_phy_clk_reset(struct clk *phy_clk)
 
 static struct msm_otg_platform_data msm_otg_pdata = {
.phy_init_seq   = hsusb_phy_init_seq,
-   .mode   = USB_PERIPHERAL,
+   .mode   = USB_DR_MODE_PERIPHERAL,
.otg_control= OTG_PHY_CONTROL,
.link_clk_reset = hsusb_link_clk_reset,
.phy_clk_reset  = hsusb_phy_clk_reset,
diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index beafe84..dac2e8d 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -348,10 +348,10 @@ static int msm_otg_reset(struct usb_phy *phy)
 
if (pdata->otg_control == OTG_PHY_CONTROL) {
val = readl(USB_OTGSC);
-   if (pdata->mode == USB_OTG) {
+   if (pdata->mode == USB_DR_MODE_OTG) {
ulpi_val = ULPI_INT_IDGRD | ULPI_INT_SESS_VALID;
val |= OTGSC_IDIE | OTGSC_BSVIE;
-   } else if (pdata->mode == USB_PERIPHERAL) {
+   } else if (pdata->mode == USB_DR_MODE_PERIPHERAL) {
ulpi_val = ULPI_INT_SESS_VALID;
val |= OTGSC_BSVIE;
}
@@ -637,7 +637,7 @@ static int msm_otg_set_host(struct usb_otg *otg, struct 
usb_bus *host)
 * Fail host registration if this board can support
 * only peripheral configuration.
 */
-   if (motg->pdata->mode == USB_PERIPHERAL) {
+   if (motg->pdata->mode == USB_DR_MODE_PERIPHERAL) {
dev_info(otg->phy->dev, "Host mode is not supported\n");
return -ENODEV;
}
@@ -666,7 +666,7 @@ static int msm_otg_set_host(struct usb_otg *otg, struct 
usb_bus *host)
 * Kick the state machine work, if peripheral is not supported
 * or peripheral is already registered with us.
 */
-   if (motg->pdata->mode == USB_HOST || otg->gadget) {
+   if (motg->pdata->mode == USB_DR_MODE_HOST || otg->gadget) {
pm_runtime_get_sync(otg->phy->dev);
schedule_work(&motg->sm_work);
}
@@ -710,7 +710,7 @@ static int msm_otg_set_peripheral(struct usb_otg *otg,
 * Fail peripheral registration if this board can support
 * only host configuration.
 */
-   if (motg->pdata->mode == USB_HOST) {
+   if (motg->pdata->mode == USB_DR_MODE_HOST) {
dev_info(otg->phy->dev, "Peripheral mode is not supported\n");
return -ENODEV;
}
@@ -735,7 +735,7 @@ static int msm_otg_set_peripheral(struct usb_otg *otg,
 * Kick the state machine work, if host is not supported
 * or host is already registered with us.
 */
-   if (motg->pdata->mode == USB_PERIPHERAL || otg->host) {
+   if (motg->pdata->mode == USB_DR_MODE_PERIPHERAL || otg->host) {
pm_runtime_get_sync(otg->phy->dev);
schedule_work(&motg->sm_work);
}
@@ -1056,7 +1056,7 @@ static void msm_otg_init_sm(struct msm_otg *motg)
u32 otgsc = readl(USB_OTGSC);
 
switch (pdata->mode) {
-   case USB_OTG:
+   case USB_DR_MODE_OTG:
if (pdata->otg_control == OTG_PHY_CONTROL) {
if (otgsc & OTGSC_ID)
set_bit(ID, &motg->inputs);
@@ -1068,21 +1068,14 @@ static void msm_otg_init_sm(struct msm_otg *motg)
else
clear_bit(B_SESS_VLD, &motg->inputs);

[PATCH v5 06/14] usb: phy: msm: Remove unused pclk_src_name

2014-03-05 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

There are no references to 'pclk_src_name' in plaform code,
so it is unused.

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c |   26 +-
 include/linux/usb/msm_hsusb.h |5 -
 2 files changed, 1 insertion(+), 30 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index dac2e8d..193d6bc 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -464,9 +464,6 @@ static int msm_otg_suspend(struct msm_otg *motg)
if (!IS_ERR(motg->core_clk))
clk_disable_unprepare(motg->core_clk);

-   if (!IS_ERR(motg->pclk_src))
-   clk_disable_unprepare(motg->pclk_src);
-
if (motg->pdata->phy_type == SNPS_28NM_INTEGRATED_PHY &&
motg->pdata->otg_control == OTG_PMIC_CONTROL) {
msm_hsusb_ldo_set_mode(motg, 0);
@@ -496,9 +493,6 @@ static int msm_otg_resume(struct msm_otg *motg)
if (!atomic_read(&motg->in_lpm))
return 0;

-   if (!IS_ERR(motg->pclk_src))
-   clk_prepare_enable(motg->pclk_src);
-
clk_prepare_enable(motg->pclk);
clk_prepare_enable(motg->clk);
if (!IS_ERR(motg->core_clk))
@@ -1395,17 +1389,8 @@ static int __init msm_otg_probe(struct platform_device 
*pdev)
 * If USB Core is running its protocol engine based on CORE CLK,
 * CORE CLK  must be running at >55Mhz for correct HSUSB
 * operation and USB core cannot tolerate frequency changes on
-* CORE CLK. For such USB cores, vote for maximum clk frequency
-* on pclk source
+* CORE CLK.
 */
-motg->pclk_src = ERR_PTR(-ENOENT);
-if (motg->pdata->pclk_src_name) {
-   motg->pclk_src = devm_clk_get(&pdev->dev,
-   motg->pdata->pclk_src_name);
-   if (IS_ERR(motg->pclk_src))
-   return PTR_ERR(motg->pclk_src);
-   }
-
motg->pclk = devm_clk_get(&pdev->dev, "usb_hs_pclk");
if (IS_ERR(motg->pclk)) {
dev_err(&pdev->dev, "failed to get usb_hs_pclk\n");
@@ -1451,10 +1436,6 @@ static int __init msm_otg_probe(struct platform_device 
*pdev)
}

clk_set_rate(motg->clk, 6000);
-   if (!IS_ERR(motg->pclk_src)) {
-   clk_set_rate(motg->pclk_src, INT_MAX);
-   clk_prepare_enable(motg->pclk_src);
-   }

clk_prepare_enable(motg->clk);
clk_prepare_enable(motg->pclk);
@@ -1530,8 +1511,6 @@ disable_clks:
clk_disable_unprepare(motg->clk);
if (!IS_ERR(motg->core_clk))
clk_disable_unprepare(motg->core_clk);
-   if (!IS_ERR(motg->pclk_src))
-   clk_disable_unprepare(motg->pclk_src);
return ret;
 }

@@ -1576,9 +1555,6 @@ static int msm_otg_remove(struct platform_device *pdev)
clk_disable_unprepare(motg->clk);
if (!IS_ERR(motg->core_clk))
clk_disable_unprepare(motg->core_clk);
-   if (!IS_ERR(motg->pclk_src))
-   clk_disable_unprepare(motg->pclk_src);
-
msm_hsusb_ldo_init(motg, 0);

pm_runtime_set_suspended(&pdev->dev);
diff --git a/include/linux/usb/msm_hsusb.h b/include/linux/usb/msm_hsusb.h
index 72c5830..262ed80 100644
--- a/include/linux/usb/msm_hsusb.h
+++ b/include/linux/usb/msm_hsusb.h
@@ -106,8 +106,6 @@ enum usb_chg_type {
  * @power_budget: VBUS power budget in mA (0 will be treated as 500mA).
  * @mode: Supported mode (OTG/peripheral/host).
  * @otg_control: OTG switch controlled by user/Id pin
- * @pclk_src_name: pclk is derived from ebi1_usb_clk in case of 7x27 and 8k
- *  dfab_usb_hs_clk in case of 8660 and 8960.
  */
 struct msm_otg_platform_data {
int *phy_init_seq;
@@ -117,7 +115,6 @@ struct msm_otg_platform_data {
enum otg_control_type otg_control;
enum msm_usb_phy_type phy_type;
void (*setup_gpio)(enum usb_otg_state state);
-   char *pclk_src_name;
int (*link_clk_reset)(struct clk *link_clk, bool assert);
int (*phy_clk_reset)(struct clk *phy_clk);
 };
@@ -129,7 +126,6 @@ struct msm_otg_platform_data {
  * @irq: IRQ number assigned for HSUSB controller.
  * @clk: clock struct of usb_hs_clk.
  * @pclk: clock struct of usb_hs_pclk.
- * @pclk_src: pclk source for voting.
  * @phy_reset_clk: clock struct of usb_phy_clk.
  * @core_clk: clock struct of usb_hs_core_clk.
  * @regs: ioremapped register base address.
@@ -150,7 +146,6 @@ struct msm_otg {
int irq;
struct clk *clk;
struct clk *pclk;
-   struct clk *pclk_src;
struct clk *phy_reset_clk;
struct clk *core_clk;
void __iomem *regs;
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 07/14] usb: phy: msm: Remove HSUSB prefix from regulator names

2014-03-05 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Prefix did not bring any useful information. Currently none
of the MSM platforms define these regulators, so it is safe
to rename them.

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c |6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 193d6bc..c2048c7 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -1417,19 +1417,19 @@ static int __init msm_otg_probe(struct platform_device 
*pdev)
return motg->irq;
}

-   motg->vddcx = devm_regulator_get(motg->phy.dev, "HSUSB_VDDCX");
+   motg->vddcx = devm_regulator_get(motg->phy.dev, "vddcx");
if (IS_ERR(motg->vddcx)) {
dev_err(motg->phy.dev, "unable to get hsusb vddcx\n");
return PTR_ERR(motg->vddcx);
}

-   motg->v3p3 = devm_regulator_get(motg->phy.dev, "HSUSB_3p3");
+   motg->v3p3 = devm_regulator_get(motg->phy.dev, "v3p3");
if (IS_ERR(motg->v3p3)) {
dev_err(motg->phy.dev, "unable to get hsusb 3p3\n");
return PTR_ERR(motg->v3p3);
}

-   motg->v1p8 = devm_regulator_get(motg->phy.dev, "HSUSB_1p8");
+   motg->v1p8 = devm_regulator_get(motg->phy.dev, "v1p8");
if (IS_ERR(motg->v1p8)) {
dev_err(motg->phy.dev, "unable to get hsusb 1p8\n");
return PTR_ERR(motg->v1p8);
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v5 08/14] usb: phy: msm: Properly check result from platform_get_irq()

2014-03-05 Thread Ivan T. Ivanov
From: "Ivan T. Ivanov" 

Function return negative code on error.

Signed-off-by: Ivan T. Ivanov 
---
 drivers/usb/phy/phy-msm-usb.c |2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index c2048c7..31fb916 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c
@@ -1412,7 +1412,7 @@ static int __init msm_otg_probe(struct platform_device 
*pdev)
dev_info(&pdev->dev, "OTG regs = %p\n", motg->regs);

motg->irq = platform_get_irq(pdev, 0);
-   if (!motg->irq) {
+   if (motg->irq < 0) {
dev_err(&pdev->dev, "platform_get_irq failed\n");
return motg->irq;
}
--
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 02/12] phy: omap-control: Update DT binding information

2014-03-05 Thread Roger Quadros
On 03/04/2014 06:28 PM, Tony Lindgren wrote:
> * Roger Quadros  [140304 01:17]:
>> Hi Tony,
>>
>> On 03/03/2014 09:02 PM, Tony Lindgren wrote:
>>> * Roger Quadros  [140303 07:10]:
 Move omap-control binding information to the right location.

 Signed-off-by: Roger Quadros 
 ---
  Documentation/devicetree/bindings/phy/ti-phy.txt   | 25 
 ++
  Documentation/devicetree/bindings/usb/omap-usb.txt | 24 
 -
  2 files changed, 25 insertions(+), 24 deletions(-)

 diff --git a/Documentation/devicetree/bindings/phy/ti-phy.txt 
 b/Documentation/devicetree/bindings/phy/ti-phy.txt
 index 207e14c..41dc132 100644
 --- a/Documentation/devicetree/bindings/phy/ti-phy.txt
 +++ b/Documentation/devicetree/bindings/phy/ti-phy.txt
 @@ -1,5 +1,30 @@
  TI PHY: DT DOCUMENTATION FOR PHYs in TI PLATFORMs
  
 +OMAP CONTROL PHY
 +
 +Required properties:
 + - compatible: Should be one of
 + "ti,control-phy-otghs" - if it has otghs_control mailbox register as on 
 OMAP4.
 + "ti,control-phy-usb2" - if it has Power down bit in control_dev_conf 
 register
 +e.g. USB2_PHY on OMAP5.
 + "ti,control-phy-pipe3" - if it has DPLL and individual Rx & Tx power 
 control
 +e.g. USB3 PHY and SATA PHY on OMAP5.
 + "ti,control-phy-dra7usb2" - if it has power down register like USB2 PHY 
 on
 +DRA7 platform.
 + "ti,control-phy-am437usb2" - if it has power down register like USB2 PHY 
 on
 +AM437 platform.
>>>
>>> To me it seems that you can leave out all the above. You can set these falgs
>>> flags directly in the driver based on the compatible flag. Then just 
>>> initialize
>>> the .data in the driver based on the compatible flag.
>>
>> I'm not sure if I got you. A single platform can have different type of phys.
>>
>> e.g. OMAP5 has both usb2 and pipe3 PHYs,
>> DRA7 has both pipe3 and usb2 PHYs, but this usb2 PHY is not compatible with 
>> OMAP5 one
>> so we need a new compatible id for that.
>>
>> To add to the woes, the designers were creative enough to make another 
>> mutation to
>> the USB2 PHY for AM437x, :(
> 
> Oh OK, in that case the compatible flag may not be enough for configuring the
> various instances.
>  
>> What do you suggest the compatible ids should look like for these 5 types of 
>> PHY control?
>> OTGHS(OMAP4 & 5)
>> USB2 (OMAP5)
>> PIPE3(OMAP5 & DRA7)
>> USB2x(DRA7)
>> USB2y(AM437)
> 
> I think in that case having the various instances fully configurable from
> device tree is OK if you prefer that. But if you wanted to use the
> compatible flag, then you could do something like this:

I'll stick to the compatible flag.

> 
> ti,control-phy-omap4-otghs(assuming same on omap4 & 5)
> ti,control-phy-omap5-usb2
> ti,control-phy-omap5-pipe3(assuming same on omap5 & dra7)
> ti,control-phy-dra7-usb2x
> ti,control-phy-am437-usb2y

OK.

The last 2 can just be 

ti,control-phy-dra7-usb2
ti,control-phy-am437-usb2

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 06/11] usb: dwc3: core: allocate scratch buffers

2014-03-05 Thread George Cherian

On 2/26/2014 1:10 AM, Felipe Balbi wrote:

We must read HWPARAMS4 register to figure out
how many scratch buffers we should allocate.

Later patch will use "Set Scratchpad Buffer
Array" command to pass the pointer to the
IP so it can be used during hibernation.

Signed-off-by: Felipe Balbi 
---
  drivers/usb/dwc3/core.c | 95 +
  drivers/usb/dwc3/core.h |  6 
  2 files changed, 101 insertions(+)

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index a49217a..2864aad 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -242,6 +242,80 @@ static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
}
  }
  
+static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc)

+{
+   if (!dwc->has_hibernation)
+   return 0;
+
+   if (!dwc->nr_scratch)
+   return 0;
+
+   dwc->scratchbuf = kmalloc_array(dwc->nr_scratch,
+   DWC3_SCRATCHBUF_SIZE, GFP_KERNEL);
+   if (!dwc->scratchbuf)
+   return -ENOMEM;
+
+   return 0;
+}
+
+static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
+{
+   dma_addr_t scratch_addr;
+   u32 param;
+   int ret;
+


Shouldn't there be check for  dwc->scratchbuf and dwc->nr_scratch
before calling dma_map_single?

This fails in AM437x since both these are zero and leads to following crash

[   57.914762] Unable to handle kernel NULL pointer dereference at 
virtual address 

[   57.926272] pgd = ed43c000
[   57.930222] [] *pgd=ac05a831, *pte=, *ppte=
[   57.939425] Internal error: Oops: 817 [#1] SMP ARM
[   57.945964] Modules linked in: dwc3(+) snd_soc_omap snd_pcm_dmaengine 
snd_soc_core snd_compress regmap_spi snd_pcm snd_timer snd soundcore 
dwc3_omap matrix_keypad
[   57.965884] CPU: 0 PID: 1126 Comm: insmod Tainted: GW 
3.14.0-rc5-00151-gc02b641-dirty #2

[   57.978198] task: ed1e2ac0 ti: ed456000 task.ti: ed456000
[   57.985570] PC is at v7_dma_clean_range+0x1c/0x34
[   57.992001] LR is at dma_cache_maint_page+0x90/0x120
[   57.998765] pc : []lr : [] psr: 000f0113
[   57.998765] sp : ed457d18  ip : edff2000  fp : c07f0924
[   58.014383] r10: c0888940  r9 :   r8 : c07f39c4
[   58.021495] r7 : 0008  r6 :   r5 : 000c  r4 : c001d75c
[   58.030374] r3 : 001f  r2 : 0020  r1 :   r0 : 
[   58.039258] Flags: nzcv  IRQs on  FIQs on  Mode SVC_32  ISA ARM 
Segment user

[   58.048971] Control: 10c53c7d  Table: ad43c059  DAC: 0015
[   58.056793] Process insmod (pid: 1126, stack limit = 0xed456248)
[   58.064967] Stack: (0xed457d18 to 0xed458000)
[   58.070899] 
7d00:    
ed456000
[   58.082031] 7d20:   ee7f2000   
48a22004 25803004 ed5ffc10
[   58.093164] 7d40: 000c0002 c00196f4 c001d75c c053205c bf0b1098 
 ee7f2000 ed474810
[   58.104298] 7d60: c07f08c0 c0019810   c000 
bf0ab0e0  
[   58.115425] 7d80:  ed5ffc10 bf0b2b70   
bf0b2b70 ed456000 0001
[   58.126553] 7da0:  c0352de8 c0352dd0 c0de004c ed5ffc10 
c0351a30 ed5ffc10 bf0b2b70
[   58.137682] 7dc0: ed5ffc44  bf0b6000 c0351be0  
bf0b2b70 c0351b4c c03501c4
[   58.148810] 7de0: ed02f0a8 ed4fded0 bf0b2b70 ed2d7180 c0863090 
c03511c4 bf0b10b8 bf0b2b70
[   58.159937] 7e00: bf0b2bd8 bf0b2b70 bf0b2bd8 bf0b2bcc 0001 
c0352210  ed457f58
[   58.171064] 7e20: bf0b2bd8 c0008908 ed1e2ac0 c0539790 0001 
ed07de40 c0d9fe2c 0001
[   58.182194] 7e40: ed456000 c008565c 6013 c0846f60 bf0b2bcc 
0001 ed07de40 c0539790
[   58.193325] 7e60: c0846f80 c0846f5c  c00627d4  
ed5f9f80 ed80 ed457f58
[   58.204453] 7e80: bf0b2bd8 bf0b2bcc 0001 ed07de40 c0d9fe2c 
0001 ed456000 c00ac1a4
[   58.215582] 7ea0: bf0b2bd8 7fff c00a9cd4 ed456000 c00a99a4 
c0d9fe24 ed456000 bf0b2c14
[   58.226713] 7ec0: bf0b2d44 c07f0940 ed457ef4  bf0b2bd8 
ed456000  c0733ccc
[   58.237842] 7ee0: 73646e65 c0539cf0 f08c b6f5a000 071e 
  
[   58.248971] 7f00:      
  
[   58.260099] 7f20:     00d2 
000c479e b6e96000 b6f6d150
[   58.271227] 7f40: 0080 c000e6e4 ed456000   
c00aca2c f07fc000 000c479e
[   58.282357] 7f60: f089166c f089147e f08bf834 8d44 9e54 
  
[   58.293484] 7f80: 0030 0031 0017 001b 0011 
 4e9c8ef8 
[   58.304612] 7fa0: 000210a0 c000e520 4e9c8ef8  b6e96000 
000c479e b6f6d150 0002
[   58.315742] 7fc0: 4e9c8ef8  000210a0 0080 00021088 
000c479e b6f6d150 
[   58.326875] 7fe0: 4e978990 bec5bc08 b6f65aa8 4e9789a0 8010 
b6e96000 c8c0c094 4ac84040
[   58.338044] [] (v7_dma_clean_range) from [] 
(dma_cache_maint_page+0x90/0x120)

Re: [PATCH v7 0/4] phy: Add new Exynos USB 2.0 PHY driver

2014-03-05 Thread Kishon Vijay Abraham I

Hi,

On Tuesday 04 March 2014 08:53 PM, Kamil Debski wrote:

Hi,

This is the seventh version of this patchset. First and most significant change
is that this patchset includes only patches touching the Generic PHY Framework.
Patches to the USB controllers were stripped as they require additional work.
S5PV210 support is also omitted - it requires more testing.

Thank you to everyone who joined the discussion, reviewed the patched and
contributed to making the code and consequently the Linux Kernel better.


Can you refresh your patches on
git://git.kernel.org/pub/scm/linux/kernel/git/kishon/linux-phy.git next
It's not applying cleanly.

While at that pls fix these checkpatch errors/warnings

on patch 3.
ERROR: code indent should use tabs where possible
#854: FILE: drivers/phy/phy-exynos4x12-usb2.c:233:
+^I^I^IEXYNOS_4x12_MODE_SWITCH_OFFSET,$

CHECK: Alignment should match open parenthesis
#854: FILE: drivers/phy/phy-exynos4x12-usb2.c:233:
+   regmap_update_bits(drv->reg_sys,
+   EXYNOS_4x12_MODE_SWITCH_OFFSET,

ERROR: code indent should use tabs where possible
#855: FILE: drivers/phy/phy-exynos4x12-usb2.c:234:
+^I^I^IEXYNOS_4x12_MODE_SWITCH_MASK,$

CHECK: Alignment should match open parenthesis
#986: FILE: drivers/phy/phy-samsung-usb2.c:29:
+   dev_dbg(drv->dev, "Request to power_on \"%s\" usb phy\n",
+   inst->cfg->label);

CHECK: Alignment should match open parenthesis
#1014: FILE: drivers/phy/phy-samsung-usb2.c:57:
+   dev_dbg(drv->dev, "Request to power_off \"%s\" usb phy\n",
+   inst->cfg->label);

CHECK: Alignment should match open parenthesis
#1146: FILE: drivers/phy/phy-samsung-usb2.c:189:
+   dev_err(drv->dev, "Failed to create usb2_phy \"%s\"\n",
+

And on patch 4

CHECK: Alignment should match open parenthesis
#350: FILE: drivers/phy/phy-exynos5250-usb2.c:212:
+   regmap_update_bits(drv->reg_sys,
+   EXYNOS_5250_MODE_SWITCH_OFFSET,

-Kishon
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Loan Application

2014-03-05 Thread Loans
Loan Application at a low rate of 0.5% send your Name,Amount,Phone and country 
to standar...@56788.com

Note: $5,000.00 USD minimum and $100,000,000 Maximum.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH] usb: musb: Remove dependency on BROKEN and mach/ headers from da8xx glue

2014-03-05 Thread Christian Riesch
Signed-off-by: Christian Riesch 
Cc: Felipe Balbi 
---
Hi,

I have successfully tested this driver with kernel 3.14-rc5 on a custom
Texas Instruments AM1808 board in gadget mode, RNDIS network gadget.
Therefore I think the dependency on BROKEN can be removed.

Commit 787f5627bec80094db487bfcb401e9744f181aed that added this dependancy
states that the dependency on  headers should also be removed.
Currently, the CFGCHIP2 define in the code is the only reason why a
 header is included in the file, so I am replacing it with the
hardcoded address.

Regards, Christian


 drivers/usb/musb/Kconfig |1 -
 drivers/usb/musb/da8xx.c |3 +--
 2 files changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
index 688dc8b..af370a4 100644
--- a/drivers/usb/musb/Kconfig
+++ b/drivers/usb/musb/Kconfig
@@ -67,7 +67,6 @@ config USB_MUSB_DAVINCI
 config USB_MUSB_DA8XX
tristate "DA8xx/OMAP-L1x"
depends on ARCH_DAVINCI_DA8XX
-   depends on BROKEN
 
 config USB_MUSB_TUSB6010
tristate "TUSB6010"
diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
index e3486de..6f4d8c7 100644
--- a/drivers/usb/musb/da8xx.c
+++ b/drivers/usb/musb/da8xx.c
@@ -34,7 +34,6 @@
 #include 
 #include 
 
-#include 
 #include 
 
 #include "musb_core.h"
@@ -80,7 +79,7 @@
 
 #define DA8XX_MENTOR_CORE_OFFSET 0x400
 
-#define CFGCHIP2   IO_ADDRESS(DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP2_REG)
+#define CFGCHIP2   IOMEM(UL(0xfec14184))
 
 struct da8xx_glue {
struct device   *dev;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 02/12] phy: omap-control: Update DT binding information

2014-03-05 Thread Roger Quadros
+ George

Tony,

On 03/04/2014 06:28 PM, Tony Lindgren wrote:
> * Roger Quadros  [140304 01:17]:
>> Hi Tony,
>>
>> On 03/03/2014 09:02 PM, Tony Lindgren wrote:
>>> * Roger Quadros  [140303 07:10]:
 Move omap-control binding information to the right location.

 Signed-off-by: Roger Quadros 
 ---
  Documentation/devicetree/bindings/phy/ti-phy.txt   | 25 
 ++
  Documentation/devicetree/bindings/usb/omap-usb.txt | 24 
 -
  2 files changed, 25 insertions(+), 24 deletions(-)

 diff --git a/Documentation/devicetree/bindings/phy/ti-phy.txt 
 b/Documentation/devicetree/bindings/phy/ti-phy.txt
 index 207e14c..41dc132 100644
 --- a/Documentation/devicetree/bindings/phy/ti-phy.txt
 +++ b/Documentation/devicetree/bindings/phy/ti-phy.txt
 @@ -1,5 +1,30 @@
  TI PHY: DT DOCUMENTATION FOR PHYs in TI PLATFORMs
  
 +OMAP CONTROL PHY
 +
 +Required properties:
 + - compatible: Should be one of
 + "ti,control-phy-otghs" - if it has otghs_control mailbox register as on 
 OMAP4.
 + "ti,control-phy-usb2" - if it has Power down bit in control_dev_conf 
 register
 +e.g. USB2_PHY on OMAP5.
 + "ti,control-phy-pipe3" - if it has DPLL and individual Rx & Tx power 
 control
 +e.g. USB3 PHY and SATA PHY on OMAP5.
 + "ti,control-phy-dra7usb2" - if it has power down register like USB2 PHY 
 on
 +DRA7 platform.
 + "ti,control-phy-am437usb2" - if it has power down register like USB2 PHY 
 on
 +AM437 platform.
>>>
>>> To me it seems that you can leave out all the above. You can set these falgs
>>> flags directly in the driver based on the compatible flag. Then just 
>>> initialize
>>> the .data in the driver based on the compatible flag.
>>
>> I'm not sure if I got you. A single platform can have different type of phys.
>>
>> e.g. OMAP5 has both usb2 and pipe3 PHYs,
>> DRA7 has both pipe3 and usb2 PHYs, but this usb2 PHY is not compatible with 
>> OMAP5 one
>> so we need a new compatible id for that.
>>
>> To add to the woes, the designers were creative enough to make another 
>> mutation to
>> the USB2 PHY for AM437x, :(
> 
> Oh OK, in that case the compatible flag may not be enough for configuring the
> various instances.
>  
>> What do you suggest the compatible ids should look like for these 5 types of 
>> PHY control?
>> OTGHS(OMAP4 & 5)
>> USB2 (OMAP5)
>> PIPE3(OMAP5 & DRA7)
>> USB2x(DRA7)
>> USB2y(AM437)
> 
> I think in that case having the various instances fully configurable from
> device tree is OK if you prefer that. But if you wanted to use the
> compatible flag, then you could do something like this:
> 
> ti,control-phy-omap4-otghs(assuming same on omap4 & 5)
> ti,control-phy-omap5-usb2
> ti,control-phy-omap5-pipe3(assuming same on omap5 & dra7)
> ti,control-phy-dra7-usb2x
> ti,control-phy-am437-usb2y
> ...
> 

Please note that the original bindings were added in v3.13 and I'm just moving 
the documentation
to the right location. So I don't think we should change the bindings now.

"ti,control-phy-dra7usb2" and "ti,control-phy-am437usb2" have no users still so 
we could probably
change those to "ti,control-phy-dra7-usb2" and "ti,control-phy-am437-usb2".

What do you say?

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 10/14] usb: phy: msm: Use reset framework for LINK and PHY resets

2014-03-05 Thread Sergei Shtylyov

Hello.

On 05-03-2014 14:13, Ivan T. Ivanov wrote:


From: "Ivan T. Ivanov" 



Signed-off-by: Ivan T. Ivanov 
---
  drivers/usb/phy/phy-msm-usb.c |   30 ++
  include/linux/usb/msm_hsusb.h |3 +++
  2 files changed, 25 insertions(+), 8 deletions(-)



diff --git a/drivers/usb/phy/phy-msm-usb.c b/drivers/usb/phy/phy-msm-usb.c
index 298820f..7e5c4ab 100644
--- a/drivers/usb/phy/phy-msm-usb.c
+++ b/drivers/usb/phy/phy-msm-usb.c

[...]

@@ -235,12 +236,16 @@ static void ulpi_init(struct msm_otg *motg)

  static int msm_otg_link_clk_reset(struct msm_otg *motg, bool assert)
  {
-   int ret = 0;
+   int ret;

-   if (!motg->pdata->link_clk_reset)
-   return ret;
+   if (motg->pdata->link_clk_reset)
+   ret = motg->pdata->link_clk_reset(motg->clk, assert);
+   else
+   if (assert)


   Kernel style assumes:

else if (assert)


+   ret = reset_control_assert(motg->link_rst);
+   else
+   ret = reset_control_deassert(motg->link_rst);


[...]

WBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 6/6] arm/dts: added dt properties to adapt to the new phy framwork

2014-03-05 Thread Kishon Vijay Abraham I

Tony/Benoit,

On Monday 03 March 2014 05:08 PM, Kishon Vijay Abraham I wrote:

Added device tree bindings for dwc3, usb2 and usb3 PHYs. The documentation
of these can be found at Documentation/devicetree/bindings/phy/phy-bindings.txt
and Documentation/devicetree/bindings/phy/ti-phy.txt.


Can this patch be queued for 3.15 merge window?

Thanks
Kishon



Signed-off-by: Kishon Vijay Abraham I 
---
  arch/arm/boot/dts/omap5.dtsi |5 -
  1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/arch/arm/boot/dts/omap5.dtsi b/arch/arm/boot/dts/omap5.dtsi
index a72813a..1c68558 100644
--- a/arch/arm/boot/dts/omap5.dtsi
+++ b/arch/arm/boot/dts/omap5.dtsi
@@ -732,7 +732,8 @@
compatible = "snps,dwc3";
reg = <0x4a03 0x1>;
interrupts = ;
-   usb-phy = <&usb2_phy>, <&usb3_phy>;
+   phys = <&usb2_phy>, <&usb3_phy>;
+   phy-names = "usb2-phy", "usb3-phy";
dr_mode = "peripheral";
tx-fifo-resize;
};
@@ -749,6 +750,7 @@
compatible = "ti,omap-usb2";
reg = <0x4a084000 0x7c>;
ctrl-module = <&omap_control_usb2phy>;
+   #phy-cells = <0>;
};

usb3_phy: usb3phy@4a084400 {
@@ -758,6 +760,7 @@
  <0x4a084c00 0x40>;
reg-names = "phy_rx", "phy_tx", "pll_ctrl";
ctrl-module = <&omap_control_usb3phy>;
+   #phy-cells = <0>;
};
};



--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 01/23] libusbg: Remove unused variables to make compiler happy.

2014-03-05 Thread Krzysztof Opasiak
Signed-off-by: Krzysztof Opasiak 
---
 examples/gadget-acm-ecm.c |1 -
 examples/show-gadgets.c   |1 -
 src/usbg.c|2 --
 3 files changed, 4 deletions(-)

diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c
index b3c776d..5b027b6 100644
--- a/examples/gadget-acm-ecm.c
+++ b/examples/gadget-acm-ecm.c
@@ -31,7 +31,6 @@ int main(void)
 {
usbg_state *s;
usbg_gadget *g;
-   usbg_function *f;
usbg_config *c;
usbg_function *f_acm0, *f_acm1, *f_ecm;
int ret = -EINVAL;
diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c
index 9814039..7ba9687 100644
--- a/examples/show-gadgets.c
+++ b/examples/show-gadgets.c
@@ -125,7 +125,6 @@ int main(void)
usbg_gadget *g;
usbg_function *f;
usbg_config *c;
-   usbg_binding *b;
 
s = usbg_init("/sys/kernel/config");
if (!s) {
diff --git a/src/usbg.c b/src/usbg.c
index 5e803f1..91165b8 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -110,14 +110,12 @@ const char *function_names[] =
 };
 
 #define ERROR(msg, ...) do {\
-char *str;\
 fprintf(stderr, "%s()  "msg" \n", \
 __func__, ##__VA_ARGS__);\
 fflush(stderr);\
 } while (0)
 
 #define ERRORNO(msg, ...) do {\
-char *str;\
 fprintf(stderr, "%s()  %s: "msg" \n", \
 __func__, strerror(errno), ##__VA_ARGS__);\
 fflush(stderr);\
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 00/23] libusbg: Add error code propagation and attributes refreshing.

2014-03-05 Thread Krzysztof Opasiak
Dear Matt,

I have prepared next series of patches. This time I have added error code
propagation which you have palced at todo list.

In this series I have also removed caching gadget/function/config attributes
in internal structures. Thos attributes may be changed by kernel when
enabling gadget, so user should get actual attributes each time he use
usbg_get_*() function.

There was also some bug in matching between binding and function.
Previously library took only function type and ignore instance name.
Now while lookup both function type and instance name is considered.

This series depends on my previous series you can easily find them on a list
or in github pull request. 

--
BR's
Krzysztof Opasiak
Samsung R&D Institute Poland
Samsung Electronics


---
Krzysztof Opasiak (23):
  libusbg: Remove unused variables to make compiler happy.
  libusbg: Refresh gadget attributes while each get.
  libusbg: Refresh gadget strings while each get.
  libusbg: Refresh config attributes while each get.
  libusbg: Refresh config strings while each get.
  libusbg: Refresh function attributes while each get.
  libusbg: Add internal free functions for each library structure.
  libusbg: Fix wrong binding parsing.
  libusbg: Add error handling to usbg_init() and related functions.
  libusbg: Return usbg_error instead of -1 in usbg_*_len().
  libusbg: Return usbg_error instead of char* in usbg_get_*_name().
  libusbg: Add parenthesis to INSERT_TAILQ_STRING_ORDER macro.
  libusbg: Add return value to gadget creation functions.
  libusbg: Add return value to usbg_set_gadget_*() functions.
  libusbg: Add return value to usb function related functions.
  libusbg: Add return value to config related functions.
  libusbg: Add return value to usbg_enable/disable_gadget().
  libusbg: Return error code instead of NULL pointer.
  libusbg: Return error code instead of NULL pointer - config.
  libusbg: Change usbg_get_function_attrs() to return error code.
  libusbg: Return error code instead of -1.
  libusbg: Add functions for getting error strings.
  libusbg: Update examples to use returned error codes.

 examples/gadget-acm-ecm.c |   73 ++-
 examples/show-gadgets.c   |   48 +-
 include/usbg/usbg.h   |  205 --
 src/usbg.c| 1553 +
 4 files changed, 1246 insertions(+), 633 deletions(-)

-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 02/23] libusbg: Refresh gadget attributes while each get.

2014-03-05 Thread Krzysztof Opasiak
Gadget attributes may be changed by kernel or other
user so they should not be cached in library structures.

Signed-off-by: Krzysztof Opasiak 
---
 src/usbg.c |   16 +---
 1 file changed, 1 insertion(+), 15 deletions(-)

diff --git a/src/usbg.c b/src/usbg.c
index 91165b8..ae26434 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -49,7 +49,6 @@ struct usbg_gadget
char path[USBG_MAX_PATH_LENGTH];
char udc[USBG_MAX_STR_LENGTH];
 
-   usbg_gadget_attrs attrs;
usbg_gadget_strs strs;
 
TAILQ_ENTRY(usbg_gadget) gnode;
@@ -465,7 +464,6 @@ static int usbg_parse_gadgets(char *path, usbg_state *s)
g->parent = s;
/* UDC bound to, if any */
usbg_read_string(path, g->name, "UDC", g->udc);
-   usbg_parse_gadget_attrs(path, g->name, &g->attrs);
usbg_parse_strings(path, g->name, &g->strs);
usbg_parse_functions(path, g);
usbg_parse_configs(path, g);
@@ -674,7 +672,6 @@ usbg_gadget *usbg_create_gadget_vid_pid(usbg_state *s, char 
*name,
usbg_write_hex16(s->path, name, "idVendor", idVendor);
usbg_write_hex16(s->path, name, "idProduct", idProduct);
 
-   usbg_parse_gadget_attrs(s->path, name, &g->attrs);
usbg_parse_strings(s->path, name, &g->strs);
 
INSERT_TAILQ_STRING_ORDER(&s->gadgets, ghead, name, g, gnode);
@@ -703,8 +700,6 @@ usbg_gadget *usbg_create_gadget(usbg_state *s, char *name,
if (g) {
if (g_attrs)
usbg_set_gadget_attrs(g, g_attrs);
-   else
-   usbg_parse_gadget_attrs(s->path, name, &g->attrs);
 
if (g_strs)
usbg_set_gadget_strs(g, LANG_US_ENG, g_strs);
@@ -721,7 +716,7 @@ usbg_gadget_attrs *usbg_get_gadget_attrs(usbg_gadget *g,
usbg_gadget_attrs *g_attrs)
 {
if (g && g_attrs)
-   *g_attrs = g->attrs;
+   usbg_parse_gadget_attrs(g->path, g->name, g_attrs);
else
g_attrs = NULL;
 
@@ -753,7 +748,6 @@ void usbg_set_gadget_attrs(usbg_gadget *g, 
usbg_gadget_attrs *g_attrs)
if (!g || !g_attrs)
return;
 
-   g->attrs = *g_attrs;
usbg_write_hex16(g->path, g->name, "bcdUSB", g_attrs->bcdUSB);
usbg_write_hex8(g->path, g->name, "bDeviceClass", 
g_attrs->bDeviceClass);
usbg_write_hex8(g->path, g->name, "bDeviceSubClass", 
g_attrs->bDeviceSubClass);
@@ -766,49 +760,41 @@ void usbg_set_gadget_attrs(usbg_gadget *g, 
usbg_gadget_attrs *g_attrs)
 
 void usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor)
 {
-   g->attrs.idVendor = idVendor;
usbg_write_hex16(g->path, g->name, "idVendor", idVendor);
 }
 
 void usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct)
 {
-   g->attrs.idProduct = idProduct;
usbg_write_hex16(g->path, g->name, "idProduct", idProduct);
 }
 
 void usbg_set_gadget_device_class(usbg_gadget *g, uint8_t bDeviceClass)
 {
-   g->attrs.bDeviceClass = bDeviceClass;
usbg_write_hex8(g->path, g->name, "bDeviceClass", bDeviceClass);
 }
 
 void usbg_set_gadget_device_protocol(usbg_gadget *g, uint8_t bDeviceProtocol)
 {
-   g->attrs.bDeviceProtocol = bDeviceProtocol;
usbg_write_hex8(g->path, g->name, "bDeviceProtocol", bDeviceProtocol);
 }
 
 void usbg_set_gadget_device_subclass(usbg_gadget *g, uint8_t bDeviceSubClass)
 {
-   g->attrs.bDeviceSubClass = bDeviceSubClass;
usbg_write_hex8(g->path, g->name, "bDeviceSubClass", bDeviceSubClass);
 }
 
 void usbg_set_gadget_device_max_packet(usbg_gadget *g, uint8_t bMaxPacketSize0)
 {
-   g->attrs.bMaxPacketSize0 = bMaxPacketSize0;
usbg_write_hex8(g->path, g->name, "bMaxPacketSize0", bMaxPacketSize0);
 }
 
 void usbg_set_gadget_device_bcd_device(usbg_gadget *g, uint16_t bcdDevice)
 {
-   g->attrs.bcdDevice = bcdDevice;
usbg_write_hex16(g->path, g->name, "bcdDevice", bcdDevice);
 }
 
 void usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB)
 {
-   g->attrs.bcdUSB = bcdUSB;
usbg_write_hex16(g->path, g->name, "bcdUSB", bcdUSB);
 }
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 03/23] libusbg: Refresh gadget strings while each get.

2014-03-05 Thread Krzysztof Opasiak
Gadget strings should not be cached in library.
Removing internal strings structure allowed to add
full support for multilingual strings.

Signed-off-by: Krzysztof Opasiak 
---
 examples/show-gadgets.c |2 +-
 include/usbg/usbg.h |6 --
 src/usbg.c  |   48 +--
 3 files changed, 22 insertions(+), 34 deletions(-)

diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c
index 7ba9687..7d9909a 100644
--- a/examples/show-gadgets.c
+++ b/examples/show-gadgets.c
@@ -51,7 +51,7 @@ void show_gadget(usbg_gadget *g)
fprintf(stdout, "  idVendor\t\t0x%04x\n", g_attrs.idVendor);
fprintf(stdout, "  idProduct\t\t0x%04x\n", g_attrs.idProduct);
 
-   usbg_get_gadget_strs(g, &g_strs);
+   usbg_get_gadget_strs(g, LANG_US_ENG, &g_strs);
fprintf(stdout, "  Serial Number\t\t%s\n", g_strs.str_ser);
fprintf(stdout, "  Manufacturer\t\t%s\n", g_strs.str_mnf);
fprintf(stdout, "  Product\t\t%s\n", g_strs.str_prd);
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 71845cd..e1a0b5c 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -355,10 +355,12 @@ extern void usbg_set_gadget_device_bcd_usb(usbg_gadget 
*g, uint16_t bcdUSB);
 /**
  * @brief Get the USB gadget strings
  * @param g Pointer to gadget
+ * @param lang Language of strings
  * @param g_sttrs Structure to be filled
- * @retur Pointer to filled structure or NULL if error occurred.
+ * @retur Pointer to filled structure or NULL if error occurred or
+ * if no strings for given language.
  */
-extern usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget *g,
+extern usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget *g, int lang,
usbg_gadget_strs *g_strs);
 
 /**
diff --git a/src/usbg.c b/src/usbg.c
index ae26434..4a69b9c 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -49,8 +49,6 @@ struct usbg_gadget
char path[USBG_MAX_PATH_LENGTH];
char udc[USBG_MAX_STR_LENGTH];
 
-   usbg_gadget_strs strs;
-
TAILQ_ENTRY(usbg_gadget) gnode;
TAILQ_HEAD(chead, usbg_config) configs;
TAILQ_HEAD(fhead, usbg_function) functions;
@@ -435,17 +433,26 @@ static void usbg_parse_gadget_attrs(char *path, char 
*name,
g_attrs->bcdDevice = (uint16_t)usbg_read_hex(path, name, "bcdDevice");
 }
 
-static void usbg_parse_strings(char *path, char *name, usbg_gadget_strs 
*g_strs)
+static usbg_gadget_strs *usbg_parse_strings(char *path, char *name, int lang,
+   usbg_gadget_strs *g_strs)
 {
-   /* Strings - hardcoded to U.S. English only for now */
-   int lang = LANG_US_ENG;
+   DIR *dir;
char spath[USBG_MAX_PATH_LENGTH];
 
sprintf(spath, "%s/%s/%s/0x%x", path, name, STRINGS_DIR, lang);
 
-   usbg_read_string(spath, "", "serialnumber", g_strs->str_ser);
-   usbg_read_string(spath, "", "manufacturer", g_strs->str_mnf);
-   usbg_read_string(spath, "", "product", g_strs->str_prd);
+   /* Check if directory exist */
+   dir = opendir(spath);
+   if (dir) {
+   closedir(dir);
+   usbg_read_string(spath, "", "serialnumber", g_strs->str_ser);
+   usbg_read_string(spath, "", "manufacturer", g_strs->str_mnf);
+   usbg_read_string(spath, "", "product", g_strs->str_prd);
+   } else {
+   g_strs = NULL;
+   }
+
+   return g_strs;
 }
 
 static int usbg_parse_gadgets(char *path, usbg_state *s)
@@ -464,7 +471,6 @@ static int usbg_parse_gadgets(char *path, usbg_state *s)
g->parent = s;
/* UDC bound to, if any */
usbg_read_string(path, g->name, "UDC", g->udc);
-   usbg_parse_strings(path, g->name, &g->strs);
usbg_parse_functions(path, g);
usbg_parse_configs(path, g);
TAILQ_INSERT_TAIL(&s->gadgets, g, gnode);
@@ -672,8 +678,6 @@ usbg_gadget *usbg_create_gadget_vid_pid(usbg_state *s, char 
*name,
usbg_write_hex16(s->path, name, "idVendor", idVendor);
usbg_write_hex16(s->path, name, "idProduct", idProduct);
 
-   usbg_parse_strings(s->path, name, &g->strs);
-
INSERT_TAILQ_STRING_ORDER(&s->gadgets, ghead, name, g, gnode);
}
 
@@ -703,8 +707,6 @@ usbg_gadget *usbg_create_gadget(usbg_state *s, char *name,
 
if (g_strs)
usbg_set_gadget_strs(g, LANG_US_ENG, g_strs);
-   else
-   usbg_parse_strings(s->path, name, &g->strs);
 
INSERT_TAILQ_STRING_ORDER(&s->gadgets, ghead, name, g, gnode);
}
@@ -798,11 +800,11 @@ void usbg_set_gadget_device_bcd_usb(usbg_gadget *g, 
uint16_t bcdUSB)
usbg_write_hex16(g->path, g->name, "bcdUSB", bcdUSB);
 }
 
-usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget *g,
+usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget *g, int lang,
usbg_gadget_strs *g_strs)
 {
if (g && g_strs)
-

[PATCH 05/23] libusbg: Refresh config strings while each get.

2014-03-05 Thread Krzysztof Opasiak
Config strings should not be cached in library.
Removing internal strings structure allowed to add
full support for multilingual strings.

Signed-off-by: Krzysztof Opasiak 
---
 examples/show-gadgets.c |2 +-
 include/usbg/usbg.h |3 ++-
 src/usbg.c  |   31 ---
 3 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c
index 7d9909a..2665262 100644
--- a/examples/show-gadgets.c
+++ b/examples/show-gadgets.c
@@ -108,7 +108,7 @@ void show_config(usbg_config *c)
fprintf(stdout, "MaxPower\t\t%d\n", c_attrs.bMaxPower);
fprintf(stdout, "bmAttributes\t0x%02x\n", c_attrs.bmAttributes);
 
-   usbg_get_config_strs(c, &c_strs);
+   usbg_get_config_strs(c, LANG_US_ENG, &c_strs);
fprintf(stdout, "configuration\t%s\n", c_strs.configuration);
 
usbg_for_each_binding(b, c) {
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index e1a0b5c..562fdc5 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -488,10 +488,11 @@ extern void usbg_set_config_bm_attrs(usbg_config *c, int 
bmAttributes);
 /**
  * @brief Get the USB configuration strings
  * @param c Pointer to configuration
+ * @param lang Language of strings
  * @param c_sttrs Structure to be filled
  * @retur Pointer to filled structure or NULL if error occurred.
  */
-extern usbg_config_strs *usbg_get_config_strs(usbg_config *c,
+extern usbg_config_strs *usbg_get_config_strs(usbg_config *c, int lang,
usbg_config_strs *c_strs);
 
 /**
diff --git a/src/usbg.c b/src/usbg.c
index e11f44e..63b8a32 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -63,7 +63,6 @@ struct usbg_config
 
char name[USBG_MAX_NAME_LENGTH];
char path[USBG_MAX_PATH_LENGTH];
-   usbg_config_strs strs;
 };
 
 struct usbg_function
@@ -339,15 +338,24 @@ static void usbg_parse_config_attrs(char *path, char 
*name,
c_attrs->bmAttributes = usbg_read_hex(path, name, "bmAttributes");
 }
 
-static void usbg_parse_config_strs(char *path, char *name,
-   usbg_config_strs *c_attrs)
+static usbg_config_strs *usbg_parse_config_strs(char *path, char *name,
+   int lang, usbg_config_strs *c_strs)
 {
-   /* Hardcoded to US English right now*/
-   int lang = LANG_US_ENG;
+   DIR *dir;
char spath[USBG_MAX_PATH_LENGTH];
 
sprintf(spath, "%s/%s/%s/0x%x", path, name, STRINGS_DIR, lang);
-   usbg_read_string(spath, "", "configuration", c_attrs->configuration);
+
+   /* Check if directory exist */
+   dir = opendir(spath);
+   if (dir) {
+   closedir(dir);
+   usbg_read_string(spath, "", "configuration", 
c_strs->configuration);
+   } else {
+   c_strs = NULL;
+   }
+
+   return c_strs;
 }
 
 static void usbg_parse_config_bindings(usbg_config *c)
@@ -407,7 +415,6 @@ static int usbg_parse_configs(char *path, usbg_gadget *g)
c->parent = g;
strcpy(c->name, dent[i]->d_name);
strcpy(c->path, cpath);
-   usbg_parse_config_strs(cpath, c->name, &c->strs);
usbg_parse_config_bindings(c);
TAILQ_INSERT_TAIL(&g->configs, c, cnode);
free(dent[i]);
@@ -949,8 +956,6 @@ usbg_config *usbg_create_config(usbg_gadget *g, char *name,
 
if (c_strs)
usbg_set_config_string(c, LANG_US_ENG, c_strs->configuration);
-   else
-   usbg_parse_config_strs(c->path, c->name, &c->strs);
 
INSERT_TAILQ_STRING_ORDER(&g->configs, chead, name, c, cnode);
 
@@ -1007,11 +1012,11 @@ void usbg_set_config_bm_attrs(usbg_config *c, int 
bmAttributes)
usbg_write_hex8(c->path, c->name, "bmAttributes", bmAttributes);
 }
 
-usbg_config_strs *usbg_get_config_strs(usbg_config *c,
+usbg_config_strs *usbg_get_config_strs(usbg_config *c, int lang,
usbg_config_strs *c_strs)
 {
if (c && c_strs)
-   *c_strs = c->strs;
+   c_strs = usbg_parse_config_strs(c->path, c->name, lang, c_strs);
else
c_strs = NULL;
 
@@ -1032,10 +1037,6 @@ void usbg_set_config_string(usbg_config *c, int lang, 
char *str)
 
mkdir(path, S_IRWXU|S_IRWXG|S_IRWXO);
 
-   /* strings in library are hardcoded to US English for now */
-   if (lang == LANG_US_ENG)
-   strcpy(c->strs.configuration, str);
-
usbg_write_string(path, "", "configuration", str);
 }
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 04/23] libusbg: Refresh config attributes while each get.

2014-03-05 Thread Krzysztof Opasiak
Config attributes may be changed by kernel or other
user so they should not be cached in library structures.

Signed-off-by: Krzysztof Opasiak 
---
 src/usbg.c |   10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/src/usbg.c b/src/usbg.c
index 4a69b9c..e11f44e 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -63,7 +63,6 @@ struct usbg_config
 
char name[USBG_MAX_NAME_LENGTH];
char path[USBG_MAX_PATH_LENGTH];
-   usbg_config_attrs attrs;
usbg_config_strs strs;
 };
 
@@ -408,7 +407,6 @@ static int usbg_parse_configs(char *path, usbg_gadget *g)
c->parent = g;
strcpy(c->name, dent[i]->d_name);
strcpy(c->path, cpath);
-   usbg_parse_config_attrs(cpath, c->name, &c->attrs);
usbg_parse_config_strs(cpath, c->name, &c->strs);
usbg_parse_config_bindings(c);
TAILQ_INSERT_TAIL(&g->configs, c, cnode);
@@ -948,8 +946,6 @@ usbg_config *usbg_create_config(usbg_gadget *g, char *name,
 
if (c_attrs)
usbg_set_config_attrs(c, c_attrs);
-   else
-   usbg_parse_config_attrs(c->path, c->name, &c->attrs);
 
if (c_strs)
usbg_set_config_string(c, LANG_US_ENG, c_strs->configuration);
@@ -986,8 +982,6 @@ void usbg_set_config_attrs(usbg_config *c, 
usbg_config_attrs *c_attrs)
if (!c || !c_attrs)
return;
 
-   c->attrs = *c_attrs;
-
usbg_write_dec(c->path, c->name, "MaxPower", c_attrs->bMaxPower);
usbg_write_hex8(c->path, c->name, "bmAttributes", 
c_attrs->bmAttributes);
 }
@@ -996,7 +990,7 @@ usbg_config_attrs *usbg_get_config_attrs(usbg_config *c,
usbg_config_attrs *c_attrs)
 {
if (c && c_attrs)
-   *c_attrs = c->attrs;
+   usbg_parse_config_attrs(c->path, c->name, c_attrs);
else
c_attrs = NULL;
 
@@ -1005,13 +999,11 @@ usbg_config_attrs *usbg_get_config_attrs(usbg_config *c,
 
 void usbg_set_config_max_power(usbg_config *c, int bMaxPower)
 {
-   c->attrs.bMaxPower = bMaxPower;
usbg_write_dec(c->path, c->name, "MaxPower", bMaxPower);
 }
 
 void usbg_set_config_bm_attrs(usbg_config *c, int bmAttributes)
 {
-   c->attrs.bmAttributes = bmAttributes;
usbg_write_hex8(c->path, c->name, "bmAttributes", bmAttributes);
 }
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 07/23] libusbg: Add internal free functions for each library structure.

2014-03-05 Thread Krzysztof Opasiak
Library should have internal API for freing structures instead of
copy pasting same code in different places.

Signed-off-by: Krzysztof Opasiak 
---
 src/usbg.c |   77 +++-
 1 file changed, 50 insertions(+), 27 deletions(-)

diff --git a/src/usbg.c b/src/usbg.c
index d7284bb..198fc7a 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -266,6 +266,55 @@ static inline void usbg_write_string(char *path, char 
*name, char *file, char *b
usbg_write_buf(path, name, file, buf);
 }
 
+static inline void usbg_free_binding(usbg_binding *b)
+{
+   free(b);
+}
+
+static inline void usbg_free_function(usbg_function *f)
+{
+   free(f);
+}
+
+static void usbg_free_config(usbg_config *c)
+{
+   usbg_binding *b;
+   while (!TAILQ_EMPTY(&c->bindings)) {
+   b = TAILQ_FIRST(&c->bindings);
+   TAILQ_REMOVE(&c->bindings, b, bnode);
+   usbg_free_binding(b);
+   }
+   free(c);
+}
+
+static void usbg_free_gadget(usbg_gadget *g)
+{
+   usbg_config *c;
+   usbg_function *f;
+   while (!TAILQ_EMPTY(&g->configs)) {
+   c = TAILQ_FIRST(&g->configs);
+   TAILQ_REMOVE(&g->configs, c, cnode);
+   usbg_free_config(c);
+   }
+   while (!TAILQ_EMPTY(&g->functions)) {
+   f = TAILQ_FIRST(&g->functions);
+   TAILQ_REMOVE(&g->functions, f, fnode);
+   usbg_free_function(f);
+   }
+   free(g);
+}
+
+static void usbg_free_state(usbg_state *s)
+{
+   usbg_gadget *g;
+   while (!TAILQ_EMPTY(&s->gadgets)) {
+   g = TAILQ_FIRST(&s->gadgets);
+   TAILQ_REMOVE(&s->gadgets, g, gnode);
+   usbg_free_gadget(g);
+   }
+   free(s);
+}
+
 static void usbg_parse_function_attrs(usbg_function *f,
usbg_function_attrs *f_attrs)
 {
@@ -532,33 +581,7 @@ out:
 
 void usbg_cleanup(usbg_state *s)
 {
-   usbg_gadget *g;
-   usbg_config *c;
-   usbg_binding *b;
-   usbg_function *f;
-
-   while (!TAILQ_EMPTY(&s->gadgets)) {
-   g = TAILQ_FIRST(&s->gadgets);
-   while (!TAILQ_EMPTY(&g->configs)) {
-   c = TAILQ_FIRST(&g->configs);
-   while(!TAILQ_EMPTY(&c->bindings)) {
-   b = TAILQ_FIRST(&c->bindings);
-   TAILQ_REMOVE(&c->bindings, b, bnode);
-   free(b);
-   }
-   TAILQ_REMOVE(&g->configs, c, cnode);
-   free(c);
-   }
-   while (!TAILQ_EMPTY(&g->functions)) {
-   f = TAILQ_FIRST(&g->functions);
-   TAILQ_REMOVE(&g->functions, f, fnode);
-   free(f);
-   }
-   TAILQ_REMOVE(&s->gadgets, g, gnode);
-   free(g);
-   }
-
-   free(s);
+   usbg_free_state(s);
 }
 
 size_t usbg_get_configfs_path_len(usbg_state *s)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 08/23] libusbg: Fix wrong binding parsing.

2014-03-05 Thread Krzysztof Opasiak
usbg_parse_bindings() function has done parsing incorrectly
and in inefficent way. Changes made in this function provide
better performance and fix wrong linking issue when having
two instances of the same function.

Signed-off-by: Krzysztof Opasiak 
---
 src/usbg.c |   34 --
 1 file changed, 20 insertions(+), 14 deletions(-)

diff --git a/src/usbg.c b/src/usbg.c
index 198fc7a..255074f 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -408,9 +408,12 @@ static usbg_config_strs *usbg_parse_config_strs(char 
*path, char *name,
 
 static void usbg_parse_config_bindings(usbg_config *c)
 {
-   int i, n;
+   int i, n, nmb;
struct dirent **dent;
char bpath[USBG_MAX_PATH_LENGTH];
+   char file_name[USBG_MAX_PATH_LENGTH];
+   char target[USBG_MAX_STR_LENGTH];
+   char *target_name;
usbg_gadget *g = c->parent;
usbg_binding *b;
usbg_function *f;
@@ -420,19 +423,22 @@ static void usbg_parse_config_bindings(usbg_config *c)
TAILQ_INIT(&c->bindings);
 
n = scandir(bpath, &dent, bindings_select, alphasort);
-   for (i=0; i < n; i++) {
-   TAILQ_FOREACH(f, &g->functions, fnode) {
-   int n;
-   char contents[USBG_MAX_STR_LENGTH];
-   char cpath[USBG_MAX_PATH_LENGTH];
-   char fname[40];
-
-   sprintf(cpath, "%s/%s", bpath, dent[i]->d_name);
-   n = readlink(cpath, contents, USBG_MAX_PATH_LENGTH);
-   if (n<0)
-   ERRORNO("bytes %d contents %s\n", n, contents);
-   strcpy(fname, f->name);
-   if (strstr(contents, strtok(fname, "."))) {
+   for (i = 0; i < n; i++) {
+   sprintf(file_name, "%s/%s", bpath, dent[i]->d_name);
+   nmb = readlink(file_name, target, USBG_MAX_PATH_LENGTH);
+   if (nmb < 0)
+   ERRORNO("bytes %d contents %s\n", n, target);
+
+   /* readlink() don't add this, so we have to do it manually */
+   target[nmb] = '\0';
+   /* Target contains a full path
+*  but we need only function dir name */
+   target_name = strrchr(target, '/') + 1;
+
+   TAILQ_FOREACH(f, &g->functions, fnode)
+   {
+   /* Check if this is our target function */
+   if (strcmp(f->name, target_name) == 0) {
b = malloc(sizeof(usbg_binding));
strcpy(b->name, dent[i]->d_name);
strcpy(b->path, bpath);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 06/23] libusbg: Refresh function attributes while each get.

2014-03-05 Thread Krzysztof Opasiak
Function attributes may be changed by kernel or other
user so they should not be cached in library structures.

Signed-off-by: Krzysztof Opasiak 
---
 src/usbg.c |   31 +++
 1 file changed, 11 insertions(+), 20 deletions(-)

diff --git a/src/usbg.c b/src/usbg.c
index 63b8a32..d7284bb 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -74,7 +74,6 @@ struct usbg_function
char path[USBG_MAX_PATH_LENGTH];
 
usbg_function_type type;
-   usbg_function_attrs attr;
 };
 
 struct usbg_binding
@@ -267,7 +266,8 @@ static inline void usbg_write_string(char *path, char 
*name, char *file, char *b
usbg_write_buf(path, name, file, buf);
 }
 
-static void usbg_parse_function_attrs(usbg_function *f)
+static void usbg_parse_function_attrs(usbg_function *f,
+   usbg_function_attrs *f_attrs)
 {
struct ether_addr *addr;
char str_addr[40];
@@ -276,7 +276,7 @@ static void usbg_parse_function_attrs(usbg_function *f)
case F_SERIAL:
case F_ACM:
case F_OBEX:
-   f->attr.serial.port_num = usbg_read_dec(f->path, f->name, 
"port_num");
+   f_attrs->serial.port_num = usbg_read_dec(f->path, f->name, 
"port_num");
break;
case F_ECM:
case F_SUBSET:
@@ -286,18 +286,18 @@ static void usbg_parse_function_attrs(usbg_function *f)
usbg_read_string(f->path, f->name, "dev_addr", str_addr);
addr = ether_aton(str_addr);
if (addr)
-   f->attr.net.dev_addr = *addr;
+   f_attrs->net.dev_addr = *addr;
 
usbg_read_string(f->path, f->name, "host_addr", str_addr);
addr = ether_aton(str_addr);
if(addr)
-   f->attr.net.host_addr = *addr;
+   f_attrs->net.host_addr = *addr;
 
-   usbg_read_string(f->path, f->name, "ifname", 
f->attr.net.ifname);
-   f->attr.net.qmult = usbg_read_dec(f->path, f->name, "qmult");
+   usbg_read_string(f->path, f->name, "ifname", 
f_attrs->net.ifname);
+   f_attrs->net.qmult = usbg_read_dec(f->path, f->name, "qmult");
break;
case F_PHONET:
-   usbg_read_string(f->path, f->name, "ifname", 
f->attr.phonet.ifname);
+   usbg_read_string(f->path, f->name, "ifname", 
f_attrs->phonet.ifname);
break;
default:
ERROR("Unsupported function type\n");
@@ -322,7 +322,6 @@ static int usbg_parse_functions(char *path, usbg_gadget *g)
strcpy(f->name, dent[i]->d_name);
strcpy(f->path, fpath);
f->type = usbg_lookup_function_type(strtok(dent[i]->d_name, 
"."));
-   usbg_parse_function_attrs(f);
TAILQ_INSERT_TAIL(&g->functions, f, fnode);
free(dent[i]);
}
@@ -905,8 +904,6 @@ usbg_function *usbg_create_function(usbg_gadget *g, 
usbg_function_type type,
 
if (f_attrs)
usbg_set_function_attrs(f, f_attrs);
-   else
-   usbg_parse_function_attrs(f);
 
INSERT_TAILQ_STRING_ORDER(&g->functions, fhead, name, f, fnode);
 
@@ -1143,10 +1140,11 @@ usbg_function_type usbg_get_function_type(usbg_function 
*f)
return f->type;
 }
 
-usbg_function_attrs *usbg_get_function_attrs(usbg_function *f, 
usbg_function_attrs *f_attrs)
+usbg_function_attrs *usbg_get_function_attrs(usbg_function *f,
+   usbg_function_attrs *f_attrs)
 {
if (f && f_attrs)
-   *f_attrs = f->attr;
+   usbg_parse_function_attrs(f, f_attrs);
else
f_attrs = NULL;
 
@@ -1160,8 +1158,6 @@ void usbg_set_function_attrs(usbg_function *f, 
usbg_function_attrs *f_attrs)
if (!f || !f_attrs)
return;
 
-   f->attr = *f_attrs;
-
switch (f->type) {
case F_SERIAL:
case F_ACM:
@@ -1195,8 +1191,6 @@ void usbg_set_net_dev_addr(usbg_function *f, struct 
ether_addr *dev_addr)
 {
char *str_addr;
 
-   f->attr.net.dev_addr = *dev_addr;
-
str_addr = ether_ntoa(dev_addr);
usbg_write_string(f->path, f->name, "dev_addr", str_addr);
 }
@@ -1205,15 +1199,12 @@ void usbg_set_net_host_addr(usbg_function *f, struct 
ether_addr *host_addr)
 {
char *str_addr;
 
-   f->attr.net.host_addr = *host_addr;
-
str_addr = ether_ntoa(host_addr);
usbg_write_string(f->path, f->name, "host_addr", str_addr);
 }
 
 void usbg_set_net_qmult(usbg_function *f, int qmult)
 {
-   f->attr.net.qmult = qmult;
usbg_write_dec(f->path, f->name, "qmult", qmult);
 }
 
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 09/23] libusbg: Add error handling to usbg_init() and related functions.

2014-03-05 Thread Krzysztof Opasiak
Assumption that all malloc() and read()/write() finish correctly
is too bold. Errors should be handled and propagated to upper
layers of library and returned to user.

Signed-off-by: Krzysztof Opasiak 

Conflicts:

src/usbg.c
---
 examples/gadget-acm-ecm.c |5 +-
 examples/show-gadgets.c   |5 +-
 include/usbg/usbg.h   |   19 ++-
 src/usbg.c|  389 +++--
 4 files changed, 290 insertions(+), 128 deletions(-)

diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c
index 5b027b6..5ab42cf 100644
--- a/examples/gadget-acm-ecm.c
+++ b/examples/gadget-acm-ecm.c
@@ -34,6 +34,7 @@ int main(void)
usbg_config *c;
usbg_function *f_acm0, *f_acm1, *f_ecm;
int ret = -EINVAL;
+   int usbg_ret;
 
usbg_gadget_attrs g_attrs = {
0x0200, /* bcdUSB */
@@ -56,8 +57,8 @@ int main(void)
"CDC 2xACM+ECM"
};
 
-   s = usbg_init("/sys/kernel/config");
-   if (!s) {
+   usbg_ret = usbg_init("/sys/kernel/config", &s);
+   if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error on USB gadget init\n");
goto out1;
}
diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c
index 2665262..4d79a09 100644
--- a/examples/show-gadgets.c
+++ b/examples/show-gadgets.c
@@ -125,9 +125,10 @@ int main(void)
usbg_gadget *g;
usbg_function *f;
usbg_config *c;
+   int usbg_ret;
 
-   s = usbg_init("/sys/kernel/config");
-   if (!s) {
+   usbg_ret = usbg_init("/sys/kernel/config", &s);
+   if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error on USB gadget init\n");
return -EINVAL;
}
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 562fdc5..ffef084 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -175,14 +175,29 @@ typedef union {
usbg_f_phonet_attrs phonet;
 } usbg_function_attrs;
 
+/**
+ * @typedef usbg_error
+ * @brief Errors which could be returned by library functions
+ */
+typedef enum  {
+   USBG_SUCCESS = 0,
+   USBG_ERROR_NO_MEM = -1,
+   USBG_ERROR_NO_ACCESS = -2,
+   USBG_ERROR_INVALID_PARAM = -3,
+   USBG_ERROR_NOT_FOUND = -4,
+   USBG_ERROR_IO = -5,
+   USBG_ERROR_OTHER_ERROR = -99
+} usbg_error;
+
 /* Library init and cleanup */
 
 /**
  * @brief Initialize the libusbg library state
  * @param configfs_path Path to the mounted configfs filesystem
- * @return Pointer to a state structure
+ * @param Pointer to be filled with pointer to usbg_state
+ * @return 0 on success, usbg_error on error
  */
-extern usbg_state *usbg_init(char *configfs_path);
+extern int usbg_init(char *configfs_path, usbg_state **state);
 
 /**
  * @brief Clean up the libusbg library state
diff --git a/src/usbg.c b/src/usbg.c
index 255074f..5cc5975 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -133,6 +133,35 @@ const char *function_names[] =
} \
} while (0)
 
+static int usbg_translate_error(int error)
+{
+   int ret;
+
+   switch (error) {
+   case ENOMEM:
+   ret = USBG_ERROR_NO_MEM;
+   break;
+   case EACCES:
+   ret = USBG_ERROR_NO_ACCESS;
+   break;
+   case ENOENT:
+   case ENOTDIR:
+   ret = USBG_ERROR_NOT_FOUND;
+   break;
+   case EINVAL:
+   case USBG_ERROR_INVALID_PARAM:
+   ret = USBG_ERROR_INVALID_PARAM;
+   break;
+   case EIO:
+   ret = USBG_ERROR_IO;
+   break;
+   default:
+   ret = USBG_ERROR_OTHER_ERROR;
+   }
+
+   return ret;
+}
+
 static int usbg_lookup_function_type(char *name)
 {
int i = 0;
@@ -169,52 +198,59 @@ static int file_select(const struct dirent *dent)
return 1;
 }
 
-static char *usbg_read_buf(char *path, char *name, char *file, char *buf)
+static int usbg_read_buf(char *path, char *name, char *file, char *buf)
 {
char p[USBG_MAX_STR_LENGTH];
FILE *fp;
-   char *ret = NULL;
+   int ret = USBG_SUCCESS;
 
sprintf(p, "%s/%s/%s", path, name, file);
 
fp = fopen(p, "r");
-   if (!fp)
-   goto out;
+   if (fp) {
+   /* Successfully opened */
+   if (!fgets(buf, USBG_MAX_STR_LENGTH, fp)) {
+   ERROR("read error");
+   ret = USBG_ERROR_IO;
+   }
 
-   ret = fgets(buf, USBG_MAX_STR_LENGTH, fp);
-   if (ret == NULL) {
-   ERROR("read error");
fclose(fp);
-   return ret;
+   } else {
+   /* Set error correctly */
+   ret = usbg_translate_error(errno);
}
 
-   fclose(fp);
-
-out:
return ret;
 }
 
-static int usbg_read_int(char *path, char *name, char *file, int base)
+static int usbg_read_int(char *path, char *name, char *

[PATCH 10/23] libusbg: Return usbg_error instead of -1 in usbg_*_len().

2014-03-05 Thread Krzysztof Opasiak
Functions which provides user length of some internal
strings should return usbg_error instead of -1.

Signed-off-by: Krzysztof Opasiak 
---
 include/usbg/usbg.h |   12 ++--
 src/usbg.c  |   12 ++--
 2 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index ffef084..ad52a5f 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -208,7 +208,7 @@ extern void usbg_cleanup(usbg_state *s);
 /**
  * @brief Get ConfigFS path length
  * @param s Pointer to state
- * @return Length of path or -1 if error occurred.
+ * @return Length of path or usbg_error if error occurred.
  */
 extern size_t usbg_get_configfs_path_len(usbg_state *s);
 
@@ -293,7 +293,7 @@ extern usbg_gadget_attrs *usbg_get_gadget_attrs(usbg_gadget 
*g,
 /**
  * @brief Get gadget name length
  * @param g Gadget which name length should be returned
- * @return Length of name string or -1 if error occurred.
+ * @return Length of name string or usbg_error if error occurred.
  */
 extern size_t usbg_get_gadget_name_len(usbg_gadget *g);
 
@@ -427,7 +427,7 @@ extern usbg_function *usbg_create_function(usbg_gadget *g, 
usbg_function_type ty
 /**
  * @brief Get function name length
  * @param f Config which name length should be returned
- * @return Length of name string or -1 if error occurred.
+ * @return Length of name string or usbg_error if error occurred.
  */
 extern size_t usbg_get_function_name_len(usbg_function *f);
 
@@ -456,7 +456,7 @@ extern usbg_config *usbg_create_config(usbg_gadget *g, char 
*name,
 /**
  * @brief Get config name length
  * @param c Config which name length should be returned
- * @return Length of name string or -1 if error occurred.
+ * @return Length of name string or usbg_error if error occurred.
  */
 extern size_t usbg_get_config_name_len(usbg_config *c);
 
@@ -546,7 +546,7 @@ extern usbg_function *usbg_get_binding_target(usbg_binding 
*b);
 /**
  * @brief Get binding name length
  * @param b Binding which name length should be returned
- * @return Length of name string or -1 if error occurred.
+ * @return Length of name string or usbg_error if error occurred.
  */
 extern size_t usbg_get_binding_name_len(usbg_binding *b);
 
@@ -584,7 +584,7 @@ extern void usbg_disable_gadget(usbg_gadget *g);
 /**
  * @brief Get gadget name length
  * @param g Gadget which name length should be returned
- * @return Length of name string or -1 if error occurred.
+ * @return Length of name string or usbg_error if error occurred.
  * @note If gadget isn't enabled on any udc returned size is 0.
  */
 extern size_t usbg_get_gadget_udc_len(usbg_gadget *g);
diff --git a/src/usbg.c b/src/usbg.c
index 5cc5975..69cf367 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -737,7 +737,7 @@ void usbg_cleanup(usbg_state *s)
 
 size_t usbg_get_configfs_path_len(usbg_state *s)
 {
-   return s ? strlen(s->path) : -1;
+   return s ? strlen(s->path) : USBG_ERROR_INVALID_PARAM;
 }
 
 char *usbg_get_configfs_path(usbg_state *s, char *buf, size_t len)
@@ -905,7 +905,7 @@ usbg_gadget_attrs *usbg_get_gadget_attrs(usbg_gadget *g,
 
 size_t usbg_get_gadget_name_len(usbg_gadget *g)
 {
-   return g ? strlen(g->name) : -1;
+   return g ? strlen(g->name) : USBG_ERROR_INVALID_PARAM;
 }
 
 char *usbg_get_gadget_name(usbg_gadget *g, char *buf, size_t len)
@@ -915,7 +915,7 @@ char *usbg_get_gadget_name(usbg_gadget *g, char *buf, 
size_t len)
 
 size_t usbg_get_gadget_udc_len(usbg_gadget *g)
 {
-   return g ? strlen(g->udc) : -1;
+   return g ? strlen(g->udc) : USBG_ERROR_INVALID_PARAM;
 }
 
 char *usbg_get_gadget_udc(usbg_gadget *g, char *buf, size_t len)
@@ -1135,7 +1135,7 @@ usbg_config *usbg_create_config(usbg_gadget *g, char 
*name,
 
 size_t usbg_get_config_name_len(usbg_config *c)
 {
-   return c ? strlen(c->name) : -1;
+   return c ? strlen(c->name) : USBG_ERROR_INVALID_PARAM;
 }
 
 char *usbg_get_config_name(usbg_config *c, char *buf, size_t len)
@@ -1145,7 +1145,7 @@ char *usbg_get_config_name(usbg_config *c, char *buf, 
size_t len)
 
 size_t usbg_get_function_name_len(usbg_function *f)
 {
-   return f ? strlen(f->name) : -1;
+   return f ? strlen(f->name) : USBG_ERROR_INVALID_PARAM;
 }
 
 char *usbg_get_function_name(usbg_function *f, char *buf, size_t len)
@@ -1265,7 +1265,7 @@ usbg_function *usbg_get_binding_target(usbg_binding *b)
 
 size_t usbg_get_binding_name_len(usbg_binding *b)
 {
-   return b ? strlen(b->name) : -1;
+   return b ? strlen(b->name) : USBG_ERROR_INVALID_PARAM;
 }
 
 char *usbg_get_binding_name(usbg_binding *b, char *buf, size_t len)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 12/23] libusbg: Add parenthesis to INSERT_TAILQ_STRING_ORDER macro.

2014-03-05 Thread Krzysztof Opasiak
Surround each pointer in macro with parenthesis to avid
errors related to operator precedence.

Signed-off-by: Krzysztof Opasiak 
---
 src/usbg.c |   16 
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/src/usbg.c b/src/usbg.c
index 56588c0..d5c36c9 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -118,17 +118,17 @@ const char *function_names[] =
 /* Insert in string order */
 #define INSERT_TAILQ_STRING_ORDER(HeadPtr, HeadType, NameField, ToInsert, 
NodeField) \
do { \
-   if (TAILQ_EMPTY(HeadPtr) || \
-   (strcmp(ToInsert->NameField, 
TAILQ_FIRST(HeadPtr)->NameField) < 0)) \
-   TAILQ_INSERT_HEAD(HeadPtr, ToInsert, NodeField); \
-   else if (strcmp(ToInsert->NameField, TAILQ_LAST(HeadPtr, 
HeadType)->NameField) > 0) \
-   TAILQ_INSERT_TAIL(HeadPtr, ToInsert, NodeField); \
+   if (TAILQ_EMPTY((HeadPtr)) || \
+   (strcmp((ToInsert)->NameField, 
TAILQ_FIRST((HeadPtr))->NameField) < 0)) \
+   TAILQ_INSERT_HEAD((HeadPtr), (ToInsert), NodeField); \
+   else if (strcmp((ToInsert)->NameField, TAILQ_LAST((HeadPtr), 
HeadType)->NameField) > 0) \
+   TAILQ_INSERT_TAIL((HeadPtr), (ToInsert), NodeField); \
else { \
typeof(ToInsert) _cur; \
-   TAILQ_FOREACH(_cur, HeadPtr, NodeField) { \
-   if (strcmp(ToInsert->NameField, 
_cur->NameField) > 0) \
+   TAILQ_FOREACH(_cur, (HeadPtr), NodeField) { \
+   if (strcmp((ToInsert)->NameField, 
_cur->NameField) > 0) \
continue; \
-   TAILQ_INSERT_BEFORE(_cur, ToInsert, NodeField); 
\
+   TAILQ_INSERT_BEFORE(_cur, (ToInsert), 
NodeField); \
} \
} \
} while (0)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 11/23] libusbg: Return usbg_error instead of char* in usbg_get_*_name().

2014-03-05 Thread Krzysztof Opasiak
API should be consistent and use error codes to determine what
type of error occurred instead of returning NULL only.

Signed-off-by: Krzysztof Opasiak 
---
 include/usbg/usbg.h |   24 ++---
 src/usbg.c  |   60 ---
 2 files changed, 60 insertions(+), 24 deletions(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index ad52a5f..0d76010 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -217,9 +217,9 @@ extern size_t usbg_get_configfs_path_len(usbg_state *s);
  * @param s Pointer to state
  * @param buf Buffer where path should be copied
  * @param len Length of given buffer
- * @return Pointer to destination or NULL if error occurred.
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern char *usbg_get_configfs_path(usbg_state *s, char *buf, size_t len);
+extern int usbg_get_configfs_path(usbg_state *s, char *buf, size_t len);
 
 /* USB gadget queries */
 
@@ -302,9 +302,9 @@ extern size_t usbg_get_gadget_name_len(usbg_gadget *g);
  * @param b Pointer to gadget
  * @param buf Buffer where name should be copied
  * @param len Length of given buffer
- * @return Pointer to destination or NULL if error occurred.
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern char *usbg_get_gadget_name(usbg_gadget *g, char *buf, size_t len);
+extern int usbg_get_gadget_name(usbg_gadget *g, char *buf, size_t len);
 
 /**
  * @brief Set the USB gadget vendor id
@@ -436,9 +436,9 @@ extern size_t usbg_get_function_name_len(usbg_function *f);
  * @param f Pointer to function
  * @param buf Buffer where name should be copied
  * @param len Length of given buffer
- * @return Pointer to destination or NULL if error occurred.
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern char *usbg_get_function_name(usbg_function *f, char *buf, size_t len);
+extern int usbg_get_function_name(usbg_function *f, char *buf, size_t len);
 
 /* USB configurations allocation and configuration */
 
@@ -465,9 +465,9 @@ extern size_t usbg_get_config_name_len(usbg_config *c);
  * @param c Pointer to config
  * @param buf Buffer where name should be copied
  * @param len Length of given buffer
- * @return Pointer to destination or NULL if error occurred.
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern char *usbg_get_config_name(usbg_config *c, char *buf, size_t len);
+extern int usbg_get_config_name(usbg_config *c, char *buf, size_t len);
 
 /**
  * @brief Set the USB configuration attributes
@@ -555,9 +555,9 @@ extern size_t usbg_get_binding_name_len(usbg_binding *b);
  * @param b Pointer to binding
  * @param buf Buffer where name should be copied
  * @param len Length of given buffer
- * @return Pointer to destination or NULL if error occurred.
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern char *usbg_get_binding_name(usbg_binding *b, char *buf, size_t len);
+extern int usbg_get_binding_name(usbg_binding *b, char *buf, size_t len);
 
 /* USB gadget setup and teardown */
 
@@ -594,10 +594,10 @@ extern size_t usbg_get_gadget_udc_len(usbg_gadget *g);
  * @param b Pointer to gadget
  * @param buf Buffer where udc name should be copied
  * @param len Length of given buffer
- * @return Pointer to destination or NULL if error occurred.
+ * @return 0 on success or usbg_error if error occurred.
  * @note If gadget isn't enabled on any udc returned string is empty.
  */
-extern char *usbg_get_gadget_udc(usbg_gadget *g, char *buf, size_t len);
+extern int usbg_get_gadget_udc(usbg_gadget *g, char *buf, size_t len);
 
 /*
  * USB function-specific attribute configuration
diff --git a/src/usbg.c b/src/usbg.c
index 69cf367..56588c0 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -740,9 +740,15 @@ size_t usbg_get_configfs_path_len(usbg_state *s)
return s ? strlen(s->path) : USBG_ERROR_INVALID_PARAM;
 }
 
-char *usbg_get_configfs_path(usbg_state *s, char *buf, size_t len)
+int usbg_get_configfs_path(usbg_state *s, char *buf, size_t len)
 {
-   return s ? strncpy(buf, s->path, len) : NULL;
+   int ret = USBG_SUCCESS;
+   if (s && buf)
+   strncpy(buf, s->path, len);
+   else
+   ret = USBG_ERROR_INVALID_PARAM;
+
+   return ret;
 }
 
 usbg_gadget *usbg_get_gadget(usbg_state *s, const char *name)
@@ -908,9 +914,15 @@ size_t usbg_get_gadget_name_len(usbg_gadget *g)
return g ? strlen(g->name) : USBG_ERROR_INVALID_PARAM;
 }
 
-char *usbg_get_gadget_name(usbg_gadget *g, char *buf, size_t len)
+int usbg_get_gadget_name(usbg_gadget *g, char *buf, size_t len)
 {
-   return g ? strncpy(buf, g->name, len) : NULL;
+   int ret = USBG_SUCCESS;
+   if (g && buf)
+   strncpy(buf, g->name, len);
+   else
+   ret = USBG_ERROR_INVALID_PARAM;
+
+   return ret;
 }
 
 size_t usbg_get_gadget_udc_len(usbg_gadget *g)
@@ -918,9 +930,15 @@ size_t usbg_get_gadget_udc_len(usbg_gadget *g)
return g ? str

[PATCH 13/23] libusbg: Add return value to gadget creation functions.

2014-03-05 Thread Krzysztof Opasiak
Functions related to gadget creation should return error codes
instead of pointer.

Signed-off-by: Krzysztof Opasiak 
---
 examples/gadget-acm-ecm.c |4 +-
 include/usbg/usbg.h   |   21 ++--
 src/usbg.c|  258 +
 3 files changed, 185 insertions(+), 98 deletions(-)

diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c
index 5ab42cf..b1131b4 100644
--- a/examples/gadget-acm-ecm.c
+++ b/examples/gadget-acm-ecm.c
@@ -63,8 +63,8 @@ int main(void)
goto out1;
}
 
-   g = usbg_create_gadget(s, "g1", &g_attrs, &g_strs);
-   if (!g) {
+   usbg_ret = usbg_create_gadget(s, "g1", &g_attrs, &g_strs, &g);
+   if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error on create gadget\n");
goto out2;
}
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 0d76010..f6f7a2e 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -186,6 +186,7 @@ typedef enum  {
USBG_ERROR_INVALID_PARAM = -3,
USBG_ERROR_NOT_FOUND = -4,
USBG_ERROR_IO = -5,
+   USBG_ERROR_EXIST = -6,
USBG_ERROR_OTHER_ERROR = -99
 } usbg_error;
 
@@ -255,10 +256,11 @@ extern usbg_config *usbg_get_config(usbg_gadget *g, const 
char *name);
  * @param name Name of the gadget
  * @param idVendor Gadget vendor ID
  * @param idProduct Gadget product ID
- * @return Pointer to gadget or NULL if the gadget cannot be created
+ * @param g Pointer to be filled with pointer to gadget
+ * @return 0 on success usbg_error if error occurred
  */
-extern usbg_gadget *usbg_create_gadget_vid_pid(usbg_state *s, char *name,
-   uint16_t idVendor, uint16_t idProduct);
+extern int usbg_create_gadget_vid_pid(usbg_state *s, char *name,
+   uint16_t idVendor, uint16_t idProduct, usbg_gadget **g);
 
 /**
  * @brief Create a new USB gadget device and set given attributes
@@ -267,18 +269,20 @@ extern usbg_gadget *usbg_create_gadget_vid_pid(usbg_state 
*s, char *name,
  * @param name Name of the gadget
  * @param g_attrs Gadget attributes to be set. If NULL setting is omitted.
  * @param g_strs Gadget strings to be set. If NULL setting is omitted.
+ * @param g Pointer to be filled with pointer to gadget
  * @note Given strings are assumed to be in US English
- * @return Pointer to gadget or NULL if the gadget cannot be created
+ * @return 0 on success usbg_error if error occurred
  */
-extern usbg_gadget *usbg_create_gadget(usbg_state *s, char *name,
-   usbg_gadget_attrs *g_attrs, usbg_gadget_strs *g_strs);
+extern int usbg_create_gadget(usbg_state *s, char *name,
+   usbg_gadget_attrs *g_attrs, usbg_gadget_strs *g_strs, 
usbg_gadget **g);
 
 /**
  * @brief Set the USB gadget attributes
  * @param g Pointer to gadget
  * @param g_attrs Gadget attributes
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_attrs(usbg_gadget *g,
+extern int usbg_set_gadget_attrs(usbg_gadget *g,
usbg_gadget_attrs *g_attrs);
 
 /**
@@ -383,8 +387,9 @@ extern usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget 
*g, int lang,
  * @param g Pointer to gadget
  * @param lang USB language ID
  * @param g_sttrs Gadget attributes
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_strs(usbg_gadget *g, int lang,
+extern int usbg_set_gadget_strs(usbg_gadget *g, int lang,
usbg_gadget_strs *g_strs);
 
 /**
diff --git a/src/usbg.c b/src/usbg.c
index d5c36c9..0a469cd 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -142,6 +142,7 @@ static int usbg_translate_error(int error)
ret = USBG_ERROR_NO_MEM;
break;
case EACCES:
+   case EROFS:
ret = USBG_ERROR_NO_ACCESS;
break;
case ENOENT:
@@ -155,6 +156,9 @@ static int usbg_translate_error(int error)
case EIO:
ret = USBG_ERROR_IO;
break;
+   case EEXIST:
+   ret = USBG_ERROR_EXIST;
+   break;
default:
ret = USBG_ERROR_OTHER_ERROR;
}
@@ -261,46 +265,49 @@ static int usbg_read_string(char *path, char *name, char 
*file, char *buf)
return ret;
 }
 
-static void usbg_write_buf(char *path, char *name, char *file, char *buf)
+static int usbg_write_buf(char *path, char *name, char *file, char *buf)
 {
char p[USBG_MAX_STR_LENGTH];
FILE *fp;
-   int err;
+   int ret = USBG_SUCCESS;
 
sprintf(p, "%s/%s/%s", path, name, file);
 
fp = fopen(p, "w");
-   if (!fp) {
-   ERRORNO("%s\n", p);
-   return;
-   }
+   if (fp) {
+   fputs(buf, fp);
+   fflush(fp);
 
-   fputs(buf, fp);
-   fflush(fp);
-   err = ferror(fp);
-   fclose(fp);
-   
-   if (err){
-   ERROR("write error");
-   return;
+   ret = ferror(fp)

[PATCH 14/23] libusbg: Add return value to usbg_set_gadget_*() functions.

2014-03-05 Thread Krzysztof Opasiak
Setting each of attribute may fail due to a lot of reasons
so those functions should report this failure to a user.

Signed-off-by: Krzysztof Opasiak 
---
 include/usbg/usbg.h |   33 +---
 src/usbg.c  |   85 +--
 2 files changed, 77 insertions(+), 41 deletions(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index f6f7a2e..17084bb 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -314,62 +314,70 @@ extern int usbg_get_gadget_name(usbg_gadget *g, char 
*buf, size_t len);
  * @brief Set the USB gadget vendor id
  * @param g Pointer to gadget
  * @param idVendor USB device vendor id
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor);
+extern int usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor);
 
 /**
  * @brief Set the USB gadget product id
  * @param g Pointer to gadget
  * @param idProduct USB device product id
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct);
+extern int usbg_set_gadget_product_id(usbg_gadget *g, uint16_t idProduct);
 
 /**
  * @brief Set the USB gadget device class code
  * @param g Pointer to gadget
  * @param bDeviceClass USB device class code
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_device_class(usbg_gadget *g,
+extern int usbg_set_gadget_device_class(usbg_gadget *g,
uint8_t bDeviceClass);
 
 /**
  * @brief Set the USB gadget protocol code
  * @param g Pointer to gadget
  * @param bDeviceProtocol USB protocol code
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_device_protocol(usbg_gadget *g,
+extern int usbg_set_gadget_device_protocol(usbg_gadget *g,
uint8_t bDeviceProtocol);
 
 /**
  * @brief Set the USB gadget device subclass code
  * @param g Pointer to gadget
  * @param bDeviceSubClass USB device subclass code
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_device_subclass(usbg_gadget *g,
+extern int usbg_set_gadget_device_subclass(usbg_gadget *g,
uint8_t bDeviceSubClass);
 
 /**
  * @brief Set the maximum packet size for a gadget
  * @param g Pointer to gadget
  * @param bMaxPacketSize0 Maximum packet size
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_device_max_packet(usbg_gadget *g,
+extern int usbg_set_gadget_device_max_packet(usbg_gadget *g,
uint8_t bMaxPacketSize0);
 
 /**
  * @brief Set the gadget device BCD release number
  * @param g Pointer to gadget
  * @param bcdDevice BCD release number
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_device_bcd_device(usbg_gadget *g,
+extern int usbg_set_gadget_device_bcd_device(usbg_gadget *g,
uint16_t bcdDevice);
 
 /**
  * @brief Set the gadget device BCD USB version
  * @param g Pointer to gadget
  * @param bcdUSB BCD USB version
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB);
+extern int usbg_set_gadget_device_bcd_usb(usbg_gadget *g, uint16_t bcdUSB);
 
 /**
  * @brief Get the USB gadget strings
@@ -397,24 +405,27 @@ extern int usbg_set_gadget_strs(usbg_gadget *g, int lang,
  * @param g Pointer to gadget
  * @param lang USB language ID
  * @param ser Serial number
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_serial_number(usbg_gadget *g, int lang, char *ser);
+extern int usbg_set_gadget_serial_number(usbg_gadget *g, int lang, char *ser);
 
 /**
  * @brief Set the manufacturer name for a gadget
  * @param g Pointer to gadget
  * @param lang USB language ID
  * @param mnf Manufacturer
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_manufacturer(usbg_gadget *g, int lang, char *mnf);
+extern int usbg_set_gadget_manufacturer(usbg_gadget *g, int lang, char *mnf);
 
 /**
  * @brief Set the product name for a gadget
  * @param g Pointer to gadget
  * @param lang USB language ID
  * @param prd Product
+ * @return 0 on success usbg_error if error occurred
  */
-extern void usbg_set_gadget_product(usbg_gadget *g, int lang, char *prd);
+extern int usbg_set_gadget_product(usbg_gadget *g, int lang, char *prd);
 
 /* USB function allocation and configuration */
 
diff --git a/src/usbg.c b/src/usbg.c
index 0a469cd..b777653 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1011,44 +1011,52 @@ out:
return ret;
 }
 
-void usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor)
+int usbg_set_gadget_vendor_id(usbg_gadget *g, uint16_t idVendor)
 {
-   usbg_write_hex16(g->path, g->name, "idVendor", idVendor);
+   return g ? usbg_write_hex16(g->path, g->name, "idVendor", idVendor)
+   : USBG_ERRO

[PATCH 17/23] libusbg: Add return value to usbg_enable/disable_gadget().

2014-03-05 Thread Krzysztof Opasiak
Enabling and disabling gadget may fail due to many reasons
so those functions should notify user about it.

Signed-off-by: Krzysztof Opasiak 
---
 include/usbg/usbg.h |   10 +---
 src/usbg.c  |   67 ++-
 2 files changed, 57 insertions(+), 20 deletions(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 1fa9d22..3ad98b6 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -187,6 +187,8 @@ typedef enum  {
USBG_ERROR_NOT_FOUND = -4,
USBG_ERROR_IO = -5,
USBG_ERROR_EXIST = -6,
+   USBG_ERROR_NO_DEV = -7,
+   USBG_ERROR_BUSY = -8,
USBG_ERROR_OTHER_ERROR = -99
 } usbg_error;
 
@@ -589,7 +591,7 @@ extern int usbg_get_binding_name(usbg_binding *b, char 
*buf, size_t len);
 /**
  * @brief Get a list of UDC devices on the system
  * @param udc_list Pointer to pointer to dirent pointer
- * @return Number of UDC devices on success, -1 on failure
+ * @return Number of UDC devices on success, usbg_error on failure
  */
 extern int usbg_get_udcs(struct dirent ***udc_list);
 
@@ -597,14 +599,16 @@ extern int usbg_get_udcs(struct dirent ***udc_list);
  * @brief Enable a USB gadget device
  * @param g Pointer to gadget
  * @param udc Name of UDC to enable gadget
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern void usbg_enable_gadget(usbg_gadget *g, char *udc);
+extern int usbg_enable_gadget(usbg_gadget *g, char *udc);
 
 /**
  * @brief Disable a USB gadget device
  * @param g Pointer to gadget
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern void usbg_disable_gadget(usbg_gadget *g);
+extern int usbg_disable_gadget(usbg_gadget *g);
 
 /**
  * @brief Get gadget name length
diff --git a/src/usbg.c b/src/usbg.c
index 3c6c008..55c9c8e 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -159,6 +159,12 @@ static int usbg_translate_error(int error)
case EEXIST:
ret = USBG_ERROR_EXIST;
break;
+   case ENODEV:
+   ret = USBG_ERROR_NO_DEV;
+   break;
+   case EBUSY:
+   ret = USBG_ERROR_BUSY;
+   break;
default:
ret = USBG_ERROR_OTHER_ERROR;
}
@@ -1442,34 +1448,61 @@ int usbg_get_binding_name(usbg_binding *b, char *buf, 
size_t len)
 
 int usbg_get_udcs(struct dirent ***udc_list)
 {
-   return scandir("/sys/class/udc", udc_list, file_select, alphasort);
+   int ret = USBG_ERROR_INVALID_PARAM;
+
+   if (udc_list) {
+   ret = scandir("/sys/class/udc", udc_list, file_select, 
alphasort);
+   if (ret < 0)
+   ret = usbg_translate_error(errno);
+   }
+
+   return ret;
 }
 
-void usbg_enable_gadget(usbg_gadget *g, char *udc)
+int usbg_enable_gadget(usbg_gadget *g, char *udc)
 {
char gudc[USBG_MAX_STR_LENGTH];
struct dirent **udc_list;
-   int n;
+   int i;
+   int ret = USBG_ERROR_INVALID_PARAM;
+
+   if (!g)
+   return ret;
 
if (!udc) {
-   n = usbg_get_udcs(&udc_list);
-   if (!n)
-   return;
-   strcpy(gudc, udc_list[0]->d_name);
-   while (n--)
-   free(udc_list[n]);
-   free(udc_list);
-   } else
-   strcpy (gudc, udc);
+   ret = usbg_get_udcs(&udc_list);
+   if (ret >= 0) {
+   /* Look for default one - first in string order */
+   strcpy(gudc, udc_list[0]->d_name);
+   udc = gudc;
+
+   /** Free the memory */
+   for (i = 0; i < ret; ++i)
+   free(udc_list[i]);
+   free(udc_list);
+   } else {
+   return ret;
+   }
+   }
+
+   ret = usbg_write_string(g->path, g->name, "UDC", udc);
 
-   strcpy(g->udc, gudc);
-   usbg_write_string(g->path, g->name, "UDC", gudc);
+   if (ret == USBG_SUCCESS)
+   strcpy(g->udc, udc);
+
+   return ret;
 }
 
-void usbg_disable_gadget(usbg_gadget *g)
+int usbg_disable_gadget(usbg_gadget *g)
 {
-   strcpy(g->udc, "");
-   usbg_write_string(g->path, g->name, "UDC", "");
+   int ret = USBG_ERROR_INVALID_PARAM;
+
+   if (g) {
+   strcpy(g->udc, "");
+   ret = usbg_write_string(g->path, g->name, "UDC", "");
+   }
+
+   return ret;
 }
 
 /*
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 18/23] libusbg: Return error code instead of NULL pointer.

2014-03-05 Thread Krzysztof Opasiak
Change usbg_get_gadget_strs() and usbg_get_gadget_attrs()
to return usbg_error instead of NULL pointer.

Signed-off-by: Krzysztof Opasiak 

Conflicts:

src/usbg.c
---
 include/usbg/usbg.h |   10 --
 src/usbg.c  |   43 ++-
 2 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 3ad98b6..6855833 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -291,10 +291,9 @@ extern int usbg_set_gadget_attrs(usbg_gadget *g,
  * @brief Get the USB gadget strings
  * @param g Pointer to gadget
  * @param g_attrs Structure to be filled
- * @retur Pointer to filled structure or NULL if error occurred.
+ * @return 0 on success usbg_error if error occurred
  */
-extern usbg_gadget_attrs *usbg_get_gadget_attrs(usbg_gadget *g,
-   usbg_gadget_attrs *g_attrs);
+extern int usbg_get_gadget_attrs(usbg_gadget *g, usbg_gadget_attrs *g_attrs);
 
 /**
  * @brief Get gadget name length
@@ -386,10 +385,9 @@ extern int usbg_set_gadget_device_bcd_usb(usbg_gadget *g, 
uint16_t bcdUSB);
  * @param g Pointer to gadget
  * @param lang Language of strings
  * @param g_sttrs Structure to be filled
- * @retur Pointer to filled structure or NULL if error occurred or
- * if no strings for given language.
+ * @return 0 on success usbg_error if error occurred
  */
-extern usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget *g, int lang,
+extern int usbg_get_gadget_strs(usbg_gadget *g, int lang,
usbg_gadget_strs *g_strs);
 
 /**
diff --git a/src/usbg.c b/src/usbg.c
index 55c9c8e..9747069 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -616,9 +616,10 @@ out:
return ret;
 }
 
-static usbg_gadget_strs *usbg_parse_strings(char *path, char *name, int lang,
+static int usbg_parse_gadget_strs(char *path, char *name, int lang,
usbg_gadget_strs *g_strs)
 {
+   int ret;
DIR *dir;
char spath[USBG_MAX_PATH_LENGTH];
 
@@ -628,14 +629,23 @@ static usbg_gadget_strs *usbg_parse_strings(char *path, 
char *name, int lang,
dir = opendir(spath);
if (dir) {
closedir(dir);
-   usbg_read_string(spath, "", "serialnumber", g_strs->str_ser);
-   usbg_read_string(spath, "", "manufacturer", g_strs->str_mnf);
-   usbg_read_string(spath, "", "product", g_strs->str_prd);
+   ret = usbg_read_string(spath, "", "serialnumber", 
g_strs->str_ser);
+   if (ret != USBG_SUCCESS)
+   goto out;
+
+   ret = usbg_read_string(spath, "", "manufacturer", 
g_strs->str_mnf);
+   if (ret != USBG_SUCCESS)
+   goto out;
+
+   ret = usbg_read_string(spath, "", "product", g_strs->str_prd);
+   if (ret != USBG_SUCCESS)
+   goto out;
} else {
-   g_strs = NULL;
+   ret = usbg_translate_error(errno);
}
 
-   return g_strs;
+out:
+   return ret;
 }
 
 static inline int usbg_parse_gadget(char *path, char *name, usbg_state *parent,
@@ -927,15 +937,10 @@ int usbg_create_gadget(usbg_state *s, char *name,
return ret;
 }
 
-usbg_gadget_attrs *usbg_get_gadget_attrs(usbg_gadget *g,
-   usbg_gadget_attrs *g_attrs)
+int usbg_get_gadget_attrs(usbg_gadget *g, usbg_gadget_attrs *g_attrs)
 {
-   if (g && g_attrs)
-   usbg_parse_gadget_attrs(g->path, g->name, g_attrs);
-   else
-   g_attrs = NULL;
-
-   return g_attrs;
+   return g && g_attrs ? usbg_parse_gadget_attrs(g->path, g->name, g_attrs)
+   : USBG_ERROR_INVALID_PARAM;
 }
 
 size_t usbg_get_gadget_name_len(usbg_gadget *g)
@@ -1065,15 +1070,11 @@ int usbg_set_gadget_device_bcd_usb(usbg_gadget *g, 
uint16_t bcdUSB)
: USBG_ERROR_INVALID_PARAM;
 }
 
-usbg_gadget_strs *usbg_get_gadget_strs(usbg_gadget *g, int lang,
+int usbg_get_gadget_strs(usbg_gadget *g, int lang,
usbg_gadget_strs *g_strs)
 {
-   if (g && g_strs)
-   g_strs = usbg_parse_strings(g->path, g->name, lang, g_strs);
-   else
-   g_strs = NULL;
-
-   return g_strs;
+   return g && g_strs ? usbg_parse_gadget_strs(g->path, g->name, lang,
+   g_strs) : USBG_ERROR_INVALID_PARAM;
 }
 
 static int usbg_check_dir(char *path)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 22/23] libusbg: Add functions for getting error strings.

2014-03-05 Thread Krzysztof Opasiak
Add usbg_error_name() to get error name as a string.

Add usbg_strerror() to get brief error description in English.

Signed-off-by: Krzysztof Opasiak 
---
 include/usbg/usbg.h |   16 ++
 src/usbg.c  |   86 +++
 2 files changed, 102 insertions(+)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 249b40f..354ba38 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -175,6 +175,8 @@ typedef union {
usbg_f_phonet_attrs phonet;
 } usbg_function_attrs;
 
+/* Error codes */
+
 /**
  * @typedef usbg_error
  * @brief Errors which could be returned by library functions
@@ -193,6 +195,20 @@ typedef enum  {
USBG_ERROR_OTHER_ERROR = -99
 } usbg_error;
 
+/*
+ * @brief Get the error name as a constant string
+ * @param e error code
+ * @return Constant string with error name
+ */
+extern const char *usbg_error_name(usbg_error e);
+
+/*
+ * @brief Get the short description of error
+ * @param e error code
+ * @return Constant string with error description
+ */
+extern const char *usbg_strerror(usbg_error e);
+
 /* Library init and cleanup */
 
 /**
diff --git a/src/usbg.c b/src/usbg.c
index 860960a..4e6da9e 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -172,6 +172,92 @@ static int usbg_translate_error(int error)
return ret;
 }
 
+const char *usbg_error_name(usbg_error e)
+{
+   char *ret = "UNKNOWN";
+
+   switch (e) {
+   case USBG_SUCCESS:
+   ret = "USBG_SUCCESS";
+   break;
+   case USBG_ERROR_NO_MEM:
+   ret = "USBG_ERROR_NO_MEM";
+   break;
+   case USBG_ERROR_NO_ACCESS:
+   ret = "USBG_ERROR_NO_ACCESS";
+   break;
+   case USBG_ERROR_INVALID_PARAM:
+   ret = "USBG_ERROR_INVALID_PARAM";
+   break;
+   case USBG_ERROR_NOT_FOUND:
+   ret = "USBG_ERROR_NOT_FOUND";
+   break;
+   case USBG_ERROR_IO:
+   ret = "USBG_ERROR_IO";
+   break;
+   case USBG_ERROR_EXIST:
+   ret = "USBG_ERROR_EXIST";
+   break;
+   case USBG_ERROR_NO_DEV:
+   ret = "USBG_ERROR_NO_DEV";
+   break;
+   case USBG_ERROR_BUSY:
+   ret = "USBG_ERROR_BUSY";
+   break;
+   case USBG_ERROR_NOT_SUPPORTED:
+   ret = "USBG_ERROR_NOT_SUPPORTED";
+   break;
+   case USBG_ERROR_OTHER_ERROR:
+   ret = "USBG_ERROR_OTHER_ERROR";
+   break;
+   }
+
+   return ret;
+}
+
+const char *usbg_strerror(usbg_error e)
+{
+   char *ret = "Unknown error";
+
+   switch (e) {
+   case USBG_SUCCESS:
+   ret = "Success";
+   break;
+   case USBG_ERROR_NO_MEM:
+   ret = "Insufficient memory";
+   break;
+   case USBG_ERROR_NO_ACCESS:
+   ret = "Access denied (insufficient permissions)";
+   break;
+   case USBG_ERROR_INVALID_PARAM:
+   ret = "Invalid parameter";
+   break;
+   case USBG_ERROR_NOT_FOUND:
+   ret = "Not found (file or directory removed)";
+   break;
+   case USBG_ERROR_IO:
+   ret = "Input/output error";
+   break;
+   case USBG_ERROR_EXIST:
+   ret = "Already exist";
+   break;
+   case USBG_ERROR_NO_DEV:
+   ret = "No such device (illegal device name)";
+   break;
+   case USBG_ERROR_BUSY:
+   ret = "Busy (gadget enabled)";
+   break;
+   case USBG_ERROR_NOT_SUPPORTED:
+   ret = "Function not supported";
+   break;
+   case USBG_ERROR_OTHER_ERROR:
+   ret = "Other error";
+   break;
+   }
+
+   return ret;
+}
+
 static int usbg_lookup_function_type(char *name)
 {
int i = 0;
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 23/23] libusbg: Update examples to use returned error codes.

2014-03-05 Thread Krzysztof Opasiak
Examples provided with the library should use returned
error codes and provide information to user.

Remove todo baceuse it has been already done.

Signed-off-by: Krzysztof Opasiak 
---
 examples/gadget-acm-ecm.c |   51 +++--
 examples/show-gadgets.c   |   40 +++
 src/usbg.c|1 -
 3 files changed, 81 insertions(+), 11 deletions(-)

diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c
index cda3808..8eb4aeb 100644
--- a/examples/gadget-acm-ecm.c
+++ b/examples/gadget-acm-ecm.c
@@ -60,44 +60,83 @@ int main(void)
usbg_ret = usbg_init("/sys/kernel/config", &s);
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error on USB gadget init\n");
+   fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
goto out1;
}
 
usbg_ret = usbg_create_gadget(s, "g1", &g_attrs, &g_strs, &g);
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error on create gadget\n");
+   fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
goto out2;
}
 
usbg_ret = usbg_create_function(g, F_ACM, "usb0", NULL, &f_acm0);
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error creating acm0 function\n");
+   fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
goto out2;
}
 
usbg_ret = usbg_create_function(g, F_ACM, "usb1", NULL, &f_acm1);
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error creating acm1 function\n");
+   fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
goto out2;
}
 
-   usbg_ret = usbg_create_function(g, F_ECM, "usb0", NULL, &f_acm1);
+   usbg_ret = usbg_create_function(g, F_ECM, "usb0", NULL, &f_ecm);
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error creating ecm function\n");
+   fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
goto out2;
}
 
-   usbg_ret = usbg_create_config(g, "c.1", NULL /* use defaults */, 
&c_strs, &c);
+   usbg_ret = usbg_create_config(g, "c.1", NULL /* use defaults */, 
&c_strs,
+   &c);
if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error creating config\n");
+   fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
goto out2;
}
 
-   usbg_add_config_function(c, "acm.GS0", f_acm0);
-   usbg_add_config_function(c, "acm.GS1", f_acm1);
-   usbg_add_config_function(c, "ecm.usb0", f_ecm);
+   usbg_ret = usbg_add_config_function(c, "acm.GS0", f_acm0);
+   if (usbg_ret != USBG_SUCCESS) {
+   fprintf(stderr, "Error adding acm.GS0\n");
+   fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
+   goto out2;
+   }
+
+   usbg_ret = usbg_add_config_function(c, "acm.GS1", f_acm1);
+   if (usbg_ret != USBG_SUCCESS) {
+   fprintf(stderr, "Error adding acm.GS1\n");
+   fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
+   goto out2;
+   }
 
-   usbg_enable_gadget(g, DEFAULT_UDC);
+   usbg_ret = usbg_add_config_function(c, "ecm.usb0", f_ecm);
+   if (usbg_ret != USBG_SUCCESS) {
+   fprintf(stderr, "Error adding ecm.usb0\n");
+   fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
+   goto out2;
+   }
+
+   usbg_ret = usbg_enable_gadget(g, DEFAULT_UDC);
+   if (usbg_ret != USBG_SUCCESS) {
+   fprintf(stderr, "Error enabling gadget\n");
+   fprintf(stderr, "Error: %s : %s\n", usbg_error_name(usbg_ret),
+   usbg_strerror(usbg_ret));
+   goto out2;
+   }
 
ret = 0;
 
diff --git a/examples/show-gadgets.c b/examples/show-gadgets.c
index 4d79a09..df86cb9 100644
--- a/examples/show-gadgets.c
+++ b/examples/show-gadgets.c
@@ -30,11 +30,17 @@
 void show_gadget(usbg_gadget *g)
 {
char buf[USBG_MAX_STR_LENGTH];
+   int usbg_ret;
usbg_gadget_attrs g_attrs;
usbg_gadget_strs g_strs;
 
usbg_get_gadget_name(g, buf, USBG_MAX_STR_LENGTH);
-   usbg_get_gadget_attrs(g, &g_attrs);
+   usbg_ret = usbg_get_gadget_attrs(g,

[PATCH 19/23] libusbg: Return error code instead of NULL pointer - config.

2014-03-05 Thread Krzysztof Opasiak
Change usbg_get_config_strs() and usbg_get_config_attrs()
to return usbg_error instead of NULL pointer.

Signed-off-by: Krzysztof Opasiak 
---
 include/usbg/usbg.h |9 -
 src/usbg.c  |   50 +-
 2 files changed, 29 insertions(+), 30 deletions(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 6855833..1bb652e 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -502,10 +502,9 @@ extern int usbg_set_config_attrs(usbg_config *c,
  * @brief Get the USB configuration strings
  * @param c Pointer to configuration
  * @param c_attrs Structure to be filled
- * @retur Pointer to filled structure or NULL if error occurred.
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern usbg_config_attrs *usbg_get_config_attrs(usbg_config *c,
-   usbg_config_attrs *c_attrs);
+extern int usbg_get_config_attrs(usbg_config *c, usbg_config_attrs *c_attrs);
 
 /**
  * @brief Set the configuration maximum power
@@ -528,9 +527,9 @@ extern int usbg_set_config_bm_attrs(usbg_config *c, int 
bmAttributes);
  * @param c Pointer to configuration
  * @param lang Language of strings
  * @param c_sttrs Structure to be filled
- * @retur Pointer to filled structure or NULL if error occurred.
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern usbg_config_strs *usbg_get_config_strs(usbg_config *c, int lang,
+extern int usbg_get_config_strs(usbg_config *c, int lang,
usbg_config_strs *c_strs);
 
 /**
diff --git a/src/usbg.c b/src/usbg.c
index 9747069..74ad533 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -441,20 +441,28 @@ static int usbg_parse_functions(char *path, usbg_gadget 
*g)
return ret;
 }
 
-static void usbg_parse_config_attrs(char *path, char *name,
+static int usbg_parse_config_attrs(char *path, char *name,
usbg_config_attrs *c_attrs)
 {
-   int buf;
-   usbg_read_dec(path, name, "MaxPower", &buf);
-   c_attrs->bMaxPower = (uint8_t)buf;
-   usbg_read_hex(path, name, "bmAttributes", &buf);
-   c_attrs->bmAttributes = (uint8_t)buf;
+   int buf, ret;
+
+   ret = usbg_read_dec(path, name, "MaxPower", &buf);
+   if (ret == USBG_SUCCESS) {
+   c_attrs->bMaxPower = (uint8_t)buf;
+
+   ret = usbg_read_hex(path, name, "bmAttributes", &buf);
+   if (ret == USBG_SUCCESS)
+   c_attrs->bmAttributes = (uint8_t)buf;
+   }
+
+   return ret;
 }
 
-static usbg_config_strs *usbg_parse_config_strs(char *path, char *name,
+static int usbg_parse_config_strs(char *path, char *name,
int lang, usbg_config_strs *c_strs)
 {
DIR *dir;
+   int ret;
char spath[USBG_MAX_PATH_LENGTH];
 
sprintf(spath, "%s/%s/%s/0x%x", path, name, STRINGS_DIR, lang);
@@ -463,12 +471,13 @@ static usbg_config_strs *usbg_parse_config_strs(char 
*path, char *name,
dir = opendir(spath);
if (dir) {
closedir(dir);
-   usbg_read_string(spath, "", "configuration", 
c_strs->configuration);
+   ret = usbg_read_string(spath, "", "configuration",
+   c_strs->configuration);
} else {
-   c_strs = NULL;
+   ret = usbg_translate_error(errno);
}
 
-   return c_strs;
+   return ret;
 }
 
 static int usbg_parse_config_bindings(usbg_config *c)
@@ -1322,15 +1331,11 @@ int usbg_set_config_attrs(usbg_config *c, 
usbg_config_attrs *c_attrs)
return ret;
 }
 
-usbg_config_attrs *usbg_get_config_attrs(usbg_config *c,
+int usbg_get_config_attrs(usbg_config *c,
usbg_config_attrs *c_attrs)
 {
-   if (c && c_attrs)
-   usbg_parse_config_attrs(c->path, c->name, c_attrs);
-   else
-   c_attrs = NULL;
-
-   return c_attrs;
+   return c && c_attrs ? usbg_parse_config_attrs(c->path, c->name, c_attrs)
+   : USBG_ERROR_INVALID_PARAM;
 }
 
 int usbg_set_config_max_power(usbg_config *c, int bMaxPower)
@@ -1345,15 +1350,10 @@ int usbg_set_config_bm_attrs(usbg_config *c, int 
bmAttributes)
: USBG_ERROR_INVALID_PARAM;
 }
 
-usbg_config_strs *usbg_get_config_strs(usbg_config *c, int lang,
-   usbg_config_strs *c_strs)
+int usbg_get_config_strs(usbg_config *c, int lang, usbg_config_strs *c_strs)
 {
-   if (c && c_strs)
-   c_strs = usbg_parse_config_strs(c->path, c->name, lang, c_strs);
-   else
-   c_strs = NULL;
-
-   return c_strs;
+   return c && c_strs ? usbg_parse_config_strs(c->path, c->name, lang, 
c_strs)
+   : USBG_ERROR_INVALID_PARAM;
 }
 
 int usbg_set_config_strs(usbg_config *c, int lang,
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 20/23] libusbg: Change usbg_get_function_attrs() to return error code.

2014-03-05 Thread Krzysztof Opasiak
usbg_get_function_attrs() may fail due to many reasons
so it should notify the user about exact reason of failure
instead of returning only NULL pointer.

Add also USBG_ERROR_NOT_SUPPORTED to usbg_set_function_attrs().

Signed-off-by: Krzysztof Opasiak 
---
 include/usbg/usbg.h |5 ++--
 src/usbg.c  |   77 +++
 2 files changed, 56 insertions(+), 26 deletions(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 1bb652e..ae53d22 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -189,6 +189,7 @@ typedef enum  {
USBG_ERROR_EXIST = -6,
USBG_ERROR_NO_DEV = -7,
USBG_ERROR_BUSY = -8,
+   USBG_ERROR_NOT_SUPPORTED = -9,
USBG_ERROR_OTHER_ERROR = -99
 } usbg_error;
 
@@ -641,9 +642,9 @@ extern usbg_function_type 
usbg_get_function_type(usbg_function *f);
  * @brief Get attributes of given function
  * @param f Pointer to function
  * @param f_attrs Union to be filled
- * @return Pointer to filled structure or NULL if error occurred.
+ * @return 0 on success usbg_error if error occurred.
  */
-extern usbg_function_attrs *usbg_get_function_attrs(usbg_function *f,
+extern int usbg_get_function_attrs(usbg_function *f,
usbg_function_attrs *f_attrs);
 
 /**
diff --git a/src/usbg.c b/src/usbg.c
index 74ad533..b14e917 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -365,43 +365,76 @@ static void usbg_free_state(usbg_state *s)
free(s);
 }
 
-
-static void usbg_parse_function_attrs(usbg_function *f,
+static int usbg_parse_function_net_attrs(usbg_function *f,
usbg_function_attrs *f_attrs)
 {
struct ether_addr *addr;
char str_addr[40];
+   int ret;
+
+   ret = usbg_read_string(f->path, f->name, "dev_addr", str_addr);
+   if (ret != USBG_SUCCESS)
+   goto out;
+
+   addr = ether_aton(str_addr);
+   if (addr) {
+   f_attrs->net.dev_addr = *addr;
+   } else {
+   ret = USBG_ERROR_IO;
+   goto out;
+   }
+
+   ret = usbg_read_string(f->path, f->name, "host_addr", str_addr);
+   if (ret != USBG_SUCCESS)
+   goto out;
+
+   addr = ether_aton(str_addr);
+   if (addr) {
+   f_attrs->net.host_addr = *addr;
+   } else {
+   ret = USBG_ERROR_IO;
+   goto out;
+   }
+
+   ret = usbg_read_string(f->path, f->name, "ifname", f_attrs->net.ifname);
+   if (ret != USBG_SUCCESS)
+   goto out;
+
+   ret = usbg_read_dec(f->path, f->name, "qmult", &(f_attrs->net.qmult));
+
+out:
+   return ret;
+}
+
+static int usbg_parse_function_attrs(usbg_function *f,
+   usbg_function_attrs *f_attrs)
+{
+   int ret;
 
switch (f->type) {
case F_SERIAL:
case F_ACM:
case F_OBEX:
-   usbg_read_dec(f->path, f->name, "port_num", 
&(f_attrs->serial.port_num));
+   ret = usbg_read_dec(f->path, f->name, "port_num",
+   &(f_attrs->serial.port_num));
break;
case F_ECM:
case F_SUBSET:
case F_NCM:
case F_EEM:
case F_RNDIS:
-   usbg_read_string(f->path, f->name, "dev_addr", str_addr);
-   addr = ether_aton(str_addr);
-   if (addr)
-   f_attrs->net.dev_addr = *addr;
-
-   usbg_read_string(f->path, f->name, "host_addr", str_addr);
-   addr = ether_aton(str_addr);
-   if(addr)
-   f_attrs->net.host_addr = *addr;
-
-   usbg_read_string(f->path, f->name, "ifname", 
f_attrs->net.ifname);
-   usbg_read_dec(f->path, f->name, "qmult", &(f_attrs->net.qmult));
+   ret = usbg_parse_function_net_attrs(f, f_attrs);
break;
case F_PHONET:
-   usbg_read_string(f->path, f->name, "ifname", 
f_attrs->phonet.ifname);
+   ret = usbg_read_string(f->path, f->name, "ifname",
+   f_attrs->phonet.ifname);
break;
default:
ERROR("Unsupported function type\n");
+   ret = USBG_ERROR_NOT_SUPPORTED;
}
+
+   return ret;
 }
 
 static int usbg_parse_functions(char *path, usbg_gadget *g)
@@ -1515,15 +1548,10 @@ usbg_function_type usbg_get_function_type(usbg_function 
*f)
return f->type;
 }
 
-usbg_function_attrs *usbg_get_function_attrs(usbg_function *f,
-   usbg_function_attrs *f_attrs)
+int usbg_get_function_attrs(usbg_function *f, usbg_function_attrs *f_attrs)
 {
-   if (f && f_attrs)
-   usbg_parse_function_attrs(f, f_attrs);
-   else
-   f_attrs = NULL;
-
-   return f_attrs;
+   return f && f_attrs ? usbg_parse_function_attrs(f, f_attrs)
+   : USBG_ERROR_INVALID_PARAM;
 }
 
 int usbg_set_function_net_attrs(usbg_function *f, usbg_f_net_attrs *attrs)
@@ -15

[PATCH v8 0/4] phy: Add new Exynos USB 2.0 PHY driver

2014-03-05 Thread Kamil Debski
Hi,

This is the eighth version of this patchset. First and most significant change
since v6 is that this patchset includes only patches touching the Generic PHY
Framework. Patches to the USB controllers were stripped as they require
additional work. S5PV210 support is also omitted - it requires more testing.

Since v7 this patch includes fixes for checkpath errors and was rebased onto
Kishon's next branch.

Best wishes,
Kamil Debski

--
Changes from v7:
1) phy: core: Add an exported of_phy_get function
   - No changes since v7.
2) phy: core: Add devm_of_phy_get to phy-core
   - No changes since v7.
3) phy: Add new Exynos USB 2.0 PHY driver
   - Fix checkpatch errors with code indentation and corrected whitespace.
4) phy: Add Exynos 5250 support to the Exynos USB 2.0 PHY
   - Fix checkpatch errors with code indentation and corrected whitespace.

--
Changes from v6: (not including the change that controller patches were removed
form this patchset, also this patchset excludes S5PV210 support - it needs more
testing)
1) phy: core: Add an exported of_phy_get function
   - No changes since v6.
2) phy: core: Add devm_of_phy_get to phy-core
   - No changes since v6.
3) phy: Add new Exynos USB 2.0 PHY driver
   - Changed the way clocks are supplied to the driver. Prior to version v7
 there were reference clocks for every phy instance, now a single "ref"
 clock was introduced.
   - Updated documentation to match the aforementioned change.
   - Add offset EXYNOS_*_UPHYCLK_PHYFSEL_OFFSET to the clock register content
 defines.
   - Corrected way clock register is modified. Instead of a simple write, a
 proper read, modify, write sequence was introduced.
   - Important stability fix - added udelay after PHY reset. This fixes a bug
 causing instability in USB LAN adapters. Without the delay the DMA burst
 mode was could not be enabled.
4) phy: Add Exynos 5250 support to the Exynos USB 2.0 PHY
   - Changed handling of clocks to use a single "ref" clock.


Changes from v5:
1) phy: core: Add an exported of_phy_get function
- corrected behaviour of the modification when GENERIC_PHY is not enabled
  by adding a stub of the of_phy_get function
2) phy: core: Add devm_of_phy_get to phy-core
- corrected behaviour of the modification when GENERIC_PHY is not enabled
  by adding a stub of the devm_of_phy_get function
3) dts: Add usb2phy to Exynos 4
- no change
4) dts: Add usb2phy to Exynos 5250
- in the previous version, this patch included some phy-exynos5250-usb2.c code
  by mistake, the code has been remove and added to the proper patch
5) phy: Add new Exynos USB PHY driver
- changed strings from Exynos 4212 to Exynos 4x12, as the Exynos 4212 driver is
  actually a driver for the whole Exynos 4x12 family
- added documentation to the Exynos USB 2.0 PHY driver adaptaion layer
- corrected strings HSCI -> HSIC
- fixed a problem introduced by previous change - on Exynos 4x12 the HSIC did
  not work on its own
- mode switch support was added to Exynos 4x12 (same io pins are used by host
  and device)
- support for phy_set_bus_width introduced by Matt Porter was added
6) phy: Add support for S5PV210 to the Exynos USB PHY
- setting of clk register was fixed
7) phy: Add Exynos 5250 support to the Exynos USB 2.0 PHY
- supoprt was added for HSIC and device
8) usb: ehci-exynos: Change to use phy provided by the generic phy framework
- DT documentation was moved from usb-ehci.txt to exynos-usb.txt


Changes from v4:
1) phy: core: Add an exported of_phy_get function
- the new exported function of_phy_get was changed to take the phy's name as a
  parameter instead of the index
2) phy: core: Add devm_of_phy_get to phy-core
- fixes made in the comments to devm_of_phy_get
3) phy: Add new Exynos USB PHY driver
- move the documentation from a new to an existing file - samsung-phy.txt
- fix typos and uppercase hex addresses
- add more explanations to Kconfig (checkpatch still complains, but I find it
  hard to think what else could I add)
- add selects MFD_SYSCON as the driver needs it (Thank you, Tobias!)
- cleanup included headers in both *.c and .h files
- use BIT(x) macro instead of (1 << x)
- replaced HOST and DEV with PHY0 and PHY1 in phy-exynos4212-usb2.c, the
  registers are described as PHYx in the documentation hence the decision to
  leave the PHYx naming
- fixed typo in exynos4210_rate_to_clk reg -> *reg
- change hax_mode_switch and enabled type to bool
4) usb: ehci-s5p: Change to use phy provided by the generic phy framework
- Put the issue of phy->otg in order - since the new phy driver does not provide
  this field. With the new driver the switch between host and device is done in
  power_on of the respective host and device phys.
5) usb: s3c-hsotg: Use the new Exynos USB phy driver with the generic phy
   framework
- fixed the example in the documentation
6) phy: Add support for S5PV210 to the Exynos USB PHY driver
- include files cleanup
- use BIT(x) ma

[PATCH 21/23] libusbg: Return error code instead of -1.

2014-03-05 Thread Krzysztof Opasiak
Change usbg_add_config_function() to return usbg_error
instead of returning 0 or -1.

Signed-off-by: Krzysztof Opasiak 
---
 include/usbg/usbg.h |2 +-
 src/usbg.c  |   14 --
 2 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index ae53d22..249b40f 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -557,7 +557,7 @@ extern int usbg_set_config_string(usbg_config *c, int lang, 
char *string);
  * @param c Pointer to config
  * @param name Name of configuration function binding
  * @param f Pointer to function
- * @return 0 on success, -1 on failure.
+ * @return 0 on success, usbg_error on failure.
  */
 extern int usbg_add_config_function(usbg_config *c, char *name, usbg_function 
*f);
 
diff --git a/src/usbg.c b/src/usbg.c
index b14e917..860960a 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1417,21 +1417,21 @@ int usbg_add_config_function(usbg_config *c, char 
*name, usbg_function *f)
char bpath[USBG_MAX_PATH_LENGTH];
char fpath[USBG_MAX_PATH_LENGTH];
usbg_binding *b;
-   int ret = -1;
+   int ret = USBG_SUCCESS;
 
if (!c || !f)
-   return ret;
+   return USBG_ERROR_INVALID_PARAM;
 
b = usbg_get_binding(c, name);
if (b) {
ERROR("duplicate binding name\n");
-   return ret;
+   return USBG_ERROR_EXIST;
}
 
b = usbg_get_link_binding(c, f);
if (b) {
ERROR("duplicate binding link\n");
-   return ret;
+   return USBG_ERROR_EXIST;
}
 
sprintf(bpath, "%s/%s/%s", c->path, c->name, name);
@@ -1440,13 +1440,15 @@ int usbg_add_config_function(usbg_config *c, char 
*name, usbg_function *f)
b = malloc(sizeof(usbg_binding));
if (!b) {
ERRORNO("allocating binding\n");
-   return -1;
+   return USBG_ERROR_NO_MEM;
}
 
ret = symlink(fpath, bpath);
if (ret < 0) {
ERRORNO("%s -> %s\n", bpath, fpath);
return ret;
+   } else {
+   ret = USBG_SUCCESS;
}
 
strcpy(b->name, name);
@@ -1456,7 +1458,7 @@ int usbg_add_config_function(usbg_config *c, char *name, 
usbg_function *f)
 
INSERT_TAILQ_STRING_ORDER(&c->bindings, bhead, name, b, bnode);
 
-   return 0;
+   return ret;
 }
 
 usbg_function *usbg_get_binding_target(usbg_binding *b)
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 2/4] phy: core: Add devm_of_phy_get to phy-core

2014-03-05 Thread Kamil Debski
Adding devm_of_phy_get will allow to get phys by supplying a
pointer to the struct device_node instead of struct device.

Signed-off-by: Kamil Debski 
---
 drivers/phy/phy-core.c  |   31 +++
 include/linux/phy/phy.h |8 
 2 files changed, 39 insertions(+)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 7c1b0e1..623b71c 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -526,6 +526,37 @@ struct phy *devm_phy_optional_get(struct device *dev, 
const char *string)
 EXPORT_SYMBOL_GPL(devm_phy_optional_get);
 
 /**
+ * devm_of_phy_get() - lookup and obtain a reference to a phy.
+ * @dev: device that requests this phy
+ * @np: node containing the phy
+ * @con_id: name of the phy from device's point of view
+ *
+ * Gets the phy using of_phy_get(), and associates a device with it using
+ * devres. On driver detach, release function is invoked on the devres data,
+ * then, devres data is freed.
+ */
+struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
+   const char *con_id)
+{
+   struct phy **ptr, *phy;
+
+   ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
+   if (!ptr)
+   return ERR_PTR(-ENOMEM);
+
+   phy = of_phy_get(np, con_id);
+   if (!IS_ERR(phy)) {
+   *ptr = phy;
+   devres_add(dev, ptr);
+   } else {
+   devres_free(ptr);
+   }
+
+   return phy;
+}
+EXPORT_SYMBOL_GPL(devm_of_phy_get);
+
+/**
  * phy_create() - create a new phy
  * @dev: device that is creating the new phy
  * @ops: function pointers for performing phy operations
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index 2fe3194..bcbf96c 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -149,6 +149,8 @@ struct phy *phy_get(struct device *dev, const char *string);
 struct phy *phy_optional_get(struct device *dev, const char *string);
 struct phy *devm_phy_get(struct device *dev, const char *string);
 struct phy *devm_phy_optional_get(struct device *dev, const char *string);
+struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
+   const char *con_id);
 void phy_put(struct phy *phy);
 void devm_phy_put(struct device *dev, struct phy *phy);
 struct phy *of_phy_get(struct device_node *np, const char *con_id);
@@ -252,6 +254,12 @@ static inline struct phy *devm_phy_optional_get(struct 
device *dev,
return ERR_PTR(-ENOSYS);
 }
 
+struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
+   const char *con_id)
+{
+   return ERR_PTR(-ENOSYS);
+}
+
 static inline void phy_put(struct phy *phy)
 {
 }
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 4/4] phy: Add Exynos 5250 support to the Exynos USB 2.0 PHY driver

2014-03-05 Thread Kamil Debski
Add support for Exynos 5250. This driver is to replace the old
USB 2.0 PHY driver.

Signed-off-by: Kamil Debski 
---
 .../devicetree/bindings/phy/samsung-phy.txt|1 +
 drivers/phy/Kconfig|   11 +
 drivers/phy/Makefile   |1 +
 drivers/phy/phy-exynos5250-usb2.c  |  405 
 drivers/phy/phy-samsung-usb2.c |6 +
 drivers/phy/phy-samsung-usb2.h |1 +
 6 files changed, 425 insertions(+)
 create mode 100644 drivers/phy/phy-exynos5250-usb2.c

diff --git a/Documentation/devicetree/bindings/phy/samsung-phy.txt 
b/Documentation/devicetree/bindings/phy/samsung-phy.txt
index bf955ab..28f9edb 100644
--- a/Documentation/devicetree/bindings/phy/samsung-phy.txt
+++ b/Documentation/devicetree/bindings/phy/samsung-phy.txt
@@ -28,6 +28,7 @@ Required properties:
 - compatible : should be one of the listed compatibles:
- "samsung,exynos4210-usb2-phy"
- "samsung,exynos4x12-usb2-phy"
+   - "samsung,exynos5250-usb2-phy"
 - reg : a list of registers used by phy driver
- first and obligatory is the location of phy modules registers
 - samsung,sysreg-phandle - handle to syscon used to control the system 
registers
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index fc5a44a..c206e25 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -125,4 +125,15 @@ config PHY_EXYNOS4X12_USB2
  Samsung USB 2.0 PHY driver is enabled and means that support for this
  particular SoC is compiled in the driver. In case of Exynos 4x12 four
  phys are available - device, host, HSIC0 and HSIC1.
+
+config PHY_EXYNOS5250_USB2
+   bool "Support for Exynos 5250"
+   depends on PHY_SAMSUNG_USB2
+   depends on SOC_EXYNOS5250
+   help
+ Enable USB PHY support for Exynos 5250. This option requires that
+ Samsung USB 2.0 PHY driver is enabled and means that support for this
+ particular SoC is compiled in the driver. In case of Exynos 5250 four
+ phys are available - device, host, HSIC0 and HSIC.
+
 endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 0ea36ff..f76c239 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_PHY_SUN4I_USB)   += phy-sun4i-usb.o
 obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-samsung-usb2.o
 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
diff --git a/drivers/phy/phy-exynos5250-usb2.c 
b/drivers/phy/phy-exynos5250-usb2.c
new file mode 100644
index 000..877994e
--- /dev/null
+++ b/drivers/phy/phy-exynos5250-usb2.c
@@ -0,0 +1,405 @@
+/*
+ * Samsung SoC USB 1.1/2.0 PHY driver - Exynos 5250 support
+ *
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd.
+ * Author: Kamil Debski 
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include "phy-samsung-usb2.h"
+
+/* Exynos USB PHY registers */
+#define EXYNOS_5250_REFCLKSEL_CRYSTAL  0x0
+#define EXYNOS_5250_REFCLKSEL_XO   0x1
+#define EXYNOS_5250_REFCLKSEL_CLKCORE  0x2
+
+#define EXYNOS_5250_FSEL_9MHZ6 0x0
+#define EXYNOS_5250_FSEL_10MHZ 0x1
+#define EXYNOS_5250_FSEL_12MHZ 0x2
+#define EXYNOS_5250_FSEL_19MHZ20x3
+#define EXYNOS_5250_FSEL_20MHZ 0x4
+#define EXYNOS_5250_FSEL_24MHZ 0x5
+#define EXYNOS_5250_FSEL_50MHZ 0x7
+
+/* Normal host */
+#define EXYNOS_5250_HOSTPHYCTRL0   0x0
+
+#define EXYNOS_5250_HOSTPHYCTRL0_PHYSWRSTALL   BIT(31)
+#define EXYNOS_5250_HOSTPHYCTRL0_REFCLKSEL_SHIFT   19
+#define EXYNOS_5250_HOSTPHYCTRL0_REFCLKSEL_MASK\
+   (0x3 << EXYNOS_5250_HOSTPHYCTRL0_REFCLKSEL_SHIFT)
+#define EXYNOS_5250_HOSTPHYCTRL0_FSEL_SHIFT16
+#define EXYNOS_5250_HOSTPHYCTRL0_FSEL_MASK \
+   (0x7 << EXYNOS_5250_HOSTPHYCTRL0_FSEL_SHIFT)
+#define EXYNOS_5250_HOSTPHYCTRL0_TESTBURNINBIT(11)
+#define EXYNOS_5250_HOSTPHYCTRL0_RETENABLE BIT(10)
+#define EXYNOS_5250_HOSTPHYCTRL0_COMMON_ON_N   BIT(9)
+#define EXYNOS_5250_HOSTPHYCTRL0_VATESTENB_MASK(0x3 << 7)
+#define EXYNOS_5250_HOSTPHYCTRL0_VATESTENB_DUAL(0x0 << 7)
+#define EXYNOS_5250_HOSTPHYCTRL0_VATESTENB_ID0 (0x1 << 7)
+#define EXYNOS_5250_HOSTPHYCTRL0_VATESTENB_ANALOGTEST  (0x2 << 7)
+#define EXYNOS_5250_HOSTPHYCTRL0_SIDDQ BIT(6)
+#define EXYNOS_5250_HOSTPHYCTRL0_FORCESLEEPBIT(5)
+#define EXYNOS_5250_HOSTPHYCTRL0_FORCESUSPEND  BIT(4)
+#define EXYNOS_5250_HOSTPHYCTRL0_WORDINTERFACE BIT(3)
+#define EXYNOS_5250_HOSTPHYCTRL0_UTMISWRS

[PATCH 16/23] libusbg: Add return value to config related functions.

2014-03-05 Thread Krzysztof Opasiak
Each usbg_set_config_*() may fail so it should have
a return value to notify user about reason of failure.

To be consistent with rest of API usbg_create_config()
should also return error code to notify user about reasons
of failure instead of binary information (NULL or not).

Signed-off-by: Krzysztof Opasiak 
---
 examples/gadget-acm-ecm.c |4 +-
 include/usbg/usbg.h   |   23 ++
 src/usbg.c|  110 ++---
 3 files changed, 81 insertions(+), 56 deletions(-)

diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c
index 678514c..cda3808 100644
--- a/examples/gadget-acm-ecm.c
+++ b/examples/gadget-acm-ecm.c
@@ -87,8 +87,8 @@ int main(void)
goto out2;
}
 
-   c = usbg_create_config(g, "c.1", NULL /* use defaults */, &c_strs);
-   if (!c) {
+   usbg_ret = usbg_create_config(g, "c.1", NULL /* use defaults */, 
&c_strs, &c);
+   if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error creating config\n");
goto out2;
}
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 005f9eb..1fa9d22 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -466,10 +466,12 @@ extern int usbg_get_function_name(usbg_function *f, char 
*buf, size_t len);
  * @param name Name of configuration
  * @param c_attrs Configuration attributes to be set
  * @param c_strs Configuration strings to be set
- * @return Pointer to configuration or NULL if it cannot be created
+ * @param c Pointer to be filled with pointer to configuration
+ * @note Given strings are assumed to be in US English
+ * @return 0 on success usbg_error if error occurred
  */
-extern usbg_config *usbg_create_config(usbg_gadget *g, char *name,
-   usbg_config_attrs *c_attrs, usbg_config_strs *c_strs);
+extern int usbg_create_config(usbg_gadget *g, char *name,
+   usbg_config_attrs *c_attrs, usbg_config_strs *c_strs, 
usbg_config **c);
 
 /**
  * @brief Get config name length
@@ -491,8 +493,9 @@ extern int usbg_get_config_name(usbg_config *c, char *buf, 
size_t len);
  * @brief Set the USB configuration attributes
  * @param c Pointer to configuration
  * @param c_attrs Configuration attributes
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern void usbg_set_config_attrs(usbg_config *c,
+extern int usbg_set_config_attrs(usbg_config *c,
usbg_config_attrs *c_attrs);
 
 /**
@@ -508,15 +511,17 @@ extern usbg_config_attrs 
*usbg_get_config_attrs(usbg_config *c,
  * @brief Set the configuration maximum power
  * @param c Pointer to config
  * @param bMaxPower Maximum power (in 2 mA units)
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern void usbg_set_config_max_power(usbg_config *c, int bMaxPower);
+extern int usbg_set_config_max_power(usbg_config *c, int bMaxPower);
 
 /**
  * @brief Set the configuration bitmap attributes
  * @param c Pointer to config
  * @param bmAttributes Configuration characteristics
+ * @return 0 on success or usbg_error if error occurred.
  */
-extern void usbg_set_config_bm_attrs(usbg_config *c, int bmAttributes);
+extern int usbg_set_config_bm_attrs(usbg_config *c, int bmAttributes);
 
 /**
  * @brief Get the USB configuration strings
@@ -533,8 +538,9 @@ extern usbg_config_strs *usbg_get_config_strs(usbg_config 
*c, int lang,
  * @param c Pointer to configuration
  * @param lang USB language ID
  * @param c_sttrs Configuration strings
+ * @return 0 on success, usbg_error on failure.
  */
-extern void usbg_set_config_strs(usbg_config *c, int lang,
+extern int usbg_set_config_strs(usbg_config *c, int lang,
usbg_config_strs *c_strs);
 
 /**
@@ -542,8 +548,9 @@ extern void usbg_set_config_strs(usbg_config *c, int lang,
  * @param c Pointer to config
  * @param lang USB language ID
  * @param string Configuration description
+ * @return 0 on success, usbg_error on failure.
  */
-extern void usbg_set_config_string(usbg_config *c, int lang, char *string);
+extern int usbg_set_config_string(usbg_config *c, int lang, char *string);
 
 /**
  * @brief Add a function to a configuration
diff --git a/src/usbg.c b/src/usbg.c
index 0b0a799..3c6c008 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1215,53 +1215,58 @@ int usbg_create_function(usbg_gadget *g, 
usbg_function_type type,
return ret;
 }
 
-usbg_config *usbg_create_config(usbg_gadget *g, char *name,
-   usbg_config_attrs *c_attrs, usbg_config_strs *c_strs)
+int usbg_create_config(usbg_gadget *g, char *name,
+   usbg_config_attrs *c_attrs, usbg_config_strs *c_strs, 
usbg_config **c)
 {
char cpath[USBG_MAX_PATH_LENGTH];
-   usbg_config *c;
-   int ret;
+   usbg_config *conf;
+   int ret = USBG_ERROR_INVALID_PARAM;
 
-   if (!g)
-   return NULL;
+   if (!g || !c)
+   return ret;
 
/**
 * @todo Check for legal configuration name
 */
-  

[PATCH v8 1/4] phy: core: Add an exported of_phy_get function

2014-03-05 Thread Kamil Debski
Previously the of_phy_get function took a struct device * and
was declared static. It was impossible to call it from
another driver and thus it was impossible to get phy defined
for a given node. The old function was renamed to _of_phy_get
and was left for internal use. of_phy_get function was added
and it was exported. The function enables to get a phy for
a given device tree node.

Signed-off-by: Kamil Debski 
---
 drivers/phy/phy-core.c  |   45 -
 include/linux/phy/phy.h |6 ++
 2 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 6c73837..7c1b0e1 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -274,8 +274,8 @@ int phy_power_off(struct phy *phy)
 EXPORT_SYMBOL_GPL(phy_power_off);
 
 /**
- * of_phy_get() - lookup and obtain a reference to a phy by phandle
- * @dev: device that requests this phy
+ * _of_phy_get() - lookup and obtain a reference to a phy by phandle
+ * @np: device_node for which to get the phy
  * @index: the index of the phy
  *
  * Returns the phy associated with the given phandle value,
@@ -284,20 +284,17 @@ EXPORT_SYMBOL_GPL(phy_power_off);
  * not yet loaded. This function uses of_xlate call back function provided
  * while registering the phy_provider to find the phy instance.
  */
-static struct phy *of_phy_get(struct device *dev, int index)
+static struct phy *_of_phy_get(struct device_node *np, int index)
 {
int ret;
struct phy_provider *phy_provider;
struct phy *phy = NULL;
struct of_phandle_args args;
 
-   ret = of_parse_phandle_with_args(dev->of_node, "phys", "#phy-cells",
+   ret = of_parse_phandle_with_args(np, "phys", "#phy-cells",
index, &args);
-   if (ret) {
-   dev_dbg(dev, "failed to get phy in %s node\n",
-   dev->of_node->full_name);
+   if (ret)
return ERR_PTR(-ENODEV);
-   }
 
mutex_lock(&phy_provider_mutex);
phy_provider = of_phy_provider_lookup(args.np);
@@ -317,6 +314,36 @@ err0:
 }
 
 /**
+ * of_phy_get() - lookup and obtain a reference to a phy using a device_node.
+ * @np: device_node for which to get the phy
+ * @con_id: name of the phy from device's point of view
+ *
+ * Returns the phy driver, after getting a refcount to it; or
+ * -ENODEV if there is no such phy. The caller is responsible for
+ * calling phy_put() to release that count.
+ */
+struct phy *of_phy_get(struct device_node *np, const char *con_id)
+{
+   struct phy *phy = NULL;
+   int index = 0;
+
+   if (con_id)
+   index = of_property_match_string(np, "phy-names", con_id);
+
+   phy = _of_phy_get(np, index);
+   if (IS_ERR(phy))
+   return phy;
+
+   if (!try_module_get(phy->ops->owner))
+   return ERR_PTR(-EPROBE_DEFER);
+
+   get_device(&phy->dev);
+
+   return phy;
+}
+EXPORT_SYMBOL_GPL(of_phy_get);
+
+/**
  * phy_put() - release the PHY
  * @phy: the phy returned by phy_get()
  *
@@ -407,7 +434,7 @@ struct phy *phy_get(struct device *dev, const char *string)
if (dev->of_node) {
index = of_property_match_string(dev->of_node, "phy-names",
string);
-   phy = of_phy_get(dev, index);
+   phy = _of_phy_get(dev->of_node, index);
} else {
phy = phy_lookup(dev, string);
}
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index 3f83459..2fe3194 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -151,6 +151,7 @@ struct phy *devm_phy_get(struct device *dev, const char 
*string);
 struct phy *devm_phy_optional_get(struct device *dev, const char *string);
 void phy_put(struct phy *phy);
 void devm_phy_put(struct device *dev, struct phy *phy);
+struct phy *of_phy_get(struct device_node *np, const char *con_id);
 struct phy *of_phy_simple_xlate(struct device *dev,
struct of_phandle_args *args);
 struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
@@ -259,6 +260,11 @@ static inline void devm_phy_put(struct device *dev, struct 
phy *phy)
 {
 }
 
+struct phy *of_phy_get(struct device_node *np, const char *con_id)
+{
+   return ERR_PTR(-ENOSYS);
+}
+
 static inline struct phy *of_phy_simple_xlate(struct device *dev,
struct of_phandle_args *args)
 {
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v8 3/4] phy: Add new Exynos USB 2.0 PHY driver

2014-03-05 Thread Kamil Debski
Add a new driver for the Exynos USB 2.0 PHY. The new driver uses the generic
PHY framework. The driver includes support for the Exynos 4x10 and 4x12
SoC families.

Signed-off-by: Kamil Debski 
---
 .../devicetree/bindings/phy/samsung-phy.txt|   53 
 Documentation/phy/samsung-usb2.txt |  134 
 drivers/phy/Kconfig|   29 ++
 drivers/phy/Makefile   |3 +
 drivers/phy/phy-exynos4210-usb2.c  |  262 
 drivers/phy/phy-exynos4x12-usb2.c  |  329 
 drivers/phy/phy-samsung-usb2.c |  223 +
 drivers/phy/phy-samsung-usb2.h |   67 
 8 files changed, 1100 insertions(+)
 create mode 100644 Documentation/phy/samsung-usb2.txt
 create mode 100644 drivers/phy/phy-exynos4210-usb2.c
 create mode 100644 drivers/phy/phy-exynos4x12-usb2.c
 create mode 100644 drivers/phy/phy-samsung-usb2.c
 create mode 100644 drivers/phy/phy-samsung-usb2.h

diff --git a/Documentation/devicetree/bindings/phy/samsung-phy.txt 
b/Documentation/devicetree/bindings/phy/samsung-phy.txt
index c0fccaa..bf955ab 100644
--- a/Documentation/devicetree/bindings/phy/samsung-phy.txt
+++ b/Documentation/devicetree/bindings/phy/samsung-phy.txt
@@ -20,3 +20,56 @@ Required properties:
 - compatible : should be "samsung,exynos5250-dp-video-phy";
 - reg : offset and length of the Display Port PHY register set;
 - #phy-cells : from the generic PHY bindings, must be 0;
+
+Samsung S5P/EXYNOS SoC series USB PHY
+-
+
+Required properties:
+- compatible : should be one of the listed compatibles:
+   - "samsung,exynos4210-usb2-phy"
+   - "samsung,exynos4x12-usb2-phy"
+- reg : a list of registers used by phy driver
+   - first and obligatory is the location of phy modules registers
+- samsung,sysreg-phandle - handle to syscon used to control the system 
registers
+- samsung,pmureg-phandle - handle to syscon used to control PMU registers
+- #phy-cells : from the generic phy bindings, must be 1;
+- clocks and clock-names:
+   - the "phy" clock is required by the phy module, used as a gate
+   - the "ref" clock is used to get the rate of the clock provided to the
+ PHY module
+
+The first phandle argument in the PHY specifier identifies the PHY, its
+meaning is compatible dependent. For the currently supported SoCs (Exynos 4210
+and Exynos 4212) it is as follows:
+  0 - USB device ("device"),
+  1 - USB host ("host"),
+  2 - HSIC0 ("hsic0"),
+  3 - HSIC1 ("hsic1"),
+
+Exynos 4210 and Exynos 4212 use mode switching and require that mode switch
+register is supplied.
+
+Example:
+
+For Exynos 4412 (compatible with Exynos 4212):
+
+usbphy: phy@125b {
+   compatible = "samsung,exynos4x12-usb2-phy";
+   reg = <0x125b 0x100>;
+   clocks = <&clock 305>, <&clock 2>;
+   clock-names = "phy", "ref";
+   status = "okay";
+   #phy-cells = <1>;
+   samsung,sysreg-phandle = <&sys_reg>;
+   samsung,pmureg-phandle = <&pmu_reg>;
+};
+
+Then the PHY can be used in other nodes such as:
+
+phy-consumer@1234 {
+   phys = <&usbphy 2>;
+   phy-names = "phy";
+};
+
+Refer to DT bindings documentation of particular PHY consumer devices for more
+information about required PHYs and the way of specification.
diff --git a/Documentation/phy/samsung-usb2.txt 
b/Documentation/phy/samsung-usb2.txt
new file mode 100644
index 000..0c8e260
--- /dev/null
+++ b/Documentation/phy/samsung-usb2.txt
@@ -0,0 +1,134 @@
+.--+
+|  Samsung USB 2.0 PHY adaptation layer   |
++-+'
+
+| 1. Description
++
+
+The architecture of the USB 2.0 PHY module in Samsung SoCs is similar
+among many SoCs. In spite of the similarities it proved difficult to
+create a one driver that would fit all these PHY controllers. Often
+the differences were minor and were found in particular bits of the
+registers of the PHY. In some rare cases the order of register writes or
+the PHY powering up process had to be altered. This adaptation layer is
+a compromise between having separate drivers and having a single driver
+with added support for many special cases.
+
+| 2. Files description
++--
+
+- phy-samsung-usb2.c
+   This is the main file of the adaptation layer. This file contains
+   the probe function and provides two callbacks to the Generic PHY
+   Framework. This two callbacks are used to power on and power off the
+   phy. They carry out the common work that has to be done on all version
+   of the PHY module. Depending on which SoC was chosen they execute SoC
+   specific callbacks. The specific SoC version is selected by choosing
+   the appropriate compatible string. In addi

USB remote wakeup through gpio interrupt

2014-03-05 Thread Jagdish Gedia
Hi,
There is some inconsistency in remote wakeup functionality in my
custom board. so I want to wakeup the runtime suspended USB host
through interrupt. My USB device is connected to the board through USB
interface and some gpios. device will give interrupt on processor gpio
when it needs attention of USB host. What should i do so that i can
wakeup the usb host when i get interrupt from the device.

My idea was to apply power management related hooks from the interrupt
handler, but I am not getting the clear idea.

My main doubt is,
Will this mechanism be efficient as remote wakeup functionality?
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH 15/23] libusbg: Add return value to usb function related functions.

2014-03-05 Thread Krzysztof Opasiak
Each usbg_set_*() may fail so it should have a return value
to notify user about reason of failure.

To be consistent with rest of API usbg_create_function()
should also return error code to notify user about reasons
of failure instead of binary information (NULL or not).

Signed-off-by: Krzysztof Opasiak 
---
 examples/gadget-acm-ecm.c |   12 ++--
 include/usbg/usbg.h   |   20 ---
 src/usbg.c|  140 -
 3 files changed, 108 insertions(+), 64 deletions(-)

diff --git a/examples/gadget-acm-ecm.c b/examples/gadget-acm-ecm.c
index b1131b4..678514c 100644
--- a/examples/gadget-acm-ecm.c
+++ b/examples/gadget-acm-ecm.c
@@ -69,20 +69,20 @@ int main(void)
goto out2;
}
 
-   f_acm0 = usbg_create_function(g, F_ACM, "usb0", NULL);
-   if (!f_acm0) {
+   usbg_ret = usbg_create_function(g, F_ACM, "usb0", NULL, &f_acm0);
+   if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error creating acm0 function\n");
goto out2;
}
 
-   f_acm1 = usbg_create_function(g, F_ACM, "usb1", NULL);
-   if (!f_acm1) {
+   usbg_ret = usbg_create_function(g, F_ACM, "usb1", NULL, &f_acm1);
+   if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error creating acm1 function\n");
goto out2;
}
 
-   f_ecm = usbg_create_function(g, F_ECM, "usb0", NULL);
-   if (!f_ecm) {
+   usbg_ret = usbg_create_function(g, F_ECM, "usb0", NULL, &f_acm1);
+   if (usbg_ret != USBG_SUCCESS) {
fprintf(stderr, "Error creating ecm function\n");
goto out2;
}
diff --git a/include/usbg/usbg.h b/include/usbg/usbg.h
index 17084bb..005f9eb 100644
--- a/include/usbg/usbg.h
+++ b/include/usbg/usbg.h
@@ -435,10 +435,12 @@ extern int usbg_set_gadget_product(usbg_gadget *g, int 
lang, char *prd);
  * @param type Type of function
  * @param instance Function instance name
  * @param f_attrs Function attributes to be set. If NULL setting is omitted.
- * @return Pointer to function or NULL if it cannot be created
+ * @param f Pointer to be filled with pointer to function
+ * @note Given strings are assumed to be in US English
+ * @return 0 on success usbg_error if error occurred
  */
-extern usbg_function *usbg_create_function(usbg_gadget *g, usbg_function_type 
type,
-   char *instance, usbg_function_attrs *f_attrs);
+extern int usbg_create_function(usbg_gadget *g, usbg_function_type type,
+   char *instance, usbg_function_attrs *f_attrs, usbg_function 
**f);
 
 /**
  * @brief Get function name length
@@ -640,29 +642,33 @@ extern usbg_function_attrs 
*usbg_get_function_attrs(usbg_function *f,
  * @brief Set attributes of given function
  * @param f Pointer to function
  * @param f_attrs Attributes to be set
+ * @return 0 on success, usbg_error if error occurred
  */
-extern void usbg_set_function_attrs(usbg_function *f, usbg_function_attrs 
*f_attrs);
+extern int usbg_set_function_attrs(usbg_function *f, usbg_function_attrs 
*f_attrs);
 
 /**
  * @brief Set USB function network device address
  * @param f Pointer to function
  * @param addr Pointer to Ethernet address
+ * @return 0 on success, usbg_error if error occurred
  */
-extern void usbg_set_net_dev_addr(usbg_function *f, struct ether_addr *addr);
+extern int usbg_set_net_dev_addr(usbg_function *f, struct ether_addr *addr);
 
 /**
  * @brief Set USB function network host address
  * @param f Pointer to function
  * @param addr Pointer to Ethernet address
+ * @return 0 on success, usbg_error if error occurred
  */
-extern void usbg_set_net_host_addr(usbg_function *f, struct ether_addr *addr);
+extern int usbg_set_net_host_addr(usbg_function *f, struct ether_addr *addr);
 
 /**
  * @brief Set USB function network qmult
  * @param f Pointer to function
  * @param qmult Queue length multiplier
+ * @return 0 on success, usbg_error if error occurred
  */
-extern void usbg_set_net_qmult(usbg_function *f, int qmult);
+extern int usbg_set_net_qmult(usbg_function *f, int qmult);
 
 /**
  * @def usbg_for_each_gadget(g, s)
diff --git a/src/usbg.c b/src/usbg.c
index b777653..0b0a799 100644
--- a/src/usbg.c
+++ b/src/usbg.c
@@ -1161,52 +1161,58 @@ int usbg_set_gadget_product(usbg_gadget *g, int lang, 
char *prd)
return ret;
 }
 
-usbg_function *usbg_create_function(usbg_gadget *g, usbg_function_type type,
-   char *instance, usbg_function_attrs *f_attrs)
+int usbg_create_function(usbg_gadget *g, usbg_function_type type,
+   char *instance, usbg_function_attrs *f_attrs, usbg_function **f)
 {
char fpath[USBG_MAX_PATH_LENGTH];
char name[USBG_MAX_STR_LENGTH];
-   usbg_function *f;
-   int ret;
+   usbg_function *func;
+   int ret = USBG_ERROR_INVALID_PARAM;
 
-   if (!g)
-   return NULL;
+   if (!g || !f)
+   return ret;
 
/**
 * @todo Check for legal funct

Re: [PATCH v8 3/4] phy: Add new Exynos USB 2.0 PHY driver

2014-03-05 Thread Kishon Vijay Abraham I

Kamil,

On Wednesday 05 March 2014 07:48 PM, Kamil Debski wrote:

Add a new driver for the Exynos USB 2.0 PHY. The new driver uses the generic
PHY framework. The driver includes support for the Exynos 4x10 and 4x12
SoC families.


Pls fix these errors which I get while applying your patch.

Applying: phy: Add new Exynos USB 2.0 PHY driver
/home/kishon/repos/linux-phy/.git/rebase-apply/patch:534: new blank line 
at EOF.

+
/home/kishon/repos/linux-phy/.git/rebase-apply/patch:869: new blank line 
at EOF.

+
/home/kishon/repos/linux-phy/.git/rebase-apply/patch:1098: new blank 
line at EOF.

+
/home/kishon/repos/linux-phy/.git/rebase-apply/patch:1171: new blank 
line at EOF.

+
warning: 4 lines add whitespace errors.

Thanks
Kishon



Signed-off-by: Kamil Debski 
---
  .../devicetree/bindings/phy/samsung-phy.txt|   53 
  Documentation/phy/samsung-usb2.txt |  134 
  drivers/phy/Kconfig|   29 ++
  drivers/phy/Makefile   |3 +
  drivers/phy/phy-exynos4210-usb2.c  |  262 
  drivers/phy/phy-exynos4x12-usb2.c  |  329 
  drivers/phy/phy-samsung-usb2.c |  223 +
  drivers/phy/phy-samsung-usb2.h |   67 
  8 files changed, 1100 insertions(+)
  create mode 100644 Documentation/phy/samsung-usb2.txt
  create mode 100644 drivers/phy/phy-exynos4210-usb2.c
  create mode 100644 drivers/phy/phy-exynos4x12-usb2.c
  create mode 100644 drivers/phy/phy-samsung-usb2.c
  create mode 100644 drivers/phy/phy-samsung-usb2.h

diff --git a/Documentation/devicetree/bindings/phy/samsung-phy.txt 
b/Documentation/devicetree/bindings/phy/samsung-phy.txt
index c0fccaa..bf955ab 100644
--- a/Documentation/devicetree/bindings/phy/samsung-phy.txt
+++ b/Documentation/devicetree/bindings/phy/samsung-phy.txt
@@ -20,3 +20,56 @@ Required properties:
  - compatible : should be "samsung,exynos5250-dp-video-phy";
  - reg : offset and length of the Display Port PHY register set;
  - #phy-cells : from the generic PHY bindings, must be 0;
+
+Samsung S5P/EXYNOS SoC series USB PHY
+-
+
+Required properties:
+- compatible : should be one of the listed compatibles:
+   - "samsung,exynos4210-usb2-phy"
+   - "samsung,exynos4x12-usb2-phy"
+- reg : a list of registers used by phy driver
+   - first and obligatory is the location of phy modules registers
+- samsung,sysreg-phandle - handle to syscon used to control the system 
registers
+- samsung,pmureg-phandle - handle to syscon used to control PMU registers
+- #phy-cells : from the generic phy bindings, must be 1;
+- clocks and clock-names:
+   - the "phy" clock is required by the phy module, used as a gate
+   - the "ref" clock is used to get the rate of the clock provided to the
+ PHY module
+
+The first phandle argument in the PHY specifier identifies the PHY, its
+meaning is compatible dependent. For the currently supported SoCs (Exynos 4210
+and Exynos 4212) it is as follows:
+  0 - USB device ("device"),
+  1 - USB host ("host"),
+  2 - HSIC0 ("hsic0"),
+  3 - HSIC1 ("hsic1"),
+
+Exynos 4210 and Exynos 4212 use mode switching and require that mode switch
+register is supplied.
+
+Example:
+
+For Exynos 4412 (compatible with Exynos 4212):
+
+usbphy: phy@125b {
+   compatible = "samsung,exynos4x12-usb2-phy";
+   reg = <0x125b 0x100>;
+   clocks = <&clock 305>, <&clock 2>;
+   clock-names = "phy", "ref";
+   status = "okay";
+   #phy-cells = <1>;
+   samsung,sysreg-phandle = <&sys_reg>;
+   samsung,pmureg-phandle = <&pmu_reg>;
+};
+
+Then the PHY can be used in other nodes such as:
+
+phy-consumer@1234 {
+   phys = <&usbphy 2>;
+   phy-names = "phy";
+};
+
+Refer to DT bindings documentation of particular PHY consumer devices for more
+information about required PHYs and the way of specification.
diff --git a/Documentation/phy/samsung-usb2.txt 
b/Documentation/phy/samsung-usb2.txt
new file mode 100644
index 000..0c8e260
--- /dev/null
+++ b/Documentation/phy/samsung-usb2.txt
@@ -0,0 +1,134 @@
+.--+
+|  Samsung USB 2.0 PHY adaptation layer   |
++-+'
+
+| 1. Description
++
+
+The architecture of the USB 2.0 PHY module in Samsung SoCs is similar
+among many SoCs. In spite of the similarities it proved difficult to
+create a one driver that would fit all these PHY controllers. Often
+the differences were minor and were found in particular bits of the
+registers of the PHY. In some rare cases the order of register writes or
+the PHY powering up process had to be altered. This adaptation layer is
+a compromise between having separate drivers and having a single driver
+wit

Re: [PATCH v8 4/4] phy: Add Exynos 5250 support to the Exynos USB 2.0 PHY driver

2014-03-05 Thread Kishon Vijay Abraham I

Hi,

On Wednesday 05 March 2014 07:48 PM, Kamil Debski wrote:

Add support for Exynos 5250. This driver is to replace the old
USB 2.0 PHY driver.


Pls fix this error too..

Applying: phy: Add Exynos 5250 support to the Exynos USB 2.0 PHY driver
/home/kishon/repos/linux-phy/.git/rebase-apply/patch:462: new blank line 
at EOF.

+
warning: 1 line adds whitespace errors.

Thanks
Kishon


Signed-off-by: Kamil Debski 
---
  .../devicetree/bindings/phy/samsung-phy.txt|1 +
  drivers/phy/Kconfig|   11 +
  drivers/phy/Makefile   |1 +
  drivers/phy/phy-exynos5250-usb2.c  |  405 
  drivers/phy/phy-samsung-usb2.c |6 +
  drivers/phy/phy-samsung-usb2.h |1 +
  6 files changed, 425 insertions(+)
  create mode 100644 drivers/phy/phy-exynos5250-usb2.c

diff --git a/Documentation/devicetree/bindings/phy/samsung-phy.txt 
b/Documentation/devicetree/bindings/phy/samsung-phy.txt
index bf955ab..28f9edb 100644
--- a/Documentation/devicetree/bindings/phy/samsung-phy.txt
+++ b/Documentation/devicetree/bindings/phy/samsung-phy.txt
@@ -28,6 +28,7 @@ Required properties:
  - compatible : should be one of the listed compatibles:
- "samsung,exynos4210-usb2-phy"
- "samsung,exynos4x12-usb2-phy"
+   - "samsung,exynos5250-usb2-phy"
  - reg : a list of registers used by phy driver
- first and obligatory is the location of phy modules registers
  - samsung,sysreg-phandle - handle to syscon used to control the system 
registers
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index fc5a44a..c206e25 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -125,4 +125,15 @@ config PHY_EXYNOS4X12_USB2
  Samsung USB 2.0 PHY driver is enabled and means that support for this
  particular SoC is compiled in the driver. In case of Exynos 4x12 four
  phys are available - device, host, HSIC0 and HSIC1.
+
+config PHY_EXYNOS5250_USB2
+   bool "Support for Exynos 5250"
+   depends on PHY_SAMSUNG_USB2
+   depends on SOC_EXYNOS5250
+   help
+ Enable USB PHY support for Exynos 5250. This option requires that
+ Samsung USB 2.0 PHY driver is enabled and means that support for this
+ particular SoC is compiled in the driver. In case of Exynos 5250 four
+ phys are available - device, host, HSIC0 and HSIC.
+
  endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 0ea36ff..f76c239 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_PHY_SUN4I_USB)   += phy-sun4i-usb.o
  obj-$(CONFIG_PHY_SAMSUNG_USB2)+= phy-samsung-usb2.o
  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
diff --git a/drivers/phy/phy-exynos5250-usb2.c 
b/drivers/phy/phy-exynos5250-usb2.c
new file mode 100644
index 000..877994e
--- /dev/null
+++ b/drivers/phy/phy-exynos5250-usb2.c
@@ -0,0 +1,405 @@
+/*
+ * Samsung SoC USB 1.1/2.0 PHY driver - Exynos 5250 support
+ *
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd.
+ * Author: Kamil Debski 
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include "phy-samsung-usb2.h"
+
+/* Exynos USB PHY registers */
+#define EXYNOS_5250_REFCLKSEL_CRYSTAL  0x0
+#define EXYNOS_5250_REFCLKSEL_XO   0x1
+#define EXYNOS_5250_REFCLKSEL_CLKCORE  0x2
+
+#define EXYNOS_5250_FSEL_9MHZ6 0x0
+#define EXYNOS_5250_FSEL_10MHZ 0x1
+#define EXYNOS_5250_FSEL_12MHZ 0x2
+#define EXYNOS_5250_FSEL_19MHZ20x3
+#define EXYNOS_5250_FSEL_20MHZ 0x4
+#define EXYNOS_5250_FSEL_24MHZ 0x5
+#define EXYNOS_5250_FSEL_50MHZ 0x7
+
+/* Normal host */
+#define EXYNOS_5250_HOSTPHYCTRL0   0x0
+
+#define EXYNOS_5250_HOSTPHYCTRL0_PHYSWRSTALL   BIT(31)
+#define EXYNOS_5250_HOSTPHYCTRL0_REFCLKSEL_SHIFT   19
+#define EXYNOS_5250_HOSTPHYCTRL0_REFCLKSEL_MASK\
+   (0x3 << EXYNOS_5250_HOSTPHYCTRL0_REFCLKSEL_SHIFT)
+#define EXYNOS_5250_HOSTPHYCTRL0_FSEL_SHIFT16
+#define EXYNOS_5250_HOSTPHYCTRL0_FSEL_MASK \
+   (0x7 << EXYNOS_5250_HOSTPHYCTRL0_FSEL_SHIFT)
+#define EXYNOS_5250_HOSTPHYCTRL0_TESTBURNINBIT(11)
+#define EXYNOS_5250_HOSTPHYCTRL0_RETENABLE BIT(10)
+#define EXYNOS_5250_HOSTPHYCTRL0_COMMON_ON_N   BIT(9)
+#define EXYNOS_5250_HOSTPHYCTRL0_VATESTENB_MASK(0x3 << 7)
+#define EXYNOS_5250_HOSTPHYCTRL0_VATESTENB_DUAL(0x0 << 7)
+#define EXYNOS_5250_HOSTPHYCTRL0_VATESTENB_ID0 (0x1 << 7)
+#define EXYNOS_5250_HOSTPHYCTRL0_VA

Re: [PATCH v5 2/6] usb: dwc3: adapt dwc3 core to use Generic PHY Framework

2014-03-05 Thread Roger Quadros
Hi Kishon,

On 03/03/2014 01:38 PM, Kishon Vijay Abraham I wrote:
> Adapted dwc3 core to use the Generic PHY Framework. So for init, exit,
> power_on and power_off the following APIs are used phy_init(), phy_exit(),
> phy_power_on() and phy_power_off().
> 
> However using the old USB phy library wont be removed till the PHYs of all
> other SoC's using dwc3 core is adapted to the Generic PHY Framework.
> 
> Signed-off-by: Kishon Vijay Abraham I 
> ---
>  Documentation/devicetree/bindings/usb/dwc3.txt |6 +-
>  drivers/usb/dwc3/core.c|   86 
> +---
>  drivers/usb/dwc3/core.h|7 ++
>  3 files changed, 89 insertions(+), 10 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt 
> b/Documentation/devicetree/bindings/usb/dwc3.txt
> index e807635..471366d 100644
> --- a/Documentation/devicetree/bindings/usb/dwc3.txt
> +++ b/Documentation/devicetree/bindings/usb/dwc3.txt
> @@ -6,11 +6,13 @@ Required properties:
>   - compatible: must be "snps,dwc3"
>   - reg : Address and length of the register set for the device
>   - interrupts: Interrupts used by the dwc3 controller.
> +
> +Optional properties:
>   - usb-phy : array of phandle for the PHY device.  The first element
> in the array is expected to be a handle to the USB2/HS PHY and
> the second element is expected to be a handle to the USB3/SS PHY
> -
> -Optional properties:
> + - phys: from the *Generic PHY* bindings
> + - phy-names: from the *Generic PHY* bindings
>   - tx-fifo-resize: determines if the FIFO *has* to be reallocated.
>  
>  This is usually a subnode to DWC3 glue to which it is connected.
> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> index 225a4d6..497234a 100644
> --- a/drivers/usb/dwc3/core.c
> +++ b/drivers/usb/dwc3/core.c
> @@ -61,9 +61,10 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
>   * dwc3_core_soft_reset - Issues core soft reset and PHY reset
>   * @dwc: pointer to our context structure
>   */
> -static void dwc3_core_soft_reset(struct dwc3 *dwc)
> +static int dwc3_core_soft_reset(struct dwc3 *dwc)
>  {
>   u32 reg;
> + int ret;
>  
>   /* Before Resetting PHY, put Core in Reset */
>   reg = dwc3_readl(dwc->regs, DWC3_GCTL);
> @@ -82,6 +83,15 @@ static void dwc3_core_soft_reset(struct dwc3 *dwc)
>  
>   usb_phy_init(dwc->usb2_phy);
>   usb_phy_init(dwc->usb3_phy);
> + ret = phy_init(dwc->usb2_generic_phy);

you need to check if dwc->usb?_generic_phy is not NULL before using any of the 
PHY APIs
throughout this patch.

> + if (ret < 0)
> + return ret;
> +
> + ret = phy_init(dwc->usb3_generic_phy);
> + if (ret < 0) {
> + phy_exit(dwc->usb2_generic_phy);
> + return ret;
> + }
>   mdelay(100);
>  
>   /* Clear USB3 PHY reset */
> @@ -100,6 +110,8 @@ static void dwc3_core_soft_reset(struct dwc3 *dwc)
>   reg = dwc3_readl(dwc->regs, DWC3_GCTL);
>   reg &= ~DWC3_GCTL_CORESOFTRESET;
>   dwc3_writel(dwc->regs, DWC3_GCTL, reg);
> +
> + return 0;
>  }
>  

cheers,
-roger

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 2/6] usb: dwc3: adapt dwc3 core to use Generic PHY Framework

2014-03-05 Thread Kishon Vijay Abraham I

Roger,

On Wednesday 05 March 2014 08:13 PM, Roger Quadros wrote:

Hi Kishon,

On 03/03/2014 01:38 PM, Kishon Vijay Abraham I wrote:

Adapted dwc3 core to use the Generic PHY Framework. So for init, exit,
power_on and power_off the following APIs are used phy_init(), phy_exit(),
phy_power_on() and phy_power_off().

However using the old USB phy library wont be removed till the PHYs of all
other SoC's using dwc3 core is adapted to the Generic PHY Framework.

Signed-off-by: Kishon Vijay Abraham I 
---
  Documentation/devicetree/bindings/usb/dwc3.txt |6 +-
  drivers/usb/dwc3/core.c|   86 +---
  drivers/usb/dwc3/core.h|7 ++
  3 files changed, 89 insertions(+), 10 deletions(-)

diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt 
b/Documentation/devicetree/bindings/usb/dwc3.txt
index e807635..471366d 100644
--- a/Documentation/devicetree/bindings/usb/dwc3.txt
+++ b/Documentation/devicetree/bindings/usb/dwc3.txt
@@ -6,11 +6,13 @@ Required properties:
   - compatible: must be "snps,dwc3"
   - reg : Address and length of the register set for the device
   - interrupts: Interrupts used by the dwc3 controller.
+
+Optional properties:
   - usb-phy : array of phandle for the PHY device.  The first element
 in the array is expected to be a handle to the USB2/HS PHY and
 the second element is expected to be a handle to the USB3/SS PHY
-
-Optional properties:
+ - phys: from the *Generic PHY* bindings
+ - phy-names: from the *Generic PHY* bindings
   - tx-fifo-resize: determines if the FIFO *has* to be reallocated.

  This is usually a subnode to DWC3 glue to which it is connected.
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 225a4d6..497234a 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -61,9 +61,10 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
   * dwc3_core_soft_reset - Issues core soft reset and PHY reset
   * @dwc: pointer to our context structure
   */
-static void dwc3_core_soft_reset(struct dwc3 *dwc)
+static int dwc3_core_soft_reset(struct dwc3 *dwc)
  {
u32 reg;
+   int ret;

/* Before Resetting PHY, put Core in Reset */
reg = dwc3_readl(dwc->regs, DWC3_GCTL);
@@ -82,6 +83,15 @@ static void dwc3_core_soft_reset(struct dwc3 *dwc)

usb_phy_init(dwc->usb2_phy);
usb_phy_init(dwc->usb3_phy);
+   ret = phy_init(dwc->usb2_generic_phy);


you need to check if dwc->usb?_generic_phy is not NULL before using any of the 
PHY APIs
throughout this patch.


Recently a patch to allow NULL in phy APIs was added to support optional 
PHYs.


commit 04c2facad8fee66c981a51852806d8923336f362
Author: Andrew Lunn 
Date:   Tue Feb 4 18:33:11 2014 +0100

drivers: phy: Make NULL a valid phy reference

Thanks
Kishon
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: BUG: USB Reset-Resume Mechanism does not work for runtime resume

2014-03-05 Thread Oliver Neukum
On Wed, 2014-03-05 at 09:40 +, Poulain, Loic wrote:
> Hi,
> 
> I think there is an issue with the reset-resume mechanism during USB
> runtime resume, leaving the interfaces suspended forever.
> 
> - Context:
> 
> Android platform, running a 3.13 + Google AOSP patches kernel.
> I'm facing a USB issue with the bsusb driver. btusb driver has the USB
> runtime suspend enabled + remote wakeup.
> However sometimes the USB runtime resume does not work as expected (we
> admit here that this can happen).
> 
> [ 3066.408413] usb 2-3: usb auto-resume
> [ 3066.408433] hub 2-0:1.0: state 7 ports 9 chg  evt 0008
> [ 3066.445465] usb 2-3: finish resume
> [ 3071.447591] usb 2-3: bt_hc_worker timed out on ep0in len=0/2
> [ 3071.447598] usb 2-3: retry with reset-resume
> 
> Then the usbcore tries a reset-resume, but btusb driver does not
> implement this callback.

This is extremely tricky, almost academical a question.
We cannot fall back to reset_resume() in this case without
very bad consequences.
If remote wakeup is needed, reset_resume() must not be used.
It seems to me that the bug in this case is the fallback itself.
>From a design viewpoint is probably wrong the unbind a device
in the runtime case. We'd better notify the driver in every case.
If you unbind and rebind you just risk getting into a tight loop.

Regards
Oliver


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v2] usb: gadget: return the right length in ffs_epfile_io()

2014-03-05 Thread Felipe Balbi
On Tue, Mar 04, 2014 at 11:38:32PM +, Liu, Chuansheng wrote:
> Hi Balbi,
> 
> > -Original Message-
> > From: Felipe Balbi [mailto:ba...@ti.com]
> > Sent: Wednesday, March 05, 2014 3:56 AM
> > To: Michal Nazarewicz
> > Cc: Robert Baldyga; Felipe Balbi; Sergei Shtylyov; Liu, Chuansheng;
> > gre...@linuxfoundation.org; linux-usb@vger.kernel.org;
> > linux-ker...@vger.kernel.org; david.a.co...@linux.intel.com
> > Subject: Re: [PATCH v2] usb: gadget: return the right length in 
> > ffs_epfile_io()
> > 
> > On Tue, Mar 04, 2014 at 08:53:40PM +0100, Michal Nazarewicz wrote:
> > > >> On 03/04/2014 10:34 AM, Chuansheng Liu wrote:
> > > >> >@@ -845,12 +845,14 @@ static ssize_t ffs_epfile_io(struct file *file,
> > struct ffs_io_data *io_data)
> > > >> >   * we may end up with more data then user space 
> > > >> > has
> > > >> >   * space for.
> > > >> >   */
> > > >> >- ret = ep->status;
> > > >> >- if (io_data->read && ret > 0 &&
> > > >> >- unlikely(copy_to_user(io_data->buf, data,
> > > >> >-   min_t(size_t, ret,
> > > >> >-   io_data->len
> > > >> >- ret = -EFAULT;
> > > >> >+ ret = ep->status;
> > >
> > > On Tue, Mar 04 2014, Felipe Balbi wrote:
> > > >>Why the indentation jumped suddenly to the right?
> > >
> > > > On Tue, Mar 04, 2014 at 08:01:15PM +0300, Sergei Shtylyov wrote:
> > > > because it was wrong before ;-)
> > >
> > > Yep.  It looks like Robert's [2e4c7553: add aio support] introduced an
> > > if-else-if-else flow but did not indent the code and I didn't caught it
> > > when reviewing that patch.
> > 
> > it's in my testing/next now, I also fixed the comment indentation which
> > was also wrong.
> Thanks your help and the fix for comment indentation also:)

no problem, cheers ;-)

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH v5 2/6] usb: dwc3: adapt dwc3 core to use Generic PHY Framework

2014-03-05 Thread Roger Quadros
On 03/05/2014 04:47 PM, Kishon Vijay Abraham I wrote:
> Roger,
> 
> On Wednesday 05 March 2014 08:13 PM, Roger Quadros wrote:
>> Hi Kishon,
>>
>> On 03/03/2014 01:38 PM, Kishon Vijay Abraham I wrote:
>>> Adapted dwc3 core to use the Generic PHY Framework. So for init, exit,
>>> power_on and power_off the following APIs are used phy_init(), phy_exit(),
>>> phy_power_on() and phy_power_off().
>>>
>>> However using the old USB phy library wont be removed till the PHYs of all
>>> other SoC's using dwc3 core is adapted to the Generic PHY Framework.
>>>
>>> Signed-off-by: Kishon Vijay Abraham I 
>>> ---
>>>   Documentation/devicetree/bindings/usb/dwc3.txt |6 +-
>>>   drivers/usb/dwc3/core.c|   86 
>>> +---
>>>   drivers/usb/dwc3/core.h|7 ++
>>>   3 files changed, 89 insertions(+), 10 deletions(-)
>>>
>>> diff --git a/Documentation/devicetree/bindings/usb/dwc3.txt 
>>> b/Documentation/devicetree/bindings/usb/dwc3.txt
>>> index e807635..471366d 100644
>>> --- a/Documentation/devicetree/bindings/usb/dwc3.txt
>>> +++ b/Documentation/devicetree/bindings/usb/dwc3.txt
>>> @@ -6,11 +6,13 @@ Required properties:
>>>- compatible: must be "snps,dwc3"
>>>- reg : Address and length of the register set for the device
>>>- interrupts: Interrupts used by the dwc3 controller.
>>> +
>>> +Optional properties:
>>>- usb-phy : array of phandle for the PHY device.  The first element
>>>  in the array is expected to be a handle to the USB2/HS PHY and
>>>  the second element is expected to be a handle to the USB3/SS PHY
>>> -
>>> -Optional properties:
>>> + - phys: from the *Generic PHY* bindings
>>> + - phy-names: from the *Generic PHY* bindings
>>>- tx-fifo-resize: determines if the FIFO *has* to be reallocated.
>>>
>>>   This is usually a subnode to DWC3 glue to which it is connected.
>>> diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
>>> index 225a4d6..497234a 100644
>>> --- a/drivers/usb/dwc3/core.c
>>> +++ b/drivers/usb/dwc3/core.c
>>> @@ -61,9 +61,10 @@ void dwc3_set_mode(struct dwc3 *dwc, u32 mode)
>>>* dwc3_core_soft_reset - Issues core soft reset and PHY reset
>>>* @dwc: pointer to our context structure
>>>*/
>>> -static void dwc3_core_soft_reset(struct dwc3 *dwc)
>>> +static int dwc3_core_soft_reset(struct dwc3 *dwc)
>>>   {
>>>   u32reg;
>>> +intret;
>>>
>>>   /* Before Resetting PHY, put Core in Reset */
>>>   reg = dwc3_readl(dwc->regs, DWC3_GCTL);
>>> @@ -82,6 +83,15 @@ static void dwc3_core_soft_reset(struct dwc3 *dwc)
>>>
>>>   usb_phy_init(dwc->usb2_phy);
>>>   usb_phy_init(dwc->usb3_phy);
>>> +ret = phy_init(dwc->usb2_generic_phy);
>>
>> you need to check if dwc->usb?_generic_phy is not NULL before using any of 
>> the PHY APIs
>> throughout this patch.
> 
> Recently a patch to allow NULL in phy APIs was added to support optional PHYs.
> 
> commit 04c2facad8fee66c981a51852806d8923336f362
> Author: Andrew Lunn 
> Date:   Tue Feb 4 18:33:11 2014 +0100
> 
> drivers: phy: Make NULL a valid phy reference

Oh OK, then it is fine. Thanks for the clarification.

cheers,
-roger
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v9 1/4] phy: core: Add an exported of_phy_get function

2014-03-05 Thread Kamil Debski
Previously the of_phy_get function took a struct device * and
was declared static. It was impossible to call it from
another driver and thus it was impossible to get phy defined
for a given node. The old function was renamed to _of_phy_get
and was left for internal use. of_phy_get function was added
and it was exported. The function enables to get a phy for
a given device tree node.

Signed-off-by: Kamil Debski 
---
 drivers/phy/phy-core.c  |   45 -
 include/linux/phy/phy.h |6 ++
 2 files changed, 42 insertions(+), 9 deletions(-)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 6c73837..7c1b0e1 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -274,8 +274,8 @@ int phy_power_off(struct phy *phy)
 EXPORT_SYMBOL_GPL(phy_power_off);
 
 /**
- * of_phy_get() - lookup and obtain a reference to a phy by phandle
- * @dev: device that requests this phy
+ * _of_phy_get() - lookup and obtain a reference to a phy by phandle
+ * @np: device_node for which to get the phy
  * @index: the index of the phy
  *
  * Returns the phy associated with the given phandle value,
@@ -284,20 +284,17 @@ EXPORT_SYMBOL_GPL(phy_power_off);
  * not yet loaded. This function uses of_xlate call back function provided
  * while registering the phy_provider to find the phy instance.
  */
-static struct phy *of_phy_get(struct device *dev, int index)
+static struct phy *_of_phy_get(struct device_node *np, int index)
 {
int ret;
struct phy_provider *phy_provider;
struct phy *phy = NULL;
struct of_phandle_args args;
 
-   ret = of_parse_phandle_with_args(dev->of_node, "phys", "#phy-cells",
+   ret = of_parse_phandle_with_args(np, "phys", "#phy-cells",
index, &args);
-   if (ret) {
-   dev_dbg(dev, "failed to get phy in %s node\n",
-   dev->of_node->full_name);
+   if (ret)
return ERR_PTR(-ENODEV);
-   }
 
mutex_lock(&phy_provider_mutex);
phy_provider = of_phy_provider_lookup(args.np);
@@ -317,6 +314,36 @@ err0:
 }
 
 /**
+ * of_phy_get() - lookup and obtain a reference to a phy using a device_node.
+ * @np: device_node for which to get the phy
+ * @con_id: name of the phy from device's point of view
+ *
+ * Returns the phy driver, after getting a refcount to it; or
+ * -ENODEV if there is no such phy. The caller is responsible for
+ * calling phy_put() to release that count.
+ */
+struct phy *of_phy_get(struct device_node *np, const char *con_id)
+{
+   struct phy *phy = NULL;
+   int index = 0;
+
+   if (con_id)
+   index = of_property_match_string(np, "phy-names", con_id);
+
+   phy = _of_phy_get(np, index);
+   if (IS_ERR(phy))
+   return phy;
+
+   if (!try_module_get(phy->ops->owner))
+   return ERR_PTR(-EPROBE_DEFER);
+
+   get_device(&phy->dev);
+
+   return phy;
+}
+EXPORT_SYMBOL_GPL(of_phy_get);
+
+/**
  * phy_put() - release the PHY
  * @phy: the phy returned by phy_get()
  *
@@ -407,7 +434,7 @@ struct phy *phy_get(struct device *dev, const char *string)
if (dev->of_node) {
index = of_property_match_string(dev->of_node, "phy-names",
string);
-   phy = of_phy_get(dev, index);
+   phy = _of_phy_get(dev->of_node, index);
} else {
phy = phy_lookup(dev, string);
}
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index 3f83459..2fe3194 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -151,6 +151,7 @@ struct phy *devm_phy_get(struct device *dev, const char 
*string);
 struct phy *devm_phy_optional_get(struct device *dev, const char *string);
 void phy_put(struct phy *phy);
 void devm_phy_put(struct device *dev, struct phy *phy);
+struct phy *of_phy_get(struct device_node *np, const char *con_id);
 struct phy *of_phy_simple_xlate(struct device *dev,
struct of_phandle_args *args);
 struct phy *phy_create(struct device *dev, const struct phy_ops *ops,
@@ -259,6 +260,11 @@ static inline void devm_phy_put(struct device *dev, struct 
phy *phy)
 {
 }
 
+struct phy *of_phy_get(struct device_node *np, const char *con_id)
+{
+   return ERR_PTR(-ENOSYS);
+}
+
 static inline struct phy *of_phy_simple_xlate(struct device *dev,
struct of_phandle_args *args)
 {
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCH v9 4/4] phy: Add Exynos 5250 support to the Exynos USB 2.0 PHY driver

2014-03-05 Thread Kamil Debski
Add support for Exynos 5250. This driver is to replace the old
USB 2.0 PHY driver.

Signed-off-by: Kamil Debski 
---
 .../devicetree/bindings/phy/samsung-phy.txt|1 +
 drivers/phy/Kconfig|   11 +
 drivers/phy/Makefile   |1 +
 drivers/phy/phy-exynos5250-usb2.c  |  404 
 drivers/phy/phy-samsung-usb2.c |6 +
 drivers/phy/phy-samsung-usb2.h |1 +
 6 files changed, 424 insertions(+)
 create mode 100644 drivers/phy/phy-exynos5250-usb2.c

diff --git a/Documentation/devicetree/bindings/phy/samsung-phy.txt 
b/Documentation/devicetree/bindings/phy/samsung-phy.txt
index bf955ab..28f9edb 100644
--- a/Documentation/devicetree/bindings/phy/samsung-phy.txt
+++ b/Documentation/devicetree/bindings/phy/samsung-phy.txt
@@ -28,6 +28,7 @@ Required properties:
 - compatible : should be one of the listed compatibles:
- "samsung,exynos4210-usb2-phy"
- "samsung,exynos4x12-usb2-phy"
+   - "samsung,exynos5250-usb2-phy"
 - reg : a list of registers used by phy driver
- first and obligatory is the location of phy modules registers
 - samsung,sysreg-phandle - handle to syscon used to control the system 
registers
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index fc5a44a..c206e25 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -125,4 +125,15 @@ config PHY_EXYNOS4X12_USB2
  Samsung USB 2.0 PHY driver is enabled and means that support for this
  particular SoC is compiled in the driver. In case of Exynos 4x12 four
  phys are available - device, host, HSIC0 and HSIC1.
+
+config PHY_EXYNOS5250_USB2
+   bool "Support for Exynos 5250"
+   depends on PHY_SAMSUNG_USB2
+   depends on SOC_EXYNOS5250
+   help
+ Enable USB PHY support for Exynos 5250. This option requires that
+ Samsung USB 2.0 PHY driver is enabled and means that support for this
+ particular SoC is compiled in the driver. In case of Exynos 5250 four
+ phys are available - device, host, HSIC0 and HSIC.
+
 endmenu
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index 0ea36ff..f76c239 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -14,3 +14,4 @@ obj-$(CONFIG_PHY_SUN4I_USB)   += phy-sun4i-usb.o
 obj-$(CONFIG_PHY_SAMSUNG_USB2) += phy-samsung-usb2.o
 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
diff --git a/drivers/phy/phy-exynos5250-usb2.c 
b/drivers/phy/phy-exynos5250-usb2.c
new file mode 100644
index 000..94179af
--- /dev/null
+++ b/drivers/phy/phy-exynos5250-usb2.c
@@ -0,0 +1,404 @@
+/*
+ * Samsung SoC USB 1.1/2.0 PHY driver - Exynos 5250 support
+ *
+ * Copyright (C) 2013 Samsung Electronics Co., Ltd.
+ * Author: Kamil Debski 
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include "phy-samsung-usb2.h"
+
+/* Exynos USB PHY registers */
+#define EXYNOS_5250_REFCLKSEL_CRYSTAL  0x0
+#define EXYNOS_5250_REFCLKSEL_XO   0x1
+#define EXYNOS_5250_REFCLKSEL_CLKCORE  0x2
+
+#define EXYNOS_5250_FSEL_9MHZ6 0x0
+#define EXYNOS_5250_FSEL_10MHZ 0x1
+#define EXYNOS_5250_FSEL_12MHZ 0x2
+#define EXYNOS_5250_FSEL_19MHZ20x3
+#define EXYNOS_5250_FSEL_20MHZ 0x4
+#define EXYNOS_5250_FSEL_24MHZ 0x5
+#define EXYNOS_5250_FSEL_50MHZ 0x7
+
+/* Normal host */
+#define EXYNOS_5250_HOSTPHYCTRL0   0x0
+
+#define EXYNOS_5250_HOSTPHYCTRL0_PHYSWRSTALL   BIT(31)
+#define EXYNOS_5250_HOSTPHYCTRL0_REFCLKSEL_SHIFT   19
+#define EXYNOS_5250_HOSTPHYCTRL0_REFCLKSEL_MASK\
+   (0x3 << EXYNOS_5250_HOSTPHYCTRL0_REFCLKSEL_SHIFT)
+#define EXYNOS_5250_HOSTPHYCTRL0_FSEL_SHIFT16
+#define EXYNOS_5250_HOSTPHYCTRL0_FSEL_MASK \
+   (0x7 << EXYNOS_5250_HOSTPHYCTRL0_FSEL_SHIFT)
+#define EXYNOS_5250_HOSTPHYCTRL0_TESTBURNINBIT(11)
+#define EXYNOS_5250_HOSTPHYCTRL0_RETENABLE BIT(10)
+#define EXYNOS_5250_HOSTPHYCTRL0_COMMON_ON_N   BIT(9)
+#define EXYNOS_5250_HOSTPHYCTRL0_VATESTENB_MASK(0x3 << 7)
+#define EXYNOS_5250_HOSTPHYCTRL0_VATESTENB_DUAL(0x0 << 7)
+#define EXYNOS_5250_HOSTPHYCTRL0_VATESTENB_ID0 (0x1 << 7)
+#define EXYNOS_5250_HOSTPHYCTRL0_VATESTENB_ANALOGTEST  (0x2 << 7)
+#define EXYNOS_5250_HOSTPHYCTRL0_SIDDQ BIT(6)
+#define EXYNOS_5250_HOSTPHYCTRL0_FORCESLEEPBIT(5)
+#define EXYNOS_5250_HOSTPHYCTRL0_FORCESUSPEND  BIT(4)
+#define EXYNOS_5250_HOSTPHYCTRL0_WORDINTERFACE BIT(3)
+#define EXYNOS_5250_HOSTPHYCTRL0_UTMISWRS

[PATCH v9 0/4] phy: Add new Exynos USB 2.0 PHY driver

2014-03-05 Thread Kamil Debski
Hi,

This is the ninth version of this patchset. First and most significant change
since v6 is that this patchset includes only patches touching the Generic PHY
Framework. Patches to the USB controllers were stripped as they require
additional work. S5PV210 support is also omitted - it requires more testing.

Since v7 this patch includes fixes for checkpath errors and was rebased onto
Kishon's next branch. v9 brings whitespace corrections compared to v8.

Best wishes,
Kamil Debski

--
Changes from v8:
1) phy: core: Add an exported of_phy_get function
   - No changes since v8.
2) phy: core: Add devm_of_phy_get to phy-core
   - No changes since v8.
3) phy: Add new Exynos USB 2.0 PHY driver
   - Fix empty blank line at EOF errors
4) phy: Add Exynos 5250 support to the Exynos USB 2.0 PHY
   - Fix empty blank line at EOF error

--
Changes from v7:
1) phy: core: Add an exported of_phy_get function
   - No changes since v7.
2) phy: core: Add devm_of_phy_get to phy-core
   - No changes since v7.
3) phy: Add new Exynos USB 2.0 PHY driver
   - Fix checkpatch errors with code indentation and corrected whitespace.
4) phy: Add Exynos 5250 support to the Exynos USB 2.0 PHY
   - Fix checkpatch errors with code indentation and corrected whitespace.

--
Changes from v6: (not including the change that controller patches were removed
form this patchset, also this patchset excludes S5PV210 support - it needs more
testing)
1) phy: core: Add an exported of_phy_get function
   - No changes since v6.
2) phy: core: Add devm_of_phy_get to phy-core
   - No changes since v6.
3) phy: Add new Exynos USB 2.0 PHY driver
   - Changed the way clocks are supplied to the driver. Prior to version v7
 there were reference clocks for every phy instance, now a single "ref"
 clock was introduced.
   - Updated documentation to match the aforementioned change.
   - Add offset EXYNOS_*_UPHYCLK_PHYFSEL_OFFSET to the clock register content
 defines.
   - Corrected way clock register is modified. Instead of a simple write, a
 proper read, modify, write sequence was introduced.
   - Important stability fix - added udelay after PHY reset. This fixes a bug
 causing instability in USB LAN adapters. Without the delay the DMA burst
 mode was could not be enabled.
4) phy: Add Exynos 5250 support to the Exynos USB 2.0 PHY
   - Changed handling of clocks to use a single "ref" clock.


Changes from v5:
1) phy: core: Add an exported of_phy_get function
- corrected behaviour of the modification when GENERIC_PHY is not enabled
  by adding a stub of the of_phy_get function
2) phy: core: Add devm_of_phy_get to phy-core
- corrected behaviour of the modification when GENERIC_PHY is not enabled
  by adding a stub of the devm_of_phy_get function
3) dts: Add usb2phy to Exynos 4
- no change
4) dts: Add usb2phy to Exynos 5250
- in the previous version, this patch included some phy-exynos5250-usb2.c code
  by mistake, the code has been remove and added to the proper patch
5) phy: Add new Exynos USB PHY driver
- changed strings from Exynos 4212 to Exynos 4x12, as the Exynos 4212 driver is
  actually a driver for the whole Exynos 4x12 family
- added documentation to the Exynos USB 2.0 PHY driver adaptaion layer
- corrected strings HSCI -> HSIC
- fixed a problem introduced by previous change - on Exynos 4x12 the HSIC did
  not work on its own
- mode switch support was added to Exynos 4x12 (same io pins are used by host
  and device)
- support for phy_set_bus_width introduced by Matt Porter was added
6) phy: Add support for S5PV210 to the Exynos USB PHY
- setting of clk register was fixed
7) phy: Add Exynos 5250 support to the Exynos USB 2.0 PHY
- supoprt was added for HSIC and device
8) usb: ehci-exynos: Change to use phy provided by the generic phy framework
- DT documentation was moved from usb-ehci.txt to exynos-usb.txt


Changes from v4:
1) phy: core: Add an exported of_phy_get function
- the new exported function of_phy_get was changed to take the phy's name as a
  parameter instead of the index
2) phy: core: Add devm_of_phy_get to phy-core
- fixes made in the comments to devm_of_phy_get
3) phy: Add new Exynos USB PHY driver
- move the documentation from a new to an existing file - samsung-phy.txt
- fix typos and uppercase hex addresses
- add more explanations to Kconfig (checkpatch still complains, but I find it
  hard to think what else could I add)
- add selects MFD_SYSCON as the driver needs it (Thank you, Tobias!)
- cleanup included headers in both *.c and .h files
- use BIT(x) macro instead of (1 << x)
- replaced HOST and DEV with PHY0 and PHY1 in phy-exynos4212-usb2.c, the
  registers are described as PHYx in the documentation hence the decision to
  leave the PHYx naming
- fixed typo in exynos4210_rate_to_clk reg -> *reg
- change hax_mode_switch and enabled type to bool
4) usb: ehci-s5p: Change to use phy provided by the generic phy framework
- Put the issue of phy->otg in o

[PATCH v9 3/4] phy: Add new Exynos USB 2.0 PHY driver

2014-03-05 Thread Kamil Debski
Add a new driver for the Exynos USB 2.0 PHY. The new driver uses the generic
PHY framework. The driver includes support for the Exynos 4x10 and 4x12
SoC families.

Signed-off-by: Kamil Debski 
---
 .../devicetree/bindings/phy/samsung-phy.txt|   53 
 Documentation/phy/samsung-usb2.txt |  134 
 drivers/phy/Kconfig|   29 ++
 drivers/phy/Makefile   |3 +
 drivers/phy/phy-exynos4210-usb2.c  |  261 
 drivers/phy/phy-exynos4x12-usb2.c  |  328 
 drivers/phy/phy-samsung-usb2.c |  222 +
 drivers/phy/phy-samsung-usb2.h |   66 
 8 files changed, 1096 insertions(+)
 create mode 100644 Documentation/phy/samsung-usb2.txt
 create mode 100644 drivers/phy/phy-exynos4210-usb2.c
 create mode 100644 drivers/phy/phy-exynos4x12-usb2.c
 create mode 100644 drivers/phy/phy-samsung-usb2.c
 create mode 100644 drivers/phy/phy-samsung-usb2.h

diff --git a/Documentation/devicetree/bindings/phy/samsung-phy.txt 
b/Documentation/devicetree/bindings/phy/samsung-phy.txt
index c0fccaa..bf955ab 100644
--- a/Documentation/devicetree/bindings/phy/samsung-phy.txt
+++ b/Documentation/devicetree/bindings/phy/samsung-phy.txt
@@ -20,3 +20,56 @@ Required properties:
 - compatible : should be "samsung,exynos5250-dp-video-phy";
 - reg : offset and length of the Display Port PHY register set;
 - #phy-cells : from the generic PHY bindings, must be 0;
+
+Samsung S5P/EXYNOS SoC series USB PHY
+-
+
+Required properties:
+- compatible : should be one of the listed compatibles:
+   - "samsung,exynos4210-usb2-phy"
+   - "samsung,exynos4x12-usb2-phy"
+- reg : a list of registers used by phy driver
+   - first and obligatory is the location of phy modules registers
+- samsung,sysreg-phandle - handle to syscon used to control the system 
registers
+- samsung,pmureg-phandle - handle to syscon used to control PMU registers
+- #phy-cells : from the generic phy bindings, must be 1;
+- clocks and clock-names:
+   - the "phy" clock is required by the phy module, used as a gate
+   - the "ref" clock is used to get the rate of the clock provided to the
+ PHY module
+
+The first phandle argument in the PHY specifier identifies the PHY, its
+meaning is compatible dependent. For the currently supported SoCs (Exynos 4210
+and Exynos 4212) it is as follows:
+  0 - USB device ("device"),
+  1 - USB host ("host"),
+  2 - HSIC0 ("hsic0"),
+  3 - HSIC1 ("hsic1"),
+
+Exynos 4210 and Exynos 4212 use mode switching and require that mode switch
+register is supplied.
+
+Example:
+
+For Exynos 4412 (compatible with Exynos 4212):
+
+usbphy: phy@125b {
+   compatible = "samsung,exynos4x12-usb2-phy";
+   reg = <0x125b 0x100>;
+   clocks = <&clock 305>, <&clock 2>;
+   clock-names = "phy", "ref";
+   status = "okay";
+   #phy-cells = <1>;
+   samsung,sysreg-phandle = <&sys_reg>;
+   samsung,pmureg-phandle = <&pmu_reg>;
+};
+
+Then the PHY can be used in other nodes such as:
+
+phy-consumer@1234 {
+   phys = <&usbphy 2>;
+   phy-names = "phy";
+};
+
+Refer to DT bindings documentation of particular PHY consumer devices for more
+information about required PHYs and the way of specification.
diff --git a/Documentation/phy/samsung-usb2.txt 
b/Documentation/phy/samsung-usb2.txt
new file mode 100644
index 000..0c8e260
--- /dev/null
+++ b/Documentation/phy/samsung-usb2.txt
@@ -0,0 +1,134 @@
+.--+
+|  Samsung USB 2.0 PHY adaptation layer   |
++-+'
+
+| 1. Description
++
+
+The architecture of the USB 2.0 PHY module in Samsung SoCs is similar
+among many SoCs. In spite of the similarities it proved difficult to
+create a one driver that would fit all these PHY controllers. Often
+the differences were minor and were found in particular bits of the
+registers of the PHY. In some rare cases the order of register writes or
+the PHY powering up process had to be altered. This adaptation layer is
+a compromise between having separate drivers and having a single driver
+with added support for many special cases.
+
+| 2. Files description
++--
+
+- phy-samsung-usb2.c
+   This is the main file of the adaptation layer. This file contains
+   the probe function and provides two callbacks to the Generic PHY
+   Framework. This two callbacks are used to power on and power off the
+   phy. They carry out the common work that has to be done on all version
+   of the PHY module. Depending on which SoC was chosen they execute SoC
+   specific callbacks. The specific SoC version is selected by choosing
+   the appropriate compatible string. In addi

[PATCH v9 2/4] phy: core: Add devm_of_phy_get to phy-core

2014-03-05 Thread Kamil Debski
Adding devm_of_phy_get will allow to get phys by supplying a
pointer to the struct device_node instead of struct device.

Signed-off-by: Kamil Debski 
---
 drivers/phy/phy-core.c  |   31 +++
 include/linux/phy/phy.h |8 
 2 files changed, 39 insertions(+)

diff --git a/drivers/phy/phy-core.c b/drivers/phy/phy-core.c
index 7c1b0e1..623b71c 100644
--- a/drivers/phy/phy-core.c
+++ b/drivers/phy/phy-core.c
@@ -526,6 +526,37 @@ struct phy *devm_phy_optional_get(struct device *dev, 
const char *string)
 EXPORT_SYMBOL_GPL(devm_phy_optional_get);
 
 /**
+ * devm_of_phy_get() - lookup and obtain a reference to a phy.
+ * @dev: device that requests this phy
+ * @np: node containing the phy
+ * @con_id: name of the phy from device's point of view
+ *
+ * Gets the phy using of_phy_get(), and associates a device with it using
+ * devres. On driver detach, release function is invoked on the devres data,
+ * then, devres data is freed.
+ */
+struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
+   const char *con_id)
+{
+   struct phy **ptr, *phy;
+
+   ptr = devres_alloc(devm_phy_release, sizeof(*ptr), GFP_KERNEL);
+   if (!ptr)
+   return ERR_PTR(-ENOMEM);
+
+   phy = of_phy_get(np, con_id);
+   if (!IS_ERR(phy)) {
+   *ptr = phy;
+   devres_add(dev, ptr);
+   } else {
+   devres_free(ptr);
+   }
+
+   return phy;
+}
+EXPORT_SYMBOL_GPL(devm_of_phy_get);
+
+/**
  * phy_create() - create a new phy
  * @dev: device that is creating the new phy
  * @ops: function pointers for performing phy operations
diff --git a/include/linux/phy/phy.h b/include/linux/phy/phy.h
index 2fe3194..bcbf96c 100644
--- a/include/linux/phy/phy.h
+++ b/include/linux/phy/phy.h
@@ -149,6 +149,8 @@ struct phy *phy_get(struct device *dev, const char *string);
 struct phy *phy_optional_get(struct device *dev, const char *string);
 struct phy *devm_phy_get(struct device *dev, const char *string);
 struct phy *devm_phy_optional_get(struct device *dev, const char *string);
+struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
+   const char *con_id);
 void phy_put(struct phy *phy);
 void devm_phy_put(struct device *dev, struct phy *phy);
 struct phy *of_phy_get(struct device_node *np, const char *con_id);
@@ -252,6 +254,12 @@ static inline struct phy *devm_phy_optional_get(struct 
device *dev,
return ERR_PTR(-ENOSYS);
 }
 
+struct phy *devm_of_phy_get(struct device *dev, struct device_node *np,
+   const char *con_id)
+{
+   return ERR_PTR(-ENOSYS);
+}
+
 static inline void phy_put(struct phy *phy)
 {
 }
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCHv3] usb: dwc2: Add function to calculate correct FIFO sizes

2014-03-05 Thread Felipe Balbi
Hi,

On Wed, Mar 05, 2014 at 12:08:08AM -0600, dingu...@altera.com wrote:
> From: Dinh Nguyen 
> 
> The dwc2 IP on the SOCFPGA cannot use the default HW configured
> FIFO sizes. The total FIFO depth as read from GHWCFG3 reports 0x1f80 or 8064
> 32-bit words. But the GRXFSIZ, GNPTXFSIZ, and HPTXFSIZ register defaults
> to 0x2000 or 8192 32-bit words. So the driver cannot just use the fifo sizes
> as read from those registers.
> 
> For platforms that face the same issue, this commits sets the RX, periodic TX,
> and non-periodic TX fifo size to those that are recommended v2.93a spec for
> the DWC2 IP. Implements Method #2 from the Synopsys v2.93a spec for the DWC2.
> 
> Signed-off-by: Dinh Nguyen 
> Acked-by: Paul Zimmerman 
> ---
> v3:
> - Address comments from Felipe
> - Used Method 2 as recommended by Synopsys to high-bandwidth endpoints.
> 
> v2:
> - Fix coding style with braces around both if() branches
> ---
>  drivers/usb/dwc2/core.c |   53 
> +++
>  1 file changed, 53 insertions(+)
> 
> diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
> index 1d12988..8d8c100 100644
> --- a/drivers/usb/dwc2/core.c
> +++ b/drivers/usb/dwc2/core.c
> @@ -507,6 +507,56 @@ void dwc2_disable_host_interrupts(struct dwc2_hsotg 
> *hsotg)
>   writel(intmsk, hsotg->regs + GINTMSK);
>  }
>  
> +/*
> + * dwc2_calculate_dynamic_fifo() - Calculates the default fifo size
> + * For system that have a total fifo depth that is smaller than the default
> + * RX + TX fifo size.
> + *
> + * @hsotg: Programming view of DWC_otg controller
> + */
> +static void dwc2_calculate_dynamic_fifo(struct dwc2_hsotg *hsotg)
> +{
> + struct dwc2_core_params *params = hsotg->core_params;
> + struct dwc2_hw_params *hw = &hsotg->hw_params;
> + u32 rxfsiz, nptxfsiz, ptxfsiz, total_fifo_size;
> +
> + total_fifo_size = hw->total_fifo_size;
> + rxfsiz = params->host_rx_fifo_size;
> + nptxfsiz = params->host_nperio_tx_fifo_size;
> + ptxfsiz = params->host_perio_tx_fifo_size;
> +
> + /* Will use Method 2 defined in the DWC2 spec: minimum FIFO depth

according to CodingStyle, this should be:

/*
 * Will use Method 2 defined in the DWC2 spec: minimum FIFO depth

> +  * allocation with support for high bandwidth endpoints. Synopsys
> +  * defines MPS(Max Packet size) for a periodic EP=1024, and for
> +  * non-periodic as 512.
> +  */
> + if (total_fifo_size < (rxfsiz + nptxfsiz + ptxfsiz)) {
> + /* For Buffer DMA mode/Scatter Gather DMA mode
> +  * 2 * ((Largest Packet size / 4) + 1 + 1) + n
> +  * with n = number of host channel.
> +  * 2 * ((1024/4) + 2) = 516
> +  */

comment style it wrong.

> + rxfsiz = 516 + hw->host_channels;

add a blank line here

> + /* min non-periodic tx fifo depth
> +  * 2 * (largest non-periodic USB packet used / 4)
> +  * 2 * (512/4) = 256
> +  */

comment style

> + nptxfsiz = 256;

blank line.

> + /* min periodic tx fifo depth
> +  * (largest packet size*MC)/4
> +  * (1024 * 3)/4 = 768
> +  */
> + ptxfsiz = 768;
> +
> + params->host_rx_fifo_size = rxfsiz;
> + params->host_nperio_tx_fifo_size = nptxfsiz;
> + params->host_perio_tx_fifo_size = ptxfsiz;
> + }
> +
> + if (total_fifo_size < (rxfsiz + nptxfsiz + ptxfsiz))

this is what I don't get, why do you have this branch again ? Is it just
to see if you *still* have fifo issues ? It looks like you could add a
comment here and make this unlikely:

/*
 * If the summation of RX, NPTX and PTX fifo sizes is still
 * bigger than the total_fifo_size, then we have a problem.
 *
 * We won't be able to allocate as many endpoints. Right now,
 * we're just printing an error message, but ideally this FIFO
 * allocation algorithm would be improved in the future.
 *
 * FIXME improve this FIFO allocation algorithm.
 */
 if (unlikely(total_fifo_size < (rxfsiz + nptxfsiz + ptxfsiz))

that way, it's clearly documented what you're trying to achieve and
someone looking at the code years from now, won't get confused.

> + dev_err(hsotg->dev, "invalid fifo sizes\n");
> +}
> +
>  static void dwc2_config_fifos(struct dwc2_hsotg *hsotg)
>  {
>   struct dwc2_core_params *params = hsotg->core_params;
> @@ -515,6 +565,9 @@ static void dwc2_config_fifos(struct dwc2_hsotg *hsotg)
>   if (!params->enable_dynamic_fifo)
>   return;
>  
> + /* Calculate the correct FIFO sizes */

this comment is a little bit pointless as it says the same thing as the
function name itself ;-)

after fixing those:

Reviewed-by: Felipe Balbi 

cheers

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH] usb: gadget: add temporary __uses_feature_flags

2014-03-05 Thread Felipe Balbi
On Mon, Mar 03, 2014 at 04:52:27PM -0600, Felipe Balbi wrote:
> On Mon, Mar 03, 2014 at 02:46:32PM -0800, Greg KH wrote:
> > On Mon, Mar 03, 2014 at 11:04:02AM -0600, Felipe Balbi wrote:
> > > during the conversion to a new method of finding
> > > proper endpoints, we need to give our users a
> > > grace period until full conversion is finished.
> > 
> > Who are these "users"?  kernel developers?  Or end-users?
> 
> kernel developers.
> 
> > > This patch adds a new internal and temporary
> > > __uses_feature_flags flag which will tell gadget
> > > framework that this UDC has been converted to
> > > the new feature flag-based endpoint scheme.
> > > 
> > > Once all gadget drivers are converted, this
> > > flag will be removed.
> > > 
> > > Signed-off-by: Felipe Balbi 
> > > ---
> > >  drivers/usb/dwc3/gadget.c   |  1 +
> > >  drivers/usb/gadget/epautoconf.c | 48 
> > > +
> > >  drivers/usb/gadget/s3c-hsotg.c  |  1 +
> > >  include/linux/usb/gadget.h  |  2 ++
> > >  4 files changed, 29 insertions(+), 23 deletions(-)
> > > 
> > > diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> > > index eaf8537..54b40ce 100644
> > > --- a/drivers/usb/dwc3/gadget.c
> > > +++ b/drivers/usb/dwc3/gadget.c
> > > @@ -2733,6 +2733,7 @@ int dwc3_gadget_init(struct dwc3 *dwc)
> > >   dwc->gadget.speed   = USB_SPEED_UNKNOWN;
> > >   dwc->gadget.sg_supported= true;
> > >   dwc->gadget.name= "dwc3-gadget";
> > > + dwc->gadget.__uses_feature_flags = true;
> > 
> > I don't really understand what this is doing for anyone.  Can't we just
> > fix up all in-kernel users of the flags properly?
> 
> I can try to do that, yes, but for v3.15 might be quite a bit of work.
> Anyway, I guess we still have a few days left.

I have dropped those patches from my "next" branch, it'll give me more
time to make this right for v3.16.

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH 06/11] usb: dwc3: core: allocate scratch buffers

2014-03-05 Thread Felipe Balbi
On Wed, Mar 05, 2014 at 04:47:31PM +0530, George Cherian wrote:
> On 2/26/2014 1:10 AM, Felipe Balbi wrote:
> >We must read HWPARAMS4 register to figure out
> >how many scratch buffers we should allocate.
> >
> >Later patch will use "Set Scratchpad Buffer
> >Array" command to pass the pointer to the
> >IP so it can be used during hibernation.
> >
> >Signed-off-by: Felipe Balbi 
> >---
> >  drivers/usb/dwc3/core.c | 95 
> > +
> >  drivers/usb/dwc3/core.h |  6 
> >  2 files changed, 101 insertions(+)
> >
> >diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
> >index a49217a..2864aad 100644
> >--- a/drivers/usb/dwc3/core.c
> >+++ b/drivers/usb/dwc3/core.c
> >@@ -242,6 +242,80 @@ static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
> > }
> >  }
> >+static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc)
> >+{
> >+if (!dwc->has_hibernation)
> >+return 0;
> >+
> >+if (!dwc->nr_scratch)
> >+return 0;
> >+
> >+dwc->scratchbuf = kmalloc_array(dwc->nr_scratch,
> >+DWC3_SCRATCHBUF_SIZE, GFP_KERNEL);
> >+if (!dwc->scratchbuf)
> >+return -ENOMEM;
> >+
> >+return 0;
> >+}
> >+
> >+static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
> >+{
> >+dma_addr_t scratch_addr;
> >+u32 param;
> >+int ret;
> >+
> 
> Shouldn't there be check for  dwc->scratchbuf and dwc->nr_scratch
> before calling dma_map_single?

fixed, thanks:

commit ae53c955b61a6270b65f384665e5e856109a9c9f
Author: Felipe Balbi 
Date:   Thu Dec 19 13:04:28 2013 -0600

usb: dwc3: core: allocate scratch buffers

We must read HWPARAMS4 register to figure out
how many scratch buffers we should allocate.

Later patch will use "Set Scratchpad Buffer
Array" command to pass the pointer to the
IP so it can be used during hibernation.

Signed-off-by: Felipe Balbi 

diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c
index 785feee..e3f8fd5 100644
--- a/drivers/usb/dwc3/core.c
+++ b/drivers/usb/dwc3/core.c
@@ -242,6 +242,90 @@ static void dwc3_event_buffers_cleanup(struct dwc3 *dwc)
}
 }
 
+static int dwc3_alloc_scratch_buffers(struct dwc3 *dwc)
+{
+   if (!dwc->has_hibernation)
+   return 0;
+
+   if (!dwc->nr_scratch)
+   return 0;
+
+   dwc->scratchbuf = kmalloc_array(dwc->nr_scratch,
+   DWC3_SCRATCHBUF_SIZE, GFP_KERNEL);
+   if (!dwc->scratchbuf)
+   return -ENOMEM;
+
+   return 0;
+}
+
+static int dwc3_setup_scratch_buffers(struct dwc3 *dwc)
+{
+   dma_addr_t scratch_addr;
+   u32 param;
+   int ret;
+
+   if (!dwc->has_hibernation)
+   return 0;
+
+   if (!dwc->nr_scratch)
+   return 0;
+
+/* should never fall here */
+   if (!WARN_ON(dwc->scratchbuf))
+   return;
+
+   scratch_addr = dma_map_single(dwc->dev, dwc->scratchbuf,
+   dwc->nr_scratch * DWC3_SCRATCHBUF_SIZE,
+   DMA_BIDIRECTIONAL);
+   if (dma_mapping_error(dwc->dev, scratch_addr)) {
+   dev_err(dwc->dev, "failed to map scratch buffer\n");
+   ret = -EFAULT;
+   goto err0;
+   }
+
+   dwc->scratch_addr = scratch_addr;
+
+   param = lower_32_bits(scratch_addr);
+
+   ret = dwc3_send_gadget_generic_command(dwc,
+   DWC3_DGCMD_SET_SCRATCHPAD_ADDR_LO, param);
+   if (ret < 0)
+   goto err1;
+
+   param = upper_32_bits(scratch_addr);
+
+   ret = dwc3_send_gadget_generic_command(dwc,
+   DWC3_DGCMD_SET_SCRATCHPAD_ADDR_HI, param);
+   if (ret < 0)
+   goto err1;
+
+   return 0;
+
+err1:
+   dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
+   DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
+
+err0:
+   return ret;
+}
+
+static void dwc3_free_scratch_buffers(struct dwc3 *dwc)
+{
+   if (!dwc->has_hibernation)
+   return;
+
+   if (!dwc->nr_scratch)
+   return;
+
+/* should never fall here */
+   if (!WARN_ON(dwc->scratchbuf))
+   return;
+
+   dma_unmap_single(dwc->dev, dwc->scratch_addr, dwc->nr_scratch *
+   DWC3_SCRATCHBUF_SIZE, DMA_BIDIRECTIONAL);
+   kfree(dwc->scratchbuf);
+}
+
 static void dwc3_core_num_eps(struct dwc3 *dwc)
 {
struct dwc3_hwparams*parms = &dwc->hwparams;
@@ -277,6 +361,7 @@ static void dwc3_cache_hwparams(struct dwc3 *dwc)
 static int dwc3_core_init(struct dwc3 *dwc)
 {
unsigned long   timeout;
+   u32 hwparams4 = dwc->hwparams.hwparams4;
u32 reg;
int ret;
 
@@ -334,6 +419,10 @@ static int dwc3_core_init(struct dwc3 *dwc)
else
reg &= ~DWC3_GCTL_DSBLCLKGTNG;
break;
+ 

Re: [PATCH v9 1/4] phy: core: Add an exported of_phy_get function

2014-03-05 Thread Tomasz Figa

On 05.03.2014 16:28, Kamil Debski wrote:

Previously the of_phy_get function took a struct device * and
was declared static. It was impossible to call it from
another driver and thus it was impossible to get phy defined
for a given node. The old function was renamed to _of_phy_get
and was left for internal use. of_phy_get function was added
and it was exported. The function enables to get a phy for
a given device tree node.

Signed-off-by: Kamil Debski 
---
  drivers/phy/phy-core.c  |   45 -
  include/linux/phy/phy.h |6 ++
  2 files changed, 42 insertions(+), 9 deletions(-)


Reviewed-by: Tomasz Figa 

Best regards,
Tomasz
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v9 3/4] phy: Add new Exynos USB 2.0 PHY driver

2014-03-05 Thread Tomasz Figa

On 05.03.2014 16:28, Kamil Debski wrote:

Add a new driver for the Exynos USB 2.0 PHY. The new driver uses the generic
PHY framework. The driver includes support for the Exynos 4x10 and 4x12
SoC families.

Signed-off-by: Kamil Debski 
---
  .../devicetree/bindings/phy/samsung-phy.txt|   53 
  Documentation/phy/samsung-usb2.txt |  134 
  drivers/phy/Kconfig|   29 ++
  drivers/phy/Makefile   |3 +
  drivers/phy/phy-exynos4210-usb2.c  |  261 
  drivers/phy/phy-exynos4x12-usb2.c  |  328 
  drivers/phy/phy-samsung-usb2.c |  222 +
  drivers/phy/phy-samsung-usb2.h |   66 
  8 files changed, 1096 insertions(+)
  create mode 100644 Documentation/phy/samsung-usb2.txt
  create mode 100644 drivers/phy/phy-exynos4210-usb2.c
  create mode 100644 drivers/phy/phy-exynos4x12-usb2.c
  create mode 100644 drivers/phy/phy-samsung-usb2.c
  create mode 100644 drivers/phy/phy-samsung-usb2.h


Reviewed-by: Tomasz Figa 

Best regards,
Tomasz
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: USB remote wakeup through gpio interrupt

2014-03-05 Thread Alan Stern
On Wed, 5 Mar 2014, Jagdish Gedia wrote:

> Hi,
> There is some inconsistency in remote wakeup functionality in my
> custom board. so I want to wakeup the runtime suspended USB host
> through interrupt. My USB device is connected to the board through USB
> interface and some gpios. device will give interrupt on processor gpio
> when it needs attention of USB host. What should i do so that i can
> wakeup the usb host when i get interrupt from the device.

Have your gpio interrupt handler call pm_request_resume() for the host
controller device.

However, this may not do what you want.  Since the root hub will remain
suspended, the host controller will go back to low-power immediately
after it is resumed.  You really need to resume the USB device itself,
not the host controller.

> My idea was to apply power management related hooks from the interrupt
> handler, but I am not getting the clear idea.
> 
> My main doubt is,
> Will this mechanism be efficient as remote wakeup functionality?

That's a hard question to answer without measurements.  But it 
shouldn't matter, because you probably won't get more than one wakeup 
per second, right?

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v9 2/4] phy: core: Add devm_of_phy_get to phy-core

2014-03-05 Thread Tomasz Figa

On 05.03.2014 16:28, Kamil Debski wrote:

Adding devm_of_phy_get will allow to get phys by supplying a
pointer to the struct device_node instead of struct device.

Signed-off-by: Kamil Debski 
---
  drivers/phy/phy-core.c  |   31 +++
  include/linux/phy/phy.h |8 
  2 files changed, 39 insertions(+)


Reviewed-by: Tomasz Figa 

Best regards,
Tomasz
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: BUG: USB Reset-Resume Mechanism does not work for runtime resume

2014-03-05 Thread Alan Stern
On Wed, 5 Mar 2014, Oliver Neukum wrote:

> On Wed, 2014-03-05 at 09:40 +, Poulain, Loic wrote:
> > Hi,
> > 
> > I think there is an issue with the reset-resume mechanism during USB
> > runtime resume, leaving the interfaces suspended forever.
> > 
> > - Context:
> > 
> > Android platform, running a 3.13 + Google AOSP patches kernel.
> > I'm facing a USB issue with the bsusb driver. btusb driver has the USB
> > runtime suspend enabled + remote wakeup.
> > However sometimes the USB runtime resume does not work as expected (we
> > admit here that this can happen).
> > 
> > [ 3066.408413] usb 2-3: usb auto-resume
> > [ 3066.408433] hub 2-0:1.0: state 7 ports 9 chg  evt 0008
> > [ 3066.445465] usb 2-3: finish resume
> > [ 3071.447591] usb 2-3: bt_hc_worker timed out on ep0in len=0/2
> > [ 3071.447598] usb 2-3: retry with reset-resume
> > 
> > Then the usbcore tries a reset-resume, but btusb driver does not
> > implement this callback.

The best solution would be to fix the hardware so that a normal resume 
does work.

> This is extremely tricky, almost academical a question.
> We cannot fall back to reset_resume() in this case without
> very bad consequences.
> If remote wakeup is needed, reset_resume() must not be used.

The only alternative is to logically disconnect the device.  But this 
conflicts with the persist_enabled flag.

> It seems to me that the bug in this case is the fallback itself.
> From a design viewpoint is probably wrong the unbind a device
> in the runtime case. We'd better notify the driver in every case.
> If you unbind and rebind you just risk getting into a tight loop.

In this case, turning off the persist flag might help:

echo 0 >/sys/bus/usb/devices/.../power/persist

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: BUG: USB Reset-Resume Mechanism does not work for runtime resume

2014-03-05 Thread Alan Stern
On Wed, 5 Mar 2014, Poulain, Loic wrote:

> + function 'do_rebind_interface' is in charge of unbind and rebind the 
> interfaces with the 'need_binfind' flag set.
> + However this method is only called in 'usb_resume_complete'.
> + Problem is that 'usb_resume_complete' is a dev_pm_ops callback (core/usb.h) 
> used by the System PM core which is never called in a runtime PM scenario.
> + So interfaces remain suspended forever (or until the next PM system 
> suspend/resume), device is unusable.
> (unbinding/rebinding manually the interface via sysfs recovers the device)
> 
> Could you please let me know if it's the expected behavior or a real issue. 
> Should we not call 'do_rebind_interface' in the runtime resume sequence?

I suspect this is an oversight.

Still, implementing it would be difficult.  In usb_runtime_resume, the 
device lock may or may not already be held.  Therefore we cannot simply 
lock the device and call do_rebind_interfaces.

Using a work queue for this seems like overkill (and it seems fragile).  
I don't know what we should do.

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH 02/12] phy: omap-control: Update DT binding information

2014-03-05 Thread Tony Lindgren
* Roger Quadros  [140305 04:26]:
> + George
> 
> Tony,
> 
> On 03/04/2014 06:28 PM, Tony Lindgren wrote:
> > * Roger Quadros  [140304 01:17]:
> >> Hi Tony,
> >>
> >> On 03/03/2014 09:02 PM, Tony Lindgren wrote:
> >>> * Roger Quadros  [140303 07:10]:
>  Move omap-control binding information to the right location.
> 
>  Signed-off-by: Roger Quadros 
>  ---
>   Documentation/devicetree/bindings/phy/ti-phy.txt   | 25 
>  ++
>   Documentation/devicetree/bindings/usb/omap-usb.txt | 24 
>  -
>   2 files changed, 25 insertions(+), 24 deletions(-)
> 
>  diff --git a/Documentation/devicetree/bindings/phy/ti-phy.txt 
>  b/Documentation/devicetree/bindings/phy/ti-phy.txt
>  index 207e14c..41dc132 100644
>  --- a/Documentation/devicetree/bindings/phy/ti-phy.txt
>  +++ b/Documentation/devicetree/bindings/phy/ti-phy.txt
>  @@ -1,5 +1,30 @@
>   TI PHY: DT DOCUMENTATION FOR PHYs in TI PLATFORMs
>   
>  +OMAP CONTROL PHY
>  +
>  +Required properties:
>  + - compatible: Should be one of
>  + "ti,control-phy-otghs" - if it has otghs_control mailbox register as 
>  on OMAP4.
>  + "ti,control-phy-usb2" - if it has Power down bit in control_dev_conf 
>  register
>  +e.g. USB2_PHY on OMAP5.
>  + "ti,control-phy-pipe3" - if it has DPLL and individual Rx & Tx power 
>  control
>  +e.g. USB3 PHY and SATA PHY on OMAP5.
>  + "ti,control-phy-dra7usb2" - if it has power down register like USB2 
>  PHY on
>  +DRA7 platform.
>  + "ti,control-phy-am437usb2" - if it has power down register like USB2 
>  PHY on
>  +AM437 platform.
> >>>
> >>> To me it seems that you can leave out all the above. You can set these 
> >>> falgs
> >>> flags directly in the driver based on the compatible flag. Then just 
> >>> initialize
> >>> the .data in the driver based on the compatible flag.
> >>
> >> I'm not sure if I got you. A single platform can have different type of 
> >> phys.
> >>
> >> e.g. OMAP5 has both usb2 and pipe3 PHYs,
> >> DRA7 has both pipe3 and usb2 PHYs, but this usb2 PHY is not compatible 
> >> with OMAP5 one
> >> so we need a new compatible id for that.
> >>
> >> To add to the woes, the designers were creative enough to make another 
> >> mutation to
> >> the USB2 PHY for AM437x, :(
> > 
> > Oh OK, in that case the compatible flag may not be enough for configuring 
> > the
> > various instances.
> >  
> >> What do you suggest the compatible ids should look like for these 5 types 
> >> of PHY control?
> >> OTGHS  (OMAP4 & 5)
> >> USB2   (OMAP5)
> >> PIPE3  (OMAP5 & DRA7)
> >> USB2x  (DRA7)
> >> USB2y  (AM437)
> > 
> > I think in that case having the various instances fully configurable from
> > device tree is OK if you prefer that. But if you wanted to use the
> > compatible flag, then you could do something like this:
> > 
> > ti,control-phy-omap4-otghs  (assuming same on omap4 & 5)
> > ti,control-phy-omap5-usb2
> > ti,control-phy-omap5-pipe3  (assuming same on omap5 & dra7)
> > ti,control-phy-dra7-usb2x
> > ti,control-phy-am437-usb2y
> > ...
> > 
> 
> Please note that the original bindings were added in v3.13 and I'm just 
> moving the documentation
> to the right location. So I don't think we should change the bindings now.

OK yeah if the bindings are established you should keep them around.
 
> "ti,control-phy-dra7usb2" and "ti,control-phy-am437usb2" have no users still 
> so we could probably
> change those to "ti,control-phy-dra7-usb2" and "ti,control-phy-am437-usb2".
> 
> What do you say?

Makes sense to me.

Regards,

Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: musb: Remove dependency on BROKEN and mach/ headers from da8xx glue

2014-03-05 Thread Felipe Balbi
On Wed, Mar 05, 2014 at 01:11:15PM +0100, Christian Riesch wrote:
> Signed-off-by: Christian Riesch 
> Cc: Felipe Balbi 
> ---
> Hi,
> 
> I have successfully tested this driver with kernel 3.14-rc5 on a custom
> Texas Instruments AM1808 board in gadget mode, RNDIS network gadget.
> Therefore I think the dependency on BROKEN can be removed.
> 
> Commit 787f5627bec80094db487bfcb401e9744f181aed that added this dependancy
> states that the dependency on  headers should also be removed.
> Currently, the CFGCHIP2 define in the code is the only reason why a
>  header is included in the file, so I am replacing it with the
> hardcoded address.
> 
> Regards, Christian
> 
> 
>  drivers/usb/musb/Kconfig |1 -
>  drivers/usb/musb/da8xx.c |3 +--
>  2 files changed, 1 insertion(+), 3 deletions(-)
> 
> diff --git a/drivers/usb/musb/Kconfig b/drivers/usb/musb/Kconfig
> index 688dc8b..af370a4 100644
> --- a/drivers/usb/musb/Kconfig
> +++ b/drivers/usb/musb/Kconfig
> @@ -67,7 +67,6 @@ config USB_MUSB_DAVINCI
>  config USB_MUSB_DA8XX
>   tristate "DA8xx/OMAP-L1x"
>   depends on ARCH_DAVINCI_DA8XX
> - depends on BROKEN
>  
>  config USB_MUSB_TUSB6010
>   tristate "TUSB6010"
> diff --git a/drivers/usb/musb/da8xx.c b/drivers/usb/musb/da8xx.c
> index e3486de..6f4d8c7 100644
> --- a/drivers/usb/musb/da8xx.c
> +++ b/drivers/usb/musb/da8xx.c
> @@ -34,7 +34,6 @@
>  #include 
>  #include 
>  
> -#include 
>  #include 
>  
>  #include "musb_core.h"
> @@ -80,7 +79,7 @@
>  
>  #define DA8XX_MENTOR_CORE_OFFSET 0x400
>  
> -#define CFGCHIP2 IO_ADDRESS(DA8XX_SYSCFG0_BASE + DA8XX_CFGCHIP2_REG)
> +#define CFGCHIP2 IOMEM(UL(0xfec14184))

the right way, would be to convert phy_on()/phy_off() into a real
drivers/phy/phy-da8xx.c driver, then remove references to the nop
transceiver from drvers/usb/musb/da8xx.c

cheers

-- 
balbi


signature.asc
Description: Digital signature


Re: [PATCH 08/23] libusbg: Fix wrong binding parsing.

2014-03-05 Thread Sergei Shtylyov

Hello.

On 03/05/2014 05:14 PM, Krzysztof Opasiak wrote:


usbg_parse_bindings() function has done parsing incorrectly
and in inefficent way. Changes made in this function provide
better performance and fix wrong linking issue when having
two instances of the same function.



Signed-off-by: Krzysztof Opasiak 
---
  src/usbg.c |   34 --
  1 file changed, 20 insertions(+), 14 deletions(-)



diff --git a/src/usbg.c b/src/usbg.c
index 198fc7a..255074f 100644
--- a/src/usbg.c
+++ b/src/usbg.c

[...]

@@ -420,19 +423,22 @@ static void usbg_parse_config_bindings(usbg_config *c)
TAILQ_INIT(&c->bindings);

n = scandir(bpath, &dent, bindings_select, alphasort);

[...]

+   for (i = 0; i < n; i++) {
+   sprintf(file_name, "%s/%s", bpath, dent[i]->d_name);
+   nmb = readlink(file_name, target, USBG_MAX_PATH_LENGTH);
+   if (nmb < 0)
+   ERRORNO("bytes %d contents %s\n", n, target);
+
+   /* readlink() don't add this, so we have to do it manually */
+   target[nmb] = '\0';
+   /* Target contains a full path
+*  but we need only function dir name */
+   target_name = strrchr(target, '/') + 1;


   Why the indentation jumped suddenly to the right? I know I'm asking this 
question for the 2nd time already. :-)


WBR, Sergei

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH] usb: gadget: add temporary __uses_feature_flags

2014-03-05 Thread Greg KH
On Wed, Mar 05, 2014 at 09:45:22AM -0600, Felipe Balbi wrote:
> On Mon, Mar 03, 2014 at 04:52:27PM -0600, Felipe Balbi wrote:
> > On Mon, Mar 03, 2014 at 02:46:32PM -0800, Greg KH wrote:
> > > On Mon, Mar 03, 2014 at 11:04:02AM -0600, Felipe Balbi wrote:
> > > > during the conversion to a new method of finding
> > > > proper endpoints, we need to give our users a
> > > > grace period until full conversion is finished.
> > > 
> > > Who are these "users"?  kernel developers?  Or end-users?
> > 
> > kernel developers.
> > 
> > > > This patch adds a new internal and temporary
> > > > __uses_feature_flags flag which will tell gadget
> > > > framework that this UDC has been converted to
> > > > the new feature flag-based endpoint scheme.
> > > > 
> > > > Once all gadget drivers are converted, this
> > > > flag will be removed.
> > > > 
> > > > Signed-off-by: Felipe Balbi 
> > > > ---
> > > >  drivers/usb/dwc3/gadget.c   |  1 +
> > > >  drivers/usb/gadget/epautoconf.c | 48 
> > > > +
> > > >  drivers/usb/gadget/s3c-hsotg.c  |  1 +
> > > >  include/linux/usb/gadget.h  |  2 ++
> > > >  4 files changed, 29 insertions(+), 23 deletions(-)
> > > > 
> > > > diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
> > > > index eaf8537..54b40ce 100644
> > > > --- a/drivers/usb/dwc3/gadget.c
> > > > +++ b/drivers/usb/dwc3/gadget.c
> > > > @@ -2733,6 +2733,7 @@ int dwc3_gadget_init(struct dwc3 *dwc)
> > > > dwc->gadget.speed   = USB_SPEED_UNKNOWN;
> > > > dwc->gadget.sg_supported= true;
> > > > dwc->gadget.name= "dwc3-gadget";
> > > > +   dwc->gadget.__uses_feature_flags = true;
> > > 
> > > I don't really understand what this is doing for anyone.  Can't we just
> > > fix up all in-kernel users of the flags properly?
> > 
> > I can try to do that, yes, but for v3.15 might be quite a bit of work.
> > Anyway, I guess we still have a few days left.
> 
> I have dropped those patches from my "next" branch, it'll give me more
> time to make this right for v3.16.

Thank you.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 part1 4/8] usb: assign default peer ports for root hubs

2014-03-05 Thread Dan Williams
On Tue, 2014-03-04 at 10:58 -0500, Alan Stern wrote:
> On Mon, 3 Mar 2014, Dan Williams wrote:
> 
> > Ok, so the root issue is that the peering code needs to see
> > hcd->primary_hcd = NULL to know that there is no longer a peer.  I
> > update usb_remove_hcd() to clear out ->shared_hcd and ->primary_hcd
> > under the peer lock before we allow the root hub to be freed.
> 
> Even if there is a peer hcd, the peer's root hub may not exist.  More
> locking is needed than you have here.
> 
> > I add some description of the new locking scheme to the changelog as
> > well.
> > 
> > 8<--
> > Subject: usb: assign default peer ports for root hubs
> > 
> > From: Dan Williams 
> > 
> > Assume that the peer of a superspeed port is the port with the same id
> > on the shared_hcd root hub.  This identification scheme is required of
> > external hubs by the USB3 spec [1].  However, for root hubs, tier mismatch
> > may be in effect [2].  Tier mismatch can only be enumerated via platform
> > firmware.  For now, simply perform the nominal association.
> > 
> > Once the root hub is marked as unregistered we block attempts to walk
> > the ->shared_hcd pointer to find a root-peer port.
> > 
> > A new lock 'usb_port_peer_mutex' is introduced to synchronize port
> > device add/remove with peer lookups.  We hold the lock for the duration
> > of registration allowing default peers (and later firmware identified
> > peers) to be discovered.  We also hold the lock whenever hub devices are
> > validated (hdev->maxchild set to non-zero) and invalidated
> > (hdev->maxchild set to zero).  Marking a hub valid and registering its
> > ports is a locked operation and conversely invalidating a hub and
> > removing its ports is another locked operation.  This prevents a port
> > from associating with an invalid peer.  Finally, we hold the lock when
> > breaking the "shared hcd" relationship at usb_remove_hcd() time.
> 
> More generally, I would say that the new mutex protects the
> hcd->shared_hcd, hcd->self.root_hub, and port_dev->child pointers, in 
> addition to hdev->maxchild.

Yes, much more succinct.

> 
> > [1]: usb 3.1 section 10.3.3
> > [2]: xhci 1.1 appendix D
> > 
> > Cc: Alan Stern 
> > [alan: usb_port_peer_mutex locking scheme]
> > Signed-off-by: Dan Williams 
> > ---
> >  drivers/usb/core/hcd.c  |   21 -
> >  drivers/usb/core/hub.c  |   37 ++
> >  drivers/usb/core/hub.h  |2 +
> >  drivers/usb/core/port.c |   78 
> > ---
> >  4 files changed, 118 insertions(+), 20 deletions(-)
> > 
> > diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
> > index 2518c3250750..259990a982f3 100644
> > --- a/drivers/usb/core/hcd.c
> > +++ b/drivers/usb/core/hcd.c
> > @@ -2766,6 +2766,8 @@ EXPORT_SYMBOL_GPL(usb_add_hcd);
> >   */
> >  void usb_remove_hcd(struct usb_hcd *hcd)
> >  {
> > +   /* only routine outside of hub.c that needs this mutex */
> > +   extern struct mutex usb_port_peer_mutex;
> 
> To be thorough, you also should hold the mutex when initially setting 
> hcd->self.root_hub.  And in usb_create_shared_hcd, when the shared_hcd 
> pointers are initialized.

Ok, I added this.

> 
> Also, don't forget to clear hcd->self.root_hub (under protection
> of the mutex) in the failure pathway of usb_add_hcd.

I made a new usb_put_invalidate_rhdev() to handle cases where we can set
hcd->self.root_hub to NULL.

> 
> > @@ -2829,6 +2830,24 @@ void usb_remove_hcd(struct usb_hcd *hcd)
> > usb_put_phy(hcd->phy);
> > hcd->phy = NULL;
> > }
> > +
> > +   /*
> > +* Before we free this device, flush in-flight peering attempts
> > +* and disable peer lookups
> > +*/
> > +   mutex_lock(&usb_port_peer_mutex);
> > +   if (hcd->shared_hcd) {
> > +   struct usb_hcd *peer_hcd = hcd->shared_hcd;
> > +
> > +   hcd->shared_hcd = NULL;
> > +   hcd->primary_hcd = NULL;
> > +   peer_hcd->shared_hcd = NULL;
> > +   if (peer_hcd->primary_hcd == hcd)
> > +   peer_hcd->primary_hcd = NULL;
> > +   }
> > +   mutex_unlock(&usb_port_peer_mutex);
> 
> This belongs in hcd_release, not here, corresponding to the fact that 
> these pointers are initialized in usb_create_shared_hcd.
> 

Yes, I overlooked hcd_release.

> > +
> > +   usb_put_dev(hcd->self.root_hub);
> 
> Before doing this, you need to set hcd->self.root_hub to NULL, under 
> the protection of the mutex.  Unfortunately, it's not possible to move 
> the usb_put_dev call into hcd_release -- this is because each USB 
> device (including the root hub) holds a reference to the hcd.
> 
> > diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
> > index 531a591a7b1e..cb42352b97e6 100644
> > --- a/drivers/usb/core/port.c
> > +++ b/drivers/usb/core/port.c
> > @@ -151,9 +151,68 @@ static struct device_driver usb_port_driver = {
> > .owner = THIS_MODULE,
> >  };
> >  
> > +/*
> > + * Set the default peer port for root hubs.  Assu

Re: [PATCH v6 part1 5/8] usb: assign usb3 external hub port peers

2014-03-05 Thread Dan Williams
On Mon, 2014-03-03 at 18:33 -0800, Dan Williams wrote:
> Subject: usb: assign usb3 external hub port peers
> 
> From: Dan Williams 
> 
> Given that root hub port peers are already established, external hub peer
> ports can be determined by traversing the device topology:
> 
> 1/ ascend to the parent hub and find the upstream port_dev
> 
> 2/ walk ->peer to find the peer port
> 
> 3/ descend to the peer hub via ->child
> 
> 4/ find the port with the matching port id
> 
> Note that this assumes the port labeling scheme required by the
> specification [1].
> 
> [1]: usb3 3.1 section 10.3.3
> 
> Signed-off-by: Dan Williams 

Just rebase to handle the find_and_link_peer() rename.

8<---
Subject: usb: assign usb3 external hub port peers

From: Dan Williams 

Given that root hub port peers are already established, external hub peer
ports can be determined by traversing the device topology:

1/ ascend to the parent hub and find the upstream port_dev

2/ walk ->peer to find the peer port

3/ descend to the peer hub via ->child

4/ find the port with the matching port id

Note that this assumes the port labeling scheme required by the
specification [1].

[1]: usb3 3.1 section 10.3.3

Signed-off-by: Dan Williams 
---
 drivers/usb/core/port.c |   32 
 1 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index 0d36610af156..fd53257de6a9 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -181,15 +181,18 @@ static void unlink_peers(struct usb_port *left, struct 
usb_port *right)
left->peer = NULL;
 }
 
-/* set the default peer port for root hubs */
+/*
+ * Set the default peer port for root hubs, or via the upstream peer
+ * relationship for all other hubs
+ */
 static void find_and_link_peer(struct usb_hub *hub, int port1)
 {
struct usb_port *port_dev = hub->ports[port1 - 1], *peer;
struct usb_device *hdev = hub->hdev;
+   struct usb_device *peer_hdev;
+   struct usb_hub *peer_hub;
 
if (!hdev->parent) {
-   struct usb_hub *peer_hub;
-   struct usb_device *peer_hdev;
struct usb_hcd *hcd = bus_to_hcd(hdev->bus);
struct usb_hcd *peer_hcd = hcd->shared_hcd;
 
@@ -197,15 +200,28 @@ static void find_and_link_peer(struct usb_hub *hub, int 
port1)
return;
 
peer_hdev = peer_hcd->self.root_hub;
-   peer_hub = usb_hub_to_struct_hub(peer_hdev);
-   if (!peer_hub || port1 > peer_hdev->maxchild)
+   } else {
+   struct usb_port *upstream;
+   struct usb_device *parent = hdev->parent;
+   struct usb_hub *parent_hub = usb_hub_to_struct_hub(parent);
+
+   if (!parent_hub)
return;
 
-   peer = peer_hub->ports[port1 - 1];
+   upstream = parent_hub->ports[hdev->portnum - 1];
+   if (!upstream || !upstream->peer)
+   return;
 
-   if (peer)
-   link_peers(port_dev, peer);
+   peer_hdev = upstream->peer->child;
}
+
+   peer_hub = usb_hub_to_struct_hub(peer_hdev);
+   if (!peer_hub || port1 > peer_hdev->maxchild)
+   return;
+
+   peer = peer_hub->ports[port1 - 1];
+   if (peer)
+   link_peers(port_dev, peer);
 }
 
 int usb_hub_create_port_device(struct usb_hub *hub, int port1)


--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v5 6/6] arm/dts: added dt properties to adapt to the new phy framwork

2014-03-05 Thread Tony Lindgren
* Kishon Vijay Abraham I  [140305 04:46]:
> Tony/Benoit,
> 
> On Monday 03 March 2014 05:08 PM, Kishon Vijay Abraham I wrote:
> >Added device tree bindings for dwc3, usb2 and usb3 PHYs. The documentation
> >of these can be found at 
> >Documentation/devicetree/bindings/phy/phy-bindings.txt
> >and Documentation/devicetree/bindings/phy/ti-phy.txt.
> 
> Can this patch be queued for 3.15 merge window?

Thanks applying this patch into omap-for-v3.15/dt.

Tony
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 part1 6/8] usb: find internal hub tier mismatch via acpi

2014-03-05 Thread Dan Williams
On Tue, 2014-03-04 at 11:33 -0500, Alan Stern wrote:
> >  static struct usb_port *find_default_peer(struct usb_hub *hub, int port1)
> >  {
> > +   struct usb_port *port_dev = hub->ports[port1 - 1];
> > struct usb_device *hdev = hub->hdev;
> > struct usb_device *peer_hdev = NULL;
> > struct usb_hub *peer_hub;
> >  
> > +   /*
> > +* If location data is available then we can only peer this port
> > +* by a location match, not the default peer (lest we create a
> > +* situation where we need to go back and undo a default peering
> > +* when the port is later peered by location data)
> > +*/
> > +   if (port_dev->location)
> > +   return NULL;
> 
> I think you probably also want to reject matches where
> port_dev->location is 0 but the peer port does have location data.

I do.  Added this as the final check before linking a default peer.

> 
> > @@ -222,9 +233,92 @@ static void unlink_peers(struct usb_port *left, struct 
> > usb_port *right)
> > left->peer = NULL;
> >  }
> >  
> > +/**
> > + * for_each_child_port() - invoke 'fn' on all usb_port instances beneath 
> > 'hdev'
[..]
> 
> This all looks more complicated than necessary.  Why not define a 
> usb_for_each_port function, like the usb_for_each_dev routine in usb.c?

Actually I can just re-use usb_for_each_dev directly and write a
function to filter on peer hubs.  Yes, much simpler, thanks.

> And instead of calling it in a new usb_set_hub_port_location routine, 
> why not call it from find_default_peer?

This is a simliar problem that patch 3 fixed.  Not sure why I did not
make the connection earlier, fixed up now.

> > @@ -247,9 +341,12 @@ int usb_hub_create_port_device(struct usb_hub *hub, 
> > int port1)
> > if (retval)
> > goto error_register;
> >  
> > -   peer = find_default_peer(hub, port1);
> > -   if (peer)
> > -   link_peers(port_dev, peer);
> > +   if (!port_dev->peer) {
> 
> port_dev->peer should never be set at this point, if you don't try to 
> do the location matching during the ACPI callback.

Agreed.

> 
> > +   struct usb_port *peer = find_default_peer(hub, port1);
> > +
> > +   if (peer)
> > +   link_peers(port_dev, peer);
> > +   }
> >  
> > pm_runtime_set_active(&port_dev->dev);
> >  
> > diff --git a/drivers/usb/core/usb-acpi.c b/drivers/usb/core/usb-acpi.c
> > index ce0f4e8d81cb..e1e1f40f6950 100644
> > --- a/drivers/usb/core/usb-acpi.c
> > +++ b/drivers/usb/core/usb-acpi.c
> > @@ -41,6 +41,17 @@ bool usb_acpi_power_manageable(struct usb_device *hdev, 
> > int index)
> >  }
> >  EXPORT_SYMBOL_GPL(usb_acpi_power_manageable);
> >  
> > +static void usb_acpi_check_port_peer(struct usb_device *hdev,
> > +   acpi_handle *handle, int port1, struct acpi_pld_info *pld)
> > +{
> > +   if (!pld)
> > +   return;
> > +
> > +   #define USB_ACPI_LOCATION_VALID (1 << 31)
> > +   usb_set_hub_port_location(hdev, port1, USB_ACPI_LOCATION_VALID
> > +   | pld->group_token << 8 | pld->group_position);
> > +}
> 
> Why call an external function?  Just store the value in the appropriate 
> port_dev->location.

Done.

8<
Subject: usb: find internal hub tier mismatch via acpi

From: Dan Williams 

ACPI identifies peer ports by setting their 'group_token' and
'group_position' _PLD data to the same value.  If a platform has tier
mismatch [1] , ACPI can override the default (USB3 defined) peer port
association for internal hubs.  External hubs follow the default peer
association scheme.

Location data is cached as an opaque cookie in usb_port_location data.

Note that we only consider the group_token and group_position attributes
from the _PLD data as ACPI specifies that group_token is a unique
identifier.

When we find port location data for a port then we assume that the
firmware will also describe its peer port.  This allows the
implementation to only ever set the peer once.  This leads to a question
about what happens when a pm runtime event occurs while the peer
associations are still resolving.  Since we only ever set the peer
information once, a USB3 port needs to be prevented from suspending
while its ->peer pointer is NULL (implemented in a subsequent patch).

There is always the possibility that firmware mis-identifies the ports,
but there is not much the kernel can do in that case.

[1]: xhci 1.1 appendix D figure 131
[2]: acpi 5 section 6.1.8

[alan]: don't do default peering when acpi data present
Suggested-by: Alan Stern 
Signed-off-by: Dan Williams 
---
 drivers/usb/core/hub.h  |2 ++
 drivers/usb/core/port.c |   54 ---
 drivers/usb/core/usb-acpi.c |   41 ++---
 drivers/usb/core/usb.h  |4 +++
 4 files changed, 79 insertions(+), 22 deletions(-)

diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h
index d51feb68165b..6858a55eceb5 100644
--- a/drivers/usb/core/hub.h
+++ b/drivers/usb/core/hub.h
@@ -83,6 +83,7 @@ struct usb_

Re: [PATCH v6 part1 7/8] usb: sysfs link peer ports

2014-03-05 Thread Dan Williams
On Mon, 2014-03-03 at 18:39 -0800, Dan Williams wrote:
> On Fri, 2014-02-28 at 15:18 -0800, Dan Williams wrote:
> > The usb topology after this change will have symlinks between usb3 ports
> > and their usb2 peers, for example:
> > 
> > usb2/2-1/2-1:1.0/2-1-port1/peer => ../../../../usb3/3-1/3-1:1.0/3-1-port1
> > usb2/2-1/2-1:1.0/2-1-port2/peer => ../../../../usb3/3-1/3-1:1.0/3-1-port2
> > usb2/2-1/2-1:1.0/2-1-port3/peer => ../../../../usb3/3-1/3-1:1.0/3-1-port3
> > usb2/2-1/2-1:1.0/2-1-port4/peer => ../../../../usb3/3-1/3-1:1.0/3-1-port4
> > usb2/2-0:1.0/usb2-port1/peer=> ../../../usb3/3-0:1.0/usb3-port1
> > usb2/2-0:1.0/usb2-port2/peer=> ../../../usb3/3-0:1.0/usb3-port2
> > usb2/2-0:1.0/usb2-port3/peer=> ../../../usb3/3-0:1.0/usb3-port3
> > usb2/2-0:1.0/usb2-port4/peer=> ../../../usb3/3-0:1.0/usb3-port4
> > 
> > usb3/3-1/3-1:1.0/usb3-1-port1/peer => ../../../../usb2/2-1/2-1:1.0/2-1-port1
> > usb3/3-1/3-1:1.0/usb3-1-port2/peer => ../../../../usb2/2-1/2-1:1.0/2-1-port2
> > usb3/3-1/3-1:1.0/usb3-1-port3/peer => ../../../../usb2/2-1/2-1:1.0/2-1-port3
> > usb3/3-1/3-1:1.0/usb3-1-port4/peer => ../../../../usb2/2-1/2-1:1.0/2-1-port4
> > usb3/3-0:1.0/usb3-port1/peer   => ../../../usb2/2-0:1.0/usb2-port1
> > usb3/3-0:1.0/usb3-port2/peer   => ../../../usb2/2-0:1.0/usb2-port2
> > usb3/3-0:1.0/usb3-port3/peer   => ../../../usb2/2-0:1.0/usb2-port3
> > usb3/3-0:1.0/usb3-port4/peer   => ../../../usb2/2-0:1.0/usb2-port4
> > 
> > Introduce link_peers_report() to notify on all link_peers() failure
> > cases.
> > 
> > Signed-off-by: Dan Williams 
> 
> Just fixing up rebase conflicts with the previous changes.

Rebase on top of find_and_link_peer() as well as usb_for_each_dev()
change.

8<-
Subject: usb: sysfs link peer ports

From: Dan Williams 

The usb topology after this change will have symlinks between usb3 ports
and their usb2 peers, for example:

usb2/2-1/2-1:1.0/2-1-port1/peer => ../../../../usb3/3-1/3-1:1.0/3-1-port1
usb2/2-1/2-1:1.0/2-1-port2/peer => ../../../../usb3/3-1/3-1:1.0/3-1-port2
usb2/2-1/2-1:1.0/2-1-port3/peer => ../../../../usb3/3-1/3-1:1.0/3-1-port3
usb2/2-1/2-1:1.0/2-1-port4/peer => ../../../../usb3/3-1/3-1:1.0/3-1-port4
usb2/2-0:1.0/usb2-port1/peer=> ../../../usb3/3-0:1.0/usb3-port1
usb2/2-0:1.0/usb2-port2/peer=> ../../../usb3/3-0:1.0/usb3-port2
usb2/2-0:1.0/usb2-port3/peer=> ../../../usb3/3-0:1.0/usb3-port3
usb2/2-0:1.0/usb2-port4/peer=> ../../../usb3/3-0:1.0/usb3-port4

usb3/3-1/3-1:1.0/usb3-1-port1/peer => ../../../../usb2/2-1/2-1:1.0/2-1-port1
usb3/3-1/3-1:1.0/usb3-1-port2/peer => ../../../../usb2/2-1/2-1:1.0/2-1-port2
usb3/3-1/3-1:1.0/usb3-1-port3/peer => ../../../../usb2/2-1/2-1:1.0/2-1-port3
usb3/3-1/3-1:1.0/usb3-1-port4/peer => ../../../../usb2/2-1/2-1:1.0/2-1-port4
usb3/3-0:1.0/usb3-port1/peer   => ../../../usb2/2-0:1.0/usb2-port1
usb3/3-0:1.0/usb3-port2/peer   => ../../../usb2/2-0:1.0/usb2-port2
usb3/3-0:1.0/usb3-port3/peer   => ../../../usb2/2-0:1.0/usb2-port3
usb3/3-0:1.0/usb3-port4/peer   => ../../../usb2/2-0:1.0/usb2-port4

Introduce link_peers_report() to notify on all link_peers() failure
cases.

Signed-off-by: Dan Williams 
---
 drivers/usb/core/port.c |   39 ++-
 1 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index 94d7de3bf808..becdb5d6cffe 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -151,10 +151,12 @@ static struct device_driver usb_port_driver = {
.owner = THIS_MODULE,
 };
 
-static void link_peers(struct usb_port *left, struct usb_port *right)
+static int link_peers(struct usb_port *left, struct usb_port *right)
 {
+   int rc;
+
if (left->peer == right && right->peer == left)
-   return;
+   return 0;
 
if (left->peer || right->peer) {
struct usb_port *lpeer = left->peer;
@@ -164,11 +166,36 @@ static void link_peers(struct usb_port *left, struct 
usb_port *right)
dev_name(&left->dev), dev_name(&right->dev),
dev_name(&left->dev), lpeer,
dev_name(&right->dev), rpeer);
-   return;
+   return -EBUSY;
+   }
+
+   rc = sysfs_create_link(&left->dev.kobj, &right->dev.kobj, "peer");
+   if (rc)
+   return rc;
+   rc = sysfs_create_link(&right->dev.kobj, &left->dev.kobj, "peer");
+   if (rc) {
+   sysfs_remove_link(&left->dev.kobj, "peer");
+   return rc;
}
 
left->peer = right;
right->peer = left;
+
+   return 0;
+}
+
+static void link_peers_report(struct usb_port *left, struct usb_port *right)
+{
+   int rc;
+
+   rc = link_peers(left, right);
+   if (rc == 0) {
+   dev_dbg(&left->dev, "peered to %s\n", dev_name(&right->dev));
+   } else {
+   dev_warn(&left->dev, "failed to peer to %s (%d)\n",
+  

Re: [PATCH v6 part1 8/8] usb: block suspension of superspeed port while hispeed peer is active

2014-03-05 Thread Dan Williams
On Mon, 2014-03-03 at 18:42 -0800, Dan Williams wrote:
> On Fri, 2014-02-28 at 15:18 -0800, Dan Williams wrote:
> > ClearPortFeature(PORT_POWER) on a usb3 port places the port in either a
> > DSPORT.Powered-off-detect / DSPORT.Powered-off-reset loop, or the
> > DSPORT.Powered-off state.  There is no way to ensure that RX
> > terminations will persist in this state, so it is possible a device will
> > degrade to its usb2 connection.  Prevent this by blocking power-off of a
> > usb3 port while its usb2 peer is active, and powering on a usb3 port
> > before its usb2 peer.
> > 
> > Signed-off-by: Dan Williams 
> 
> ...just rebasing:
> 
...and again, just a rebase, no functional changes.  link_peers() simply
moved locations port.c

8<-
Subject: usb: block suspension of superspeed port while hispeed peer is active

From: Dan Williams 

ClearPortFeature(PORT_POWER) on a usb3 port places the port in either a
DSPORT.Powered-off-detect / DSPORT.Powered-off-reset loop, or the
DSPORT.Powered-off state.  There is no way to ensure that RX
terminations will persist in this state, so it is possible a device will
degrade to its usb2 connection.  Prevent this by blocking power-off of a
usb3 port while its usb2 peer is active, and powering on a usb3 port
before its usb2 peer.

Signed-off-by: Dan Williams 
---
 drivers/usb/core/hub.c  |5 ---
 drivers/usb/core/hub.h  |5 +++
 drivers/usb/core/port.c |   72 +++
 3 files changed, 77 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
index c025edb90e1f..ea24f62e2a26 100644
--- a/drivers/usb/core/hub.c
+++ b/drivers/usb/core/hub.c
@@ -36,11 +36,6 @@
 #define USB_VENDOR_GENESYS_LOGIC   0x05e3
 #define HUB_QUIRK_CHECK_PORT_AUTOSUSPEND   0x01
 
-static inline int hub_is_superspeed(struct usb_device *hdev)
-{
-   return (hdev->descriptor.bDeviceProtocol == USB_HUB_PR_SS);
-}
-
 /* Protect struct usb_device->state and ->children members
  * Note: Both are also protected by ->dev.sem, except that ->state can
  * change to USB_STATE_NOTATTACHED even when the semaphore isn't held. */
diff --git a/drivers/usb/core/hub.h b/drivers/usb/core/hub.h
index 6858a55eceb5..45959767db8f 100644
--- a/drivers/usb/core/hub.h
+++ b/drivers/usb/core/hub.h
@@ -125,6 +125,11 @@ static inline bool hub_is_port_power_switchable(struct 
usb_hub *hub)
return (le16_to_cpu(hcs) & HUB_CHAR_LPSM) < HUB_CHAR_NO_LPSM;
 }
 
+static inline int hub_is_superspeed(struct usb_device *hdev)
+{
+   return hdev->descriptor.bDeviceProtocol == USB_HUB_PR_SS;
+}
+
 static inline int hub_port_debounce_be_connected(struct usb_hub *hub,
int port1)
 {
diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
index becdb5d6cffe..f6e356478174 100644
--- a/drivers/usb/core/port.c
+++ b/drivers/usb/core/port.c
@@ -76,12 +76,20 @@ static int usb_port_runtime_resume(struct device *dev)
struct usb_device *hdev = to_usb_device(dev->parent->parent);
struct usb_interface *intf = to_usb_interface(dev->parent);
struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
+   struct usb_port *peer = port_dev->peer;
int port1 = port_dev->portnum;
int retval;
 
if (!hub)
return -EINVAL;
 
+   /*
+* Power on our usb3 peer before this usb2 port to prevent a usb3
+* device from degrading to its usb2 connection
+*/
+   if (!hub_is_superspeed(hdev) && peer)
+   pm_runtime_get_sync(&peer->dev);
+
usb_autopm_get_interface(intf);
set_bit(port1, hub->busy_bits);
 
@@ -103,6 +111,7 @@ static int usb_port_runtime_resume(struct device *dev)
 
clear_bit(port1, hub->busy_bits);
usb_autopm_put_interface(intf);
+
return retval;
 }
 
@@ -112,6 +121,7 @@ static int usb_port_runtime_suspend(struct device *dev)
struct usb_device *hdev = to_usb_device(dev->parent->parent);
struct usb_interface *intf = to_usb_interface(dev->parent);
struct usb_hub *hub = usb_hub_to_struct_hub(hdev);
+   struct usb_port *peer = port_dev->peer;
int port1 = port_dev->portnum;
int retval;
 
@@ -129,6 +139,15 @@ static int usb_port_runtime_suspend(struct device *dev)
usb_clear_port_feature(hdev, port1, USB_PORT_FEAT_C_ENABLE);
clear_bit(port1, hub->busy_bits);
usb_autopm_put_interface(intf);
+
+   /*
+* Our peer usb3 port may now be able to suspend, asynchronously
+* queue a suspend request to observe that this usb2 peer port
+* is now off.
+*/
+   if (!hub_is_superspeed(hdev) && peer)
+   pm_runtime_put(&peer->dev);
+
return retval;
 }
 #endif
@@ -151,8 +170,26 @@ static struct device_driver usb_port_driver = {
.owner = THIS_MODULE,
 };
 
+/*
+ * Modifying ->peer affects usb_port_runtime_{suspend|resume} so make
+ * sure devices are active before the change and r

Re: [PATCH v6 part1 4/8] usb: assign default peer ports for root hubs

2014-03-05 Thread Alan Stern
On Wed, 5 Mar 2014, Dan Williams wrote:

> Please have a look at the following.  I'm sure Greg will be happy that
> we are killing these bugs before they become fodder for -stable.  Thanks

Wow, do you really think all these changes will ever go into -stable?  
I'm doubtful; they're rather large.

> for the review!  The other change I made was to convert
> find_default_peer to find_and_link_peer per your other comments about
> centralizing peering on patch 6.

Good idea, since it now finds all peers and not just the default ones.

> 8<-
> Subject: usb: assign default peer ports for root hubs
> 
> From: Dan Williams 
> 
> Assume that the peer of a superspeed port is the port with the same id
> on the shared_hcd root hub.  This identification scheme is required of
> external hubs by the USB3 spec [1].  However, for root hubs, tier mismatch
> may be in effect [2].  Tier mismatch can only be enumerated via platform
> firmware.  For now, simply perform the nominal association.
> 
> A new lock 'usb_port_peer_mutex' is introduced to synchronize port
> device add/remove with peer lookups.  It protects peering against
> changes to hcd->shared_hcd, hcd->self.root_hub, hdev->maxchild, and
> port_dev->child pointers.
> 
> [1]: usb 3.1 section 10.3.3
> [2]: xhci 1.1 appendix D
> 
> Cc: Alan Stern 
> [alan: usb_port_peer_mutex locking scheme]
> Signed-off-by: Dan Williams 

> diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
> index 531a591a7b1e..0d36610af156 100644
> --- a/drivers/usb/core/port.c
> +++ b/drivers/usb/core/port.c
> @@ -151,9 +151,66 @@ static struct device_driver usb_port_driver = {
>   .owner = THIS_MODULE,
>  };
>  
> +static void link_peers(struct usb_port *left, struct usb_port *right)
> +{
> + if (left->peer == right && right->peer == left)
> + return;
> +
> + if (left->peer || right->peer) {
> + struct usb_port *lpeer = left->peer;
> + struct usb_port *rpeer = right->peer;
> +
> + WARN(1, "failed to peer %s and %s (%s -> %p) (%s -> %p)\n",
> + dev_name(&left->dev), dev_name(&right->dev),
> + dev_name(&left->dev), lpeer,
> + dev_name(&right->dev), rpeer);
> + return;
> + }
> +
> + left->peer = right;
> + right->peer = left;
> +}
> +
> +static void unlink_peers(struct usb_port *left, struct usb_port *right)
> +{
> + WARN(right->peer != left || left->peer != right,
> + "%s and %s are not peers?\n",
> + dev_name(&left->dev), dev_name(&right->dev));

At some point, maybe we'll have enough confidence in the locking to 
remove all these checks.  :-)

Acked-by: Alan Stern 

Alan Stern

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 part1 5/8] usb: assign usb3 external hub port peers

2014-03-05 Thread Alan Stern
On Wed, 5 Mar 2014, Dan Williams wrote:

> 8<---
> Subject: usb: assign usb3 external hub port peers
> 
> From: Dan Williams 
> 
> Given that root hub port peers are already established, external hub peer
> ports can be determined by traversing the device topology:
> 
> 1/ ascend to the parent hub and find the upstream port_dev
> 
> 2/ walk ->peer to find the peer port
> 
> 3/ descend to the peer hub via ->child
> 
> 4/ find the port with the matching port id
> 
> Note that this assumes the port labeling scheme required by the
> specification [1].
> 
> [1]: usb3 3.1 section 10.3.3
> 
> Signed-off-by: Dan Williams 

Acked-by: Alan Stern 

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


Re: [PATCH v6 part1 4/8] usb: assign default peer ports for root hubs

2014-03-05 Thread Dan Williams
On Wed, Mar 5, 2014 at 12:18 PM, Alan Stern  wrote:
> On Wed, 5 Mar 2014, Dan Williams wrote:
>
>> Please have a look at the following.  I'm sure Greg will be happy that
>> we are killing these bugs before they become fodder for -stable.  Thanks
>
> Wow, do you really think all these changes will ever go into -stable?
> I'm doubtful; they're rather large.

Heck no :-).  I meant the later fixes for these bugs that we're
squashing at review time.

>> for the review!  The other change I made was to convert
>> find_default_peer to find_and_link_peer per your other comments about
>> centralizing peering on patch 6.
>
> Good idea, since it now finds all peers and not just the default ones.
>
>> 8<-
>> Subject: usb: assign default peer ports for root hubs
>>
>> From: Dan Williams 
>>
>> Assume that the peer of a superspeed port is the port with the same id
>> on the shared_hcd root hub.  This identification scheme is required of
>> external hubs by the USB3 spec [1].  However, for root hubs, tier mismatch
>> may be in effect [2].  Tier mismatch can only be enumerated via platform
>> firmware.  For now, simply perform the nominal association.
>>
>> A new lock 'usb_port_peer_mutex' is introduced to synchronize port
>> device add/remove with peer lookups.  It protects peering against
>> changes to hcd->shared_hcd, hcd->self.root_hub, hdev->maxchild, and
>> port_dev->child pointers.
>>
>> [1]: usb 3.1 section 10.3.3
>> [2]: xhci 1.1 appendix D
>>
>> Cc: Alan Stern 
>> [alan: usb_port_peer_mutex locking scheme]
>> Signed-off-by: Dan Williams 
>
>> diff --git a/drivers/usb/core/port.c b/drivers/usb/core/port.c
>> index 531a591a7b1e..0d36610af156 100644
>> --- a/drivers/usb/core/port.c
>> +++ b/drivers/usb/core/port.c
>> @@ -151,9 +151,66 @@ static struct device_driver usb_port_driver = {
>>   .owner = THIS_MODULE,
>>  };
>>
>> +static void link_peers(struct usb_port *left, struct usb_port *right)
>> +{
>> + if (left->peer == right && right->peer == left)
>> + return;
>> +
>> + if (left->peer || right->peer) {
>> + struct usb_port *lpeer = left->peer;
>> + struct usb_port *rpeer = right->peer;
>> +
>> + WARN(1, "failed to peer %s and %s (%s -> %p) (%s -> %p)\n",
>> + dev_name(&left->dev), dev_name(&right->dev),
>> + dev_name(&left->dev), lpeer,
>> + dev_name(&right->dev), rpeer);
>> + return;
>> + }
>> +
>> + left->peer = right;
>> + right->peer = left;
>> +}
>> +
>> +static void unlink_peers(struct usb_port *left, struct usb_port *right)
>> +{
>> + WARN(right->peer != left || left->peer != right,
>> + "%s and %s are not peers?\n",
>> + dev_name(&left->dev), dev_name(&right->dev));
>
> At some point, maybe we'll have enough confidence in the locking to
> remove all these checks.  :-)
>
> Acked-by: Alan Stern 

Cheers.
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


USB Host support for mx25

2014-03-05 Thread Fabio Estevam
Hi,

Has anyone succeeded on getting USB host support on mx25 with the
chipidea driver?

I am trying to add USB host1 support for mx25pdk and I am starting to
debug it, but


Looking at imx25.dtsi we have:

usbphy1: usbphy@1 {
compatible = "nop-usbphy";
status = "disabled";
};

usbphy2: usbphy@2 {
compatible = "nop-usbphy";
status = "disabled";
};

,but "nop-usbphy" is not defined anywhere.

Any help is appreciated.

Regards,

Fabio Estevam
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[PATCHv4] usb: dwc2: Add function to calculate correct FIFO sizes

2014-03-05 Thread dinguyen
From: Dinh Nguyen 

The dwc2 IP on the SOCFPGA cannot use the default HW configured
FIFO sizes. The total FIFO depth as read from GHWCFG3 reports 0x1f80 or 8064
32-bit words. But the GRXFSIZ, GNPTXFSIZ, and HPTXFSIZ register defaults
to 0x2000 or 8192 32-bit words. So the driver cannot just use the fifo sizes
as read from those registers.

For platforms that face the same issue, this commits sets the RX, periodic TX,
and non-periodic TX fifo size to those that are recommended v2.93a spec for
the DWC2 IP. Implements Method #2 from the Synopsys v2.93a spec for the DWC2.

Signed-off-by: Dinh Nguyen 
Acked-by: Paul Zimmerman 
Reviewed-by: Felipe Balbi 
---
v4:
- Fix comment style errors
- Use comment suggestion from Felipe to clearly commmunicate invalid fifo sizes
- Removed useless comment

v3:
- Address comments from Felipe
- Used Method 2 as recommended by Synopsys to high-bandwidth endpoints.

v2:
- Fix coding style with braces around both if() branches
---
 drivers/usb/dwc2/core.c |   68 +++
 1 file changed, 68 insertions(+)

diff --git a/drivers/usb/dwc2/core.c b/drivers/usb/dwc2/core.c
index 1d12988..a738d05 100644
--- a/drivers/usb/dwc2/core.c
+++ b/drivers/usb/dwc2/core.c
@@ -507,6 +507,72 @@ void dwc2_disable_host_interrupts(struct dwc2_hsotg *hsotg)
writel(intmsk, hsotg->regs + GINTMSK);
 }
 
+/*
+ * dwc2_calculate_dynamic_fifo() - Calculates the default fifo size
+ * For system that have a total fifo depth that is smaller than the default
+ * RX + TX fifo size.
+ *
+ * @hsotg: Programming view of DWC_otg controller
+ */
+static void dwc2_calculate_dynamic_fifo(struct dwc2_hsotg *hsotg)
+{
+   struct dwc2_core_params *params = hsotg->core_params;
+   struct dwc2_hw_params *hw = &hsotg->hw_params;
+   u32 rxfsiz, nptxfsiz, ptxfsiz, total_fifo_size;
+
+   total_fifo_size = hw->total_fifo_size;
+   rxfsiz = params->host_rx_fifo_size;
+   nptxfsiz = params->host_nperio_tx_fifo_size;
+   ptxfsiz = params->host_perio_tx_fifo_size;
+
+   /*
+* Will use Method 2 defined in the DWC2 spec: minimum FIFO depth
+* allocation with support for high bandwidth endpoints. Synopsys
+* defines MPS(Max Packet size) for a periodic EP=1024, and for
+* non-periodic as 512.
+*/
+   if (total_fifo_size < (rxfsiz + nptxfsiz + ptxfsiz)) {
+   /*
+* For Buffer DMA mode/Scatter Gather DMA mode
+* 2 * ((Largest Packet size / 4) + 1 + 1) + n
+* with n = number of host channel.
+* 2 * ((1024/4) + 2) = 516
+*/
+   rxfsiz = 516 + hw->host_channels;
+
+   /*
+* min non-periodic tx fifo depth
+* 2 * (largest non-periodic USB packet used / 4)
+* 2 * (512/4) = 256
+*/
+   nptxfsiz = 256;
+
+   /*
+* min periodic tx fifo depth
+* (largest packet size*MC)/4
+* (1024 * 3)/4 = 768
+*/
+   ptxfsiz = 768;
+
+   params->host_rx_fifo_size = rxfsiz;
+   params->host_nperio_tx_fifo_size = nptxfsiz;
+   params->host_perio_tx_fifo_size = ptxfsiz;
+   }
+
+   /*
+* If the summation of RX, NPTX and PTX fifo sizes is still
+* bigger than the total_fifo_size, then we have a problem.
+*
+* We won't be able to allocate as many endpoints. Right now,
+* we're just printing an error message, but ideally this FIFO
+* allocation algorithm would be improved in the future.
+*
+* FIXME improve this FIFO allocation algorithm.
+*/
+   if (unlikely(total_fifo_size < (rxfsiz + nptxfsiz + ptxfsiz))
+   dev_err(hsotg->dev, "invalid fifo sizes\n");
+}
+
 static void dwc2_config_fifos(struct dwc2_hsotg *hsotg)
 {
struct dwc2_core_params *params = hsotg->core_params;
@@ -515,6 +581,8 @@ static void dwc2_config_fifos(struct dwc2_hsotg *hsotg)
if (!params->enable_dynamic_fifo)
return;
 
+   dwc2_calculate_dynamic_fifo(hsotg);
+
/* Rx FIFO */
grxfsiz = readl(hsotg->regs + GRXFSIZ);
dev_dbg(hsotg->dev, "initial grxfsiz=%08x\n", grxfsiz);
-- 
1.7.9.5

--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html


  1   2   >