usb: gadget: uvc: Make color matching attributes read/write
authorDaniel Scally <dan.scally@ideasonboard.com>
Thu, 2 Feb 2023 11:41:41 +0000 (11:41 +0000)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 6 Feb 2023 12:46:43 +0000 (13:46 +0100)
In preparation for allowing more than the default color matching
descriptor, make the color matching attributes writeable.

Signed-off-by: Daniel Scally <dan.scally@ideasonboard.com>
Link: https://lore.kernel.org/r/20230202114142.300858-6-dan.scally@ideasonboard.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Documentation/ABI/testing/configfs-usb-gadget-uvc
drivers/usb/gadget/function/uvc_configfs.c

index eb13cc5d363ae3dee634668b364301f842dd8022..ef3b8b852cd2492f6accc53c17f800f122ca7625 100644 (file)
@@ -167,7 +167,7 @@ Date:               Dec 2014
 KernelVersion: 4.0
 Description:   Default color matching descriptors
 
-               All attributes read only:
+               All attributes read/write:
 
                ========================  ======================================
                bMatrixCoefficients       matrix used to compute luma and
index 56e23b80d63ff8580fb9b6cd193a2c4618107ab5..a210b199008085c7e36645548e87dcc010f0e8fa 100644 (file)
@@ -1904,7 +1904,44 @@ static ssize_t uvcg_color_matching_##cname##_show(                       \
        return result;                                                  \
 }                                                                      \
                                                                        \
-UVC_ATTR_RO(uvcg_color_matching_, cname, aname)
+static ssize_t uvcg_color_matching_##cname##_store(                    \
+       struct config_item *item, const char *page, size_t len)         \
+{                                                                      \
+       struct config_group *group = to_config_group(item);             \
+       struct mutex *su_mutex = &group->cg_subsys->su_mutex;           \
+       struct uvcg_color_matching *color_match =                       \
+               to_uvcg_color_matching(group);                          \
+       struct f_uvc_opts *opts;                                        \
+       struct config_item *opts_item;                                  \
+       int ret;                                                        \
+       u##bits num;                                                    \
+                                                                       \
+       ret = kstrtou##bits(page, 0, &num);                             \
+       if (ret)                                                        \
+               return ret;                                             \
+                                                                       \
+       mutex_lock(su_mutex); /* for navigating configfs hierarchy */   \
+                                                                       \
+       if (color_match->refcnt) {                                      \
+               ret = -EBUSY;                                           \
+               goto unlock_su;                                         \
+       }                                                               \
+                                                                       \
+       opts_item = group->cg_item.ci_parent->ci_parent->ci_parent;     \
+       opts = to_f_uvc_opts(opts_item);                                \
+                                                                       \
+       mutex_lock(&opts->lock);                                        \
+                                                                       \
+       color_match->desc.aname = num;                                  \
+       ret = len;                                                      \
+                                                                       \
+       mutex_unlock(&opts->lock);                                      \
+unlock_su:                                                             \
+       mutex_unlock(su_mutex);                                         \
+                                                                       \
+       return ret;                                                     \
+}                                                                      \
+UVC_ATTR(uvcg_color_matching_, cname, aname)
 
 UVCG_COLOR_MATCHING_ATTR(b_color_primaries, bColorPrimaries, 8);
 UVCG_COLOR_MATCHING_ATTR(b_transfer_characteristics, bTransferCharacteristics, 8);