diff options
author | Michal Nazarewicz <mina86@mina86.com> | 2011-08-30 11:11:19 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2011-09-18 04:29:04 -0400 |
commit | e538dfdae85244fd2c4231725d82cc1f1bc4942c (patch) | |
tree | f8471dd9af305b95557d29a30f427c85418b1621 /drivers/usb/gadget/langwell_udc.c | |
parent | c58a76cdd7ab5a945a44fd2d64f6faf40323f95b (diff) |
usb: Provide usb_speed_string() function
In a few places in the kernel, the code prints
a human-readable USB device speed (eg. "high speed").
This involves a switch statement sometimes wrapped
around in ({ ... }) block leading to code repetition.
To mitigate this issue, this commit introduces
usb_speed_string() function, which returns
a human-readable name of provided speed.
It also changes a few places switch was used to use
this new function. This changes a bit the way the
speed is printed in few instances at the same time
standardising it.
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/gadget/langwell_udc.c')
-rw-r--r-- | drivers/usb/gadget/langwell_udc.c | 50 |
1 files changed, 17 insertions, 33 deletions
diff --git a/drivers/usb/gadget/langwell_udc.c b/drivers/usb/gadget/langwell_udc.c index 6e444995d398..c88158f307a8 100644 --- a/drivers/usb/gadget/langwell_udc.c +++ b/drivers/usb/gadget/langwell_udc.c | |||
@@ -1690,20 +1690,7 @@ static ssize_t show_langwell_udc(struct device *_dev, | |||
1690 | "BmAttributes: %d\n\n", | 1690 | "BmAttributes: %d\n\n", |
1691 | LPM_PTS(tmp_reg), | 1691 | LPM_PTS(tmp_reg), |
1692 | (tmp_reg & LPM_STS) ? 1 : 0, | 1692 | (tmp_reg & LPM_STS) ? 1 : 0, |
1693 | ({ | 1693 | usb_speed_string(lpm_device_speed(tmp_reg)), |
1694 | char *s; | ||
1695 | switch (LPM_PSPD(tmp_reg)) { | ||
1696 | case LPM_SPEED_FULL: | ||
1697 | s = "Full Speed"; break; | ||
1698 | case LPM_SPEED_LOW: | ||
1699 | s = "Low Speed"; break; | ||
1700 | case LPM_SPEED_HIGH: | ||
1701 | s = "High Speed"; break; | ||
1702 | default: | ||
1703 | s = "Unknown Speed"; break; | ||
1704 | } | ||
1705 | s; | ||
1706 | }), | ||
1707 | (tmp_reg & LPM_PFSC) ? "Force Full Speed" : "Not Force", | 1694 | (tmp_reg & LPM_PFSC) ? "Force Full Speed" : "Not Force", |
1708 | (tmp_reg & LPM_PHCD) ? "Disabled" : "Enabled", | 1695 | (tmp_reg & LPM_PHCD) ? "Disabled" : "Enabled", |
1709 | LPM_BA(tmp_reg)); | 1696 | LPM_BA(tmp_reg)); |
@@ -2647,12 +2634,24 @@ done: | |||
2647 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); | 2634 | dev_vdbg(&dev->pdev->dev, "<--- %s()\n", __func__); |
2648 | } | 2635 | } |
2649 | 2636 | ||
2637 | static inline enum usb_device_speed lpm_device_speed(u32 reg) | ||
2638 | { | ||
2639 | switch (LPM_PSPD(reg)) { | ||
2640 | case LPM_SPEED_HIGH: | ||
2641 | return USB_SPEED_HIGH; | ||
2642 | case LPM_SPEED_FULL: | ||
2643 | return USB_SPEED_FULL; | ||
2644 | case LPM_SPEED_LOW: | ||
2645 | return USB_SPEED_LOW; | ||
2646 | default: | ||
2647 | return USB_SPEED_UNKNOWN; | ||
2648 | } | ||
2649 | } | ||
2650 | 2650 | ||
2651 | /* port change detect interrupt handler */ | 2651 | /* port change detect interrupt handler */ |
2652 | static void handle_port_change(struct langwell_udc *dev) | 2652 | static void handle_port_change(struct langwell_udc *dev) |
2653 | { | 2653 | { |
2654 | u32 portsc1, devlc; | 2654 | u32 portsc1, devlc; |
2655 | u32 speed; | ||
2656 | 2655 | ||
2657 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); | 2656 | dev_vdbg(&dev->pdev->dev, "---> %s()\n", __func__); |
2658 | 2657 | ||
@@ -2667,24 +2666,9 @@ static void handle_port_change(struct langwell_udc *dev) | |||
2667 | /* bus reset is finished */ | 2666 | /* bus reset is finished */ |
2668 | if (!(portsc1 & PORTS_PR)) { | 2667 | if (!(portsc1 & PORTS_PR)) { |
2669 | /* get the speed */ | 2668 | /* get the speed */ |
2670 | speed = LPM_PSPD(devlc); | 2669 | dev->gadget.speed = lpm_device_speed(devlc); |
2671 | switch (speed) { | 2670 | dev_vdbg(&dev->pdev->dev, "dev->gadget.speed = %d\n", |
2672 | case LPM_SPEED_HIGH: | 2671 | dev->gadget.speed); |
2673 | dev->gadget.speed = USB_SPEED_HIGH; | ||
2674 | break; | ||
2675 | case LPM_SPEED_FULL: | ||
2676 | dev->gadget.speed = USB_SPEED_FULL; | ||
2677 | break; | ||
2678 | case LPM_SPEED_LOW: | ||
2679 | dev->gadget.speed = USB_SPEED_LOW; | ||
2680 | break; | ||
2681 | default: | ||
2682 | dev->gadget.speed = USB_SPEED_UNKNOWN; | ||
2683 | break; | ||
2684 | } | ||
2685 | dev_vdbg(&dev->pdev->dev, | ||
2686 | "speed = %d, dev->gadget.speed = %d\n", | ||
2687 | speed, dev->gadget.speed); | ||
2688 | } | 2672 | } |
2689 | 2673 | ||
2690 | /* LPM L0 to L1 */ | 2674 | /* LPM L0 to L1 */ |