aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
authorMichal Nazarewicz <m.nazarewicz@samsung.com>2010-06-16 06:07:59 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2010-08-10 17:35:36 -0400
commitf2adc4f8aaf272de9ac71dcb18d95ebe05fc3f94 (patch)
tree07b92ce8914bca169edbf5e0852a3c93bea81e4b /drivers/usb/gadget
parent7898aee1dacbb246fee958f0a6102320b61768d9 (diff)
USB: gadget: composite: usb_string_ids_*() functions added
usb_string_ids_tab() and usb_string_ids_n() functions added to the composite framework. The first accepts an array of usb_string object and for each registeres a string id and the second registeres a given number of ids and returns the first. This may simplify string ids registration since gadgets and composite functions won't have to call usb_string_id() several times and each time check for errer status -- all this will be done with a single call. Signed-off-by: Michal Nazarewicz <m.nazarewicz@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/composite.c71
1 files changed, 67 insertions, 4 deletions
diff --git a/drivers/usb/gadget/composite.c b/drivers/usb/gadget/composite.c
index 391d169f8d07..125167e17ce5 100644
--- a/drivers/usb/gadget/composite.c
+++ b/drivers/usb/gadget/composite.c
@@ -673,20 +673,83 @@ static int get_string(struct usb_composite_dev *cdev,
673 * string IDs. Drivers for functions, configurations, or gadgets will 673 * string IDs. Drivers for functions, configurations, or gadgets will
674 * then store that ID in the appropriate descriptors and string table. 674 * then store that ID in the appropriate descriptors and string table.
675 * 675 *
676 * All string identifier should be allocated using this routine, to 676 * All string identifier should be allocated using this,
677 * ensure that for example different functions don't wrongly assign 677 * @usb_string_ids_tab() or @usb_string_ids_n() routine, to ensure
678 * different meanings to the same identifier. 678 * that for example different functions don't wrongly assign different
679 * meanings to the same identifier.
679 */ 680 */
680int usb_string_id(struct usb_composite_dev *cdev) 681int usb_string_id(struct usb_composite_dev *cdev)
681{ 682{
682 if (cdev->next_string_id < 254) { 683 if (cdev->next_string_id < 254) {
683 /* string id 0 is reserved */ 684 /* string id 0 is reserved by USB spec for list of
685 * supported languages */
686 /* 255 reserved as well? -- mina86 */
684 cdev->next_string_id++; 687 cdev->next_string_id++;
685 return cdev->next_string_id; 688 return cdev->next_string_id;
686 } 689 }
687 return -ENODEV; 690 return -ENODEV;
688} 691}
689 692
693/**
694 * usb_string_ids() - allocate unused string IDs in batch
695 * @cdev: the device whose string descriptor IDs are being allocated
696 * @str: an array of usb_string objects to assign numbers to
697 * Context: single threaded during gadget setup
698 *
699 * @usb_string_ids() is called from bind() callbacks to allocate
700 * string IDs. Drivers for functions, configurations, or gadgets will
701 * then copy IDs from the string table to the appropriate descriptors
702 * and string table for other languages.
703 *
704 * All string identifier should be allocated using this,
705 * @usb_string_id() or @usb_string_ids_n() routine, to ensure that for
706 * example different functions don't wrongly assign different meanings
707 * to the same identifier.
708 */
709int usb_string_ids_tab(struct usb_composite_dev *cdev, struct usb_string *str)
710{
711 int next = cdev->next_string_id;
712
713 for (; str->s; ++str) {
714 if (unlikely(next >= 254))
715 return -ENODEV;
716 str->id = ++next;
717 }
718
719 cdev->next_string_id = next;
720
721 return 0;
722}
723
724/**
725 * usb_string_ids_n() - allocate unused string IDs in batch
726 * @cdev: the device whose string descriptor IDs are being allocated
727 * @n: number of string IDs to allocate
728 * Context: single threaded during gadget setup
729 *
730 * Returns the first requested ID. This ID and next @n-1 IDs are now
731 * valid IDs. At least providind that @n is non zore because if it
732 * is, returns last requested ID which is now very useful information.
733 *
734 * @usb_string_ids_n() is called from bind() callbacks to allocate
735 * string IDs. Drivers for functions, configurations, or gadgets will
736 * then store that ID in the appropriate descriptors and string table.
737 *
738 * All string identifier should be allocated using this,
739 * @usb_string_id() or @usb_string_ids_n() routine, to ensure that for
740 * example different functions don't wrongly assign different meanings
741 * to the same identifier.
742 */
743int usb_string_ids_n(struct usb_composite_dev *c, unsigned n)
744{
745 unsigned next = c->next_string_id;
746 if (unlikely(n > 254 || (unsigned)next + n > 254))
747 return -ENODEV;
748 c->next_string_id += n;
749 return next + 1;
750}
751
752
690/*-------------------------------------------------------------------------*/ 753/*-------------------------------------------------------------------------*/
691 754
692static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req) 755static void composite_setup_complete(struct usb_ep *ep, struct usb_request *req)