From nobody Thu Nov 28 19:46:26 2024 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 55C15149C6D; Fri, 27 Sep 2024 15:22:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727450556; cv=none; b=ti2gFCrdl3JYgXCgULEoDEVtdeP1TercXKvdcPn2/GTJRkscGQaPWmxQuqRW8Z2QjiIgi8mmRmH0rBXaHibPxUL4uYJ9XD8EdlEsuTm2MXwx14hzNf1cQa5B0EecrdngkIygZnC11sntZG8QcBJQx+PuQ5KaraVe+jmki0N5yM4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1727450556; c=relaxed/simple; bh=Z23+G7mPee2zuA9JCRsVSEWFoggcyeK/wonPDXsB49Q=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=bvtzQ6jR8sJsOcVe2LZk+JWQT6SSLl4N+FT5ThIm0zKzhC0O3laORBlEu+hCV9fWLHEa1pHgS9D33bZKX+ECPTlLYgkmCC7vHmto/8MzJV56fN4KFQ+tZxyKrnQDdRkE9oLXurX4uuS+V6sd/gvz2fLifiKHwJZZEphm/nmsJ20= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=a0wBAZkC; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="a0wBAZkC" Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48RFDuPL026381; Fri, 27 Sep 2024 15:22:26 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-type:date:from:message-id:mime-version:subject:to; s= qcppdkim1; bh=xnFW1svEdvEpYi0CJlDfQ6zH263RrZetg070gOA/tbk=; b=a0 wBAZkCrBTx8d4m8RO3ssIACboKrDPEUT9sWKopKCOa721LBGfCvoJYwb6cseutRB XW1Ce2ol5UC24C6v9XWObebwMRsN59oSq3WtgE/r/UkaRVV1QYs3pvWk0fs3L8zx QpEALi9t4OPF4bEqrZuPfTug3I4MsQOGEkHbyUL01udIj4Xm2UVNb3WKVQJlqmuy 8A1JOayHBYHWlXftLSjW0ivjCok2ekt5IkPfGLb683liX6voncDbLQ2e9pC3PgyQ tZhm+1uSguPz6sacU83/hZGYz6GOedaPZCsEO/zPglQOeS7E/297vyj342HoM5QZ JIvXXnRDIhai1/nJ4Q2w== Received: from nasanppmta03.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41snfhbmqn-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Sep 2024 15:22:25 +0000 (GMT) Received: from nasanex01a.na.qualcomm.com (nasanex01a.na.qualcomm.com [10.52.223.231]) by NASANPPMTA03.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 48RFMO9Z000487 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 27 Sep 2024 15:22:24 GMT Received: from hu-akakum-hyd.qualcomm.com (10.80.80.8) by nasanex01a.na.qualcomm.com (10.52.223.231) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.9; Fri, 27 Sep 2024 08:22:17 -0700 From: Akash Kumar To: Thinh Nguyen , Greg Kroah-Hartman , Felipe Balbi , Jack Pham , , Wesley Cheng , Laurent Pinchart , Daniel Scally CC: Vijayavardhan Vennapusa , Krishna Kurapati , , , Akash Kumar Subject: [PATCH v3] usb: gadget: uvc: configfs: Add frame-based frame format support Date: Fri, 27 Sep 2024 20:51:38 +0530 Message-ID: <20240927152138.31416-1-quic_akakum@quicinc.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nasanex01b.na.qualcomm.com (10.46.141.250) To nasanex01a.na.qualcomm.com (10.52.223.231) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: JcLVtBATsMH0XueYreBty6jf2D9pJQtL X-Proofpoint-GUID: JcLVtBATsMH0XueYreBty6jf2D9pJQtL X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1011 adultscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 mlxscore=0 suspectscore=0 impostorscore=0 spamscore=0 phishscore=0 mlxlogscore=999 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409270110 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add support for frame-based frame format, which can be used to support multiple formats like H264 or H265, in addition to MJPEG and YUV frames. The frame-based format is set to H264 by default, but it can be updated to other formats by modifying the GUID through the guid configfs attribute. Different structures are used for all three formats, as H264 has a different structure compared to MJPEG and uncompressed formats. These structures will be passed to the frame make function based on the active format, using a common frame structure with additional parameters needed only for frame-based formats. These parameters are handled at runtime in the UVC driver. Signed-off-by: Akash Kumar --- Changes for v3: Added framebased format support without impacting existing formats and used same frame structure and handled the different paramters within the uvc driver code so userspace libraries not need to change. Changes for v2: https://lore.kernel.org/all/20240711082304.1363-1-quic_akakum@quicinc.com/ Added Documentation for new format details. Changes for v1: https://lore.kernel.org/all/20240708041328.1942-1-quic_akakum@quicinc.com/ Added framebased format support. --- .../ABI/testing/configfs-usb-gadget-uvc | 64 ++++ drivers/usb/gadget/function/uvc_configfs.c | 348 +++++++++++++++++- drivers/usb/gadget/function/uvc_configfs.h | 16 + drivers/usb/gadget/function/uvc_v4l2.c | 11 +- include/uapi/linux/usb/video.h | 58 +++ 5 files changed, 485 insertions(+), 12 deletions(-) diff --git a/Documentation/ABI/testing/configfs-usb-gadget-uvc b/Documentat= ion/ABI/testing/configfs-usb-gadget-uvc index 4feb692c4c1d..b6720768d63d 100644 --- a/Documentation/ABI/testing/configfs-usb-gadget-uvc +++ b/Documentation/ABI/testing/configfs-usb-gadget-uvc @@ -342,6 +342,70 @@ Description: Specific uncompressed frame descriptors support =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =20 +What: /config/usb-gadget/gadget/functions/uvc.name/streaming/fra= mebased +Date: Sept 2024 +KernelVersion: 5.15 +Description: Framebased format descriptors + +What: /config/usb-gadget/gadget/functions/uvc.name/streaming/fra= mebased/name +Date: Sept 2024 +KernelVersion: 5.15 +Description: Specific framebased format descriptors + + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + bFormatIndex unique id for this format descript= or; + only defined after parent header is + linked into the streaming class; + read-only + bmaControls this format's data for bmaControls= in + the streaming header + bmInterlaceFlags specifies interlace information, + read-only + bAspectRatioY the X dimension of the picture asp= ect + ratio, read-only + bAspectRatioX the Y dimension of the picture asp= ect + ratio, read-only + bDefaultFrameIndex optimum frame index for this stream + bBitsPerPixel number of bits per pixel used to + specify color in the decoded video + frame + guidFormat globally unique id used to identify + stream-encoding format + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D = =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +What: /config/usb-gadget/gadget/functions/uvc.name/streaming/fra= mebased/name/name +Date: Sept 2024 +KernelVersion: 5.15 +Description: Specific framebased frame descriptors + + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + bFrameIndex unique id for this framedescrip= tor; + only defined after parent forma= t is + linked into the streaming heade= r; + read-only + dwFrameInterval indicates how frame interval ca= n be + programmed; a number of values + separated by newline can be spe= cified + dwDefaultFrameInterval the frame interval the device w= ould + like to use as default + dwBytesPerLine Specifies the number of bytes p= er line + of video for packed fixed frame= size + formats, allowing the receiver = to + perform stride alignment of the= video. + If the bVariableSize value (abo= ve) is + TRUE (1), or if the format does= not + permit such alignment, this val= ue shall + be set to zero (0). + dwMaxBitRate the maximum bit rate at the sho= rtest + frame interval in bps + dwMinBitRate the minimum bit rate at the lon= gest + frame interval in bps + wHeight height of decoded bitmap frame = in px + wWidth width of decoded bitmam frame i= n px + bmCapabilities still image support, fixed fram= e-rate + support + =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + What: /config/usb-gadget/gadget/functions/uvc.name/streaming/header Date: Dec 2014 KernelVersion: 4.0 diff --git a/drivers/usb/gadget/function/uvc_configfs.c b/drivers/usb/gadge= t/function/uvc_configfs.c index 6fac696ea846..f131943254a4 100644 --- a/drivers/usb/gadget/function/uvc_configfs.c +++ b/drivers/usb/gadget/function/uvc_configfs.c @@ -1566,11 +1566,13 @@ static const struct uvcg_config_group_type uvcg_con= trol_grp_type =3D { /* -----------------------------------------------------------------------= ------ * streaming/uncompressed * streaming/mjpeg + * streaming/framebased */ =20 static const char * const uvcg_format_names[] =3D { "uncompressed", "mjpeg", + "framebased", }; =20 static struct uvcg_color_matching * @@ -1777,6 +1779,9 @@ static int uvcg_streaming_header_allow_link(struct co= nfig_item *src, target_fmt =3D container_of(to_config_group(target), struct uvcg_format, group); =20 + if (!target_fmt) + goto out; + uvcg_format_set_indices(to_config_group(target)); =20 format_ptr =3D kzalloc(sizeof(*format_ptr), GFP_KERNEL); @@ -1816,6 +1821,9 @@ static void uvcg_streaming_header_drop_link(struct co= nfig_item *src, target_fmt =3D container_of(to_config_group(target), struct uvcg_format, group); =20 + if (!target_fmt) + goto out; + list_for_each_entry_safe(format_ptr, tmp, &src_hdr->formats, entry) if (format_ptr->fmt =3D=3D target_fmt) { list_del(&format_ptr->entry); @@ -1826,6 +1834,7 @@ static void uvcg_streaming_header_drop_link(struct co= nfig_item *src, =20 --target_fmt->linked; =20 +out: mutex_unlock(&opts->lock); mutex_unlock(su_mutex); } @@ -2022,6 +2031,7 @@ UVCG_FRAME_ATTR(dw_min_bit_rate, dwMinBitRate, 32); UVCG_FRAME_ATTR(dw_max_bit_rate, dwMaxBitRate, 32); UVCG_FRAME_ATTR(dw_max_video_frame_buffer_size, dwMaxVideoFrameBufferSize,= 32); UVCG_FRAME_ATTR(dw_default_frame_interval, dwDefaultFrameInterval, 32); +UVCG_FRAME_ATTR(dw_bytes_perline, dwBytesPerLine, 32); =20 #undef UVCG_FRAME_ATTR =20 @@ -2035,7 +2045,7 @@ static ssize_t uvcg_frame_dw_frame_interval_show(stru= ct config_item *item, int result, i; char *pg =3D page; =20 - mutex_lock(su_mutex); /* for navigating configfs hierarchy */ + mutex_lock(su_mutex); /* for navigating configfs hierarchy */ =20 opts_item =3D frm->item.ci_parent->ci_parent->ci_parent->ci_parent; opts =3D to_f_uvc_opts(opts_item); @@ -2105,7 +2115,7 @@ static ssize_t uvcg_frame_dw_frame_interval_store(str= uct config_item *item, =20 UVC_ATTR(uvcg_frame_, dw_frame_interval, dwFrameInterval); =20 -static struct configfs_attribute *uvcg_frame_attrs[] =3D { +static struct configfs_attribute *uvcg_frame_attrs1[] =3D { &uvcg_frame_attr_b_frame_index, &uvcg_frame_attr_bm_capabilities, &uvcg_frame_attr_w_width, @@ -2118,12 +2128,31 @@ static struct configfs_attribute *uvcg_frame_attrs[= ] =3D { NULL, }; =20 -static const struct config_item_type uvcg_frame_type =3D { +static struct configfs_attribute *uvcg_frame_attrs2[] =3D { + &uvcg_frame_attr_b_frame_index, + &uvcg_frame_attr_bm_capabilities, + &uvcg_frame_attr_w_width, + &uvcg_frame_attr_w_height, + &uvcg_frame_attr_dw_min_bit_rate, + &uvcg_frame_attr_dw_max_bit_rate, + &uvcg_frame_attr_dw_default_frame_interval, + &uvcg_frame_attr_dw_frame_interval, + &uvcg_frame_attr_dw_bytes_perline, + NULL, +}; + +static const struct config_item_type uvcg_frame_type1 =3D { .ct_item_ops =3D &uvcg_config_item_ops, - .ct_attrs =3D uvcg_frame_attrs, + .ct_attrs =3D uvcg_frame_attrs1, .ct_owner =3D THIS_MODULE, }; =20 +static const struct config_item_type uvcg_frame_type2 =3D { + .ct_item_ops =3D &uvcg_config_item_ops, + .ct_attrs =3D uvcg_frame_attrs2, + .ct_owner =3D THIS_MODULE, +}; + static struct config_item *uvcg_frame_make(struct config_group *group, const char *name) { @@ -2145,6 +2174,7 @@ static struct config_item *uvcg_frame_make(struct con= fig_group *group, h->frame.dw_max_bit_rate =3D 55296000; h->frame.dw_max_video_frame_buffer_size =3D 460800; h->frame.dw_default_frame_interval =3D 666666; + h->frame.dw_bytes_perline =3D 0; =20 opts_item =3D group->cg_item.ci_parent->ci_parent->ci_parent; opts =3D to_f_uvc_opts(opts_item); @@ -2157,6 +2187,9 @@ static struct config_item *uvcg_frame_make(struct con= fig_group *group, } else if (fmt->type =3D=3D UVCG_MJPEG) { h->frame.b_descriptor_subtype =3D UVC_VS_FRAME_MJPEG; h->fmt_type =3D UVCG_MJPEG; + } else if (fmt->type =3D=3D UVCG_FRAMEBASED) { + h->frame.b_descriptor_subtype =3D UVC_VS_FRAME_FRAME_BASED; + h->fmt_type =3D UVCG_FRAMEBASED; } else { mutex_unlock(&opts->lock); kfree(h); @@ -2175,7 +2208,10 @@ static struct config_item *uvcg_frame_make(struct co= nfig_group *group, ++fmt->num_frames; mutex_unlock(&opts->lock); =20 - config_item_init_type_name(&h->item, name, &uvcg_frame_type); + if (fmt->type =3D=3D UVCG_FRAMEBASED) + config_item_init_type_name(&h->item, name, &uvcg_frame_type2); + else + config_item_init_type_name(&h->item, name, &uvcg_frame_type1); =20 return &h->item; } @@ -2215,9 +2251,6 @@ static void uvcg_format_set_indices(struct config_gro= up *fmt) list_for_each_entry(ci, &fmt->cg_children, ci_entry) { struct uvcg_frame *frm; =20 - if (ci->ci_type !=3D &uvcg_frame_type) - continue; - frm =3D to_uvcg_frame(ci); frm->frame.b_frame_index =3D i++; } @@ -2677,6 +2710,251 @@ static const struct uvcg_config_group_type uvcg_mjp= eg_grp_type =3D { .name =3D "mjpeg", }; =20 +/* -----------------------------------------------------------------------= ------ + * streaming/framebased/ + */ + +static struct configfs_group_operations uvcg_framebased_group_ops =3D { + .make_item =3D uvcg_frame_make, + .drop_item =3D uvcg_frame_drop, +}; + +#define UVCG_FRAMEBASED_ATTR_RO(cname, aname, bits) \ +static ssize_t uvcg_framebased_##cname##_show(struct config_item *item, \ + char *page) \ +{ \ + struct uvcg_framebased *u =3D to_uvcg_framebased(item); \ + struct f_uvc_opts *opts; \ + struct config_item *opts_item; \ + struct mutex *su_mutex =3D &u->fmt.group.cg_subsys->su_mutex; \ + int result; \ + \ + mutex_lock(su_mutex); /* for navigating configfs hierarchy */ \ + \ + opts_item =3D u->fmt.group.cg_item.ci_parent->ci_parent->ci_parent;\ + opts =3D to_f_uvc_opts(opts_item); \ + \ + mutex_lock(&opts->lock); \ + result =3D sprintf(page, "%u\n", le##bits##_to_cpu(u->desc.aname));\ + mutex_unlock(&opts->lock); \ + \ + mutex_unlock(su_mutex); \ + return result; \ +} \ + \ +UVC_ATTR_RO(uvcg_framebased_, cname, aname) + +#define UVCG_FRAMEBASED_ATTR(cname, aname, bits) \ +static ssize_t uvcg_framebased_##cname##_show(struct config_item *item, \ + char *page) \ +{ \ + struct uvcg_framebased *u =3D to_uvcg_framebased(item); \ + struct f_uvc_opts *opts; \ + struct config_item *opts_item; \ + struct mutex *su_mutex =3D &u->fmt.group.cg_subsys->su_mutex; \ + int result; \ + \ + mutex_lock(su_mutex); /* for navigating configfs hierarchy */ \ + \ + opts_item =3D u->fmt.group.cg_item.ci_parent->ci_parent->ci_parent;\ + opts =3D to_f_uvc_opts(opts_item); \ + \ + mutex_lock(&opts->lock); \ + result =3D sprintf(page, "%u\n", le##bits##_to_cpu(u->desc.aname));\ + mutex_unlock(&opts->lock); \ + \ + mutex_unlock(su_mutex); \ + return result; \ +} \ + \ +static ssize_t \ +uvcg_framebased_##cname##_store(struct config_item *item, \ + const char *page, size_t len) \ +{ \ + struct uvcg_framebased *u =3D to_uvcg_framebased(item); \ + struct f_uvc_opts *opts; \ + struct config_item *opts_item; \ + struct mutex *su_mutex =3D &u->fmt.group.cg_subsys->su_mutex; \ + int ret; \ + u8 num; \ + \ + mutex_lock(su_mutex); /* for navigating configfs hierarchy */ \ + \ + opts_item =3D u->fmt.group.cg_item.ci_parent->ci_parent->ci_parent;\ + opts =3D to_f_uvc_opts(opts_item); \ + \ + mutex_lock(&opts->lock); \ + if (u->fmt.linked || opts->refcnt) { \ + ret =3D -EBUSY; \ + goto end; \ + } \ + \ + ret =3D kstrtou8(page, 0, &num); \ + if (ret) \ + goto end; \ + \ + if (num > 255) { \ + ret =3D -EINVAL; \ + goto end; \ + } \ + u->desc.aname =3D num; \ + ret =3D len; \ +end: \ + mutex_unlock(&opts->lock); \ + mutex_unlock(su_mutex); \ + return ret; \ +} \ + \ +UVC_ATTR(uvcg_framebased_, cname, aname) + +UVCG_FRAMEBASED_ATTR_RO(b_format_index, bFormatIndex, 8); +UVCG_FRAMEBASED_ATTR_RO(b_bits_per_pixel, bBitsPerPixel, 8); +UVCG_FRAMEBASED_ATTR(b_default_frame_index, bDefaultFrameIndex, 8); +UVCG_FRAMEBASED_ATTR_RO(b_aspect_ratio_x, bAspectRatioX, 8); +UVCG_FRAMEBASED_ATTR_RO(b_aspect_ratio_y, bAspectRatioY, 8); +UVCG_FRAMEBASED_ATTR_RO(bm_interface_flags, bmInterfaceFlags, 8); + +#undef UVCG_FRAMEBASED_ATTR +#undef UVCG_FRAMEBASED_ATTR_RO + +static ssize_t uvcg_framebased_guid_format_show(struct config_item *item, + char *page) +{ + struct uvcg_framebased *ch =3D to_uvcg_framebased(item); + struct f_uvc_opts *opts; + struct config_item *opts_item; + struct mutex *su_mutex =3D &ch->fmt.group.cg_subsys->su_mutex; + + mutex_lock(su_mutex); /* for navigating configfs hierarchy */ + + opts_item =3D ch->fmt.group.cg_item.ci_parent->ci_parent->ci_parent; + opts =3D to_f_uvc_opts(opts_item); + + mutex_lock(&opts->lock); + memcpy(page, ch->desc.guidFormat, sizeof(ch->desc.guidFormat)); + mutex_unlock(&opts->lock); + + mutex_unlock(su_mutex); + + return sizeof(ch->desc.guidFormat); +} + +static ssize_t uvcg_framebased_guid_format_store(struct config_item *item, + const char *page, size_t len) +{ + struct uvcg_framebased *ch =3D to_uvcg_framebased(item); + struct f_uvc_opts *opts; + struct config_item *opts_item; + struct mutex *su_mutex =3D &ch->fmt.group.cg_subsys->su_mutex; + int ret; + + mutex_lock(su_mutex); /* for navigating configfs hierarchy */ + + opts_item =3D ch->fmt.group.cg_item.ci_parent->ci_parent->ci_parent; + opts =3D to_f_uvc_opts(opts_item); + + mutex_lock(&opts->lock); + if (ch->fmt.linked || opts->refcnt) { + ret =3D -EBUSY; + goto end; + } + + memcpy(ch->desc.guidFormat, page, + min(sizeof(ch->desc.guidFormat), len)); + ret =3D sizeof(ch->desc.guidFormat); + +end: + mutex_unlock(&opts->lock); + mutex_unlock(su_mutex); + return ret; +} + +UVC_ATTR(uvcg_framebased_, guid_format, guidFormat); + +static inline ssize_t +uvcg_framebased_bma_controls_show(struct config_item *item, char *page) +{ + struct uvcg_framebased *u =3D to_uvcg_framebased(item); + + return uvcg_format_bma_controls_show(&u->fmt, page); +} + +static inline ssize_t +uvcg_framebased_bma_controls_store(struct config_item *item, + const char *page, size_t len) +{ + struct uvcg_framebased *u =3D to_uvcg_framebased(item); + + return uvcg_format_bma_controls_store(&u->fmt, page, len); +} + +UVC_ATTR(uvcg_framebased_, bma_controls, bmaControls); + +static struct configfs_attribute *uvcg_framebased_attrs[] =3D { + &uvcg_framebased_attr_b_format_index, + &uvcg_framebased_attr_b_default_frame_index, + &uvcg_framebased_attr_b_bits_per_pixel, + &uvcg_framebased_attr_b_aspect_ratio_x, + &uvcg_framebased_attr_b_aspect_ratio_y, + &uvcg_framebased_attr_bm_interface_flags, + &uvcg_framebased_attr_bma_controls, + &uvcg_framebased_attr_guid_format, + NULL, +}; + +static const struct config_item_type uvcg_framebased_type =3D { + .ct_item_ops =3D &uvcg_config_item_ops, + .ct_group_ops =3D &uvcg_framebased_group_ops, + .ct_attrs =3D uvcg_framebased_attrs, + .ct_owner =3D THIS_MODULE, +}; + +static struct config_group *uvcg_framebased_make(struct config_group *grou= p, + const char *name) +{ + static char guid[] =3D { /*Declear frame based as H264 format*/ + 'H', '2', '6', '4', 0x00, 0x00, 0x10, 0x00, + 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 + }; + struct uvcg_framebased *h; + + h =3D kzalloc(sizeof(*h), GFP_KERNEL); + if (!h) + return ERR_PTR(-ENOMEM); + + h->desc.bLength =3D UVC_DT_FORMAT_FRAMEBASED_SIZE; + h->desc.bDescriptorType =3D USB_DT_CS_INTERFACE; + h->desc.bDescriptorSubType =3D UVC_VS_FORMAT_FRAME_BASED; + memcpy(h->desc.guidFormat, guid, sizeof(guid)); + h->desc.bBitsPerPixel =3D 0; + h->desc.bDefaultFrameIndex =3D 1; + h->desc.bAspectRatioX =3D 0; + h->desc.bAspectRatioY =3D 0; + h->desc.bmInterfaceFlags =3D 0; + h->desc.bCopyProtect =3D 0; + h->desc.bVariableSize =3D 1; + + INIT_LIST_HEAD(&h->fmt.frames); + h->fmt.type =3D UVCG_FRAMEBASED; + config_group_init_type_name(&h->fmt.group, name, + &uvcg_framebased_type); + + return &h->fmt.group; +} + +static struct configfs_group_operations uvcg_framebased_grp_ops =3D { + .make_group =3D uvcg_framebased_make, +}; + +static const struct uvcg_config_group_type uvcg_framebased_grp_type =3D { + .type =3D { + .ct_item_ops =3D &uvcg_config_item_ops, + .ct_group_ops =3D &uvcg_framebased_grp_ops, + .ct_owner =3D THIS_MODULE, + }, + .name =3D "framebased", +}; + /* -----------------------------------------------------------------------= ------ * streaming/color_matching/default */ @@ -2912,6 +3190,7 @@ static int __uvcg_iter_strm_cls(struct uvcg_streaming= _header *h, if (ret) return ret; grp =3D &f->fmt->group; + j =3D 0; list_for_each_entry(item, &grp->cg_children, ci_entry) { frm =3D to_uvcg_frame(item); ret =3D fun(frm, priv2, priv3, j++, UVCG_FRAME); @@ -2965,6 +3244,11 @@ static int __uvcg_cnt_strm(void *priv1, void *priv2,= void *priv3, int n, container_of(fmt, struct uvcg_mjpeg, fmt); =20 *size +=3D sizeof(m->desc); + } else if (fmt->type =3D=3D UVCG_FRAMEBASED) { + struct uvcg_framebased *f =3D + container_of(fmt, struct uvcg_framebased, fmt); + + *size +=3D sizeof(f->desc); } else { return -EINVAL; } @@ -2975,6 +3259,11 @@ static int __uvcg_cnt_strm(void *priv1, void *priv2,= void *priv3, int n, int sz =3D sizeof(frm->dw_frame_interval); =20 *size +=3D sizeof(frm->frame); + /* + * framebased has duplicate member with uncompressed and + * mjpeg, so minus it + */ + *size -=3D sizeof(u32); *size +=3D frm->frame.b_frame_interval_type * sz; } break; @@ -2991,6 +3280,27 @@ static int __uvcg_cnt_strm(void *priv1, void *priv2,= void *priv3, int n, return 0; } =20 +static int __uvcg_copy_framebased_desc(void *dest, struct uvcg_frame *frm, + int sz) +{ + struct uvc_frame_framebased *desc =3D dest; + + desc->bLength =3D frm->frame.b_length; + desc->bDescriptorType =3D frm->frame.b_descriptor_type; + desc->bDescriptorSubType =3D frm->frame.b_descriptor_subtype; + desc->bFrameIndex =3D frm->frame.b_frame_index; + desc->bmCapabilities =3D frm->frame.bm_capabilities; + desc->wWidth =3D frm->frame.w_width; + desc->wHeight =3D frm->frame.w_height; + desc->dwMinBitRate =3D frm->frame.dw_min_bit_rate; + desc->dwMaxBitRate =3D frm->frame.dw_max_bit_rate; + desc->dwDefaultFrameInterval =3D frm->frame.dw_default_frame_interval; + desc->bFrameIntervalType =3D frm->frame.b_frame_interval_type; + desc->dwBytesPerLine =3D frm->frame.dw_bytes_perline; + + return 0; +} + /* * Fill an array of streaming descriptors. * @@ -3045,6 +3355,15 @@ static int __uvcg_fill_strm(void *priv1, void *priv2= , void *priv3, int n, m->desc.bNumFrameDescriptors =3D fmt->num_frames; memcpy(*dest, &m->desc, sizeof(m->desc)); *dest +=3D sizeof(m->desc); + } else if (fmt->type =3D=3D UVCG_FRAMEBASED) { + struct uvcg_framebased *f =3D + container_of(fmt, struct uvcg_framebased, + fmt); + + f->desc.bFormatIndex =3D n + 1; + f->desc.bNumFrameDescriptors =3D fmt->num_frames; + memcpy(*dest, &f->desc, sizeof(f->desc)); + *dest +=3D sizeof(f->desc); } else { return -EINVAL; } @@ -3054,8 +3373,11 @@ static int __uvcg_fill_strm(void *priv1, void *priv2= , void *priv3, int n, struct uvcg_frame *frm =3D priv1; struct uvc_descriptor_header *h =3D *dest; =20 - sz =3D sizeof(frm->frame); - memcpy(*dest, &frm->frame, sz); + sz =3D sizeof(frm->frame) - 4; + if (frm->fmt_type !=3D UVCG_FRAMEBASED) + memcpy(*dest, &frm->frame, sz); + else + __uvcg_copy_framebased_desc(*dest, frm, sz); *dest +=3D sz; sz =3D frm->frame.b_frame_interval_type * sizeof(*frm->dw_frame_interval); @@ -3066,7 +3388,10 @@ static int __uvcg_fill_strm(void *priv1, void *priv2= , void *priv3, int n, frm->frame.b_frame_interval_type); else if (frm->fmt_type =3D=3D UVCG_MJPEG) h->bLength =3D UVC_DT_FRAME_MJPEG_SIZE( - frm->frame.b_frame_interval_type); + frm->frame.b_frame_interval_type); + else if (frm->fmt_type =3D=3D UVCG_FRAMEBASED) + h->bLength =3D UVC_DT_FRAME_FRAMEBASED_SIZE( + frm->frame.b_frame_interval_type); } break; case UVCG_COLOR_MATCHING: { @@ -3285,6 +3610,7 @@ static const struct uvcg_config_group_type uvcg_strea= ming_grp_type =3D { &uvcg_streaming_header_grp_type, &uvcg_uncompressed_grp_type, &uvcg_mjpeg_grp_type, + &uvcg_framebased_grp_type, &uvcg_color_matching_grp_type, &uvcg_streaming_class_grp_type, NULL, diff --git a/drivers/usb/gadget/function/uvc_configfs.h b/drivers/usb/gadge= t/function/uvc_configfs.h index c6a690158138..2f78cd4f396f 100644 --- a/drivers/usb/gadget/function/uvc_configfs.h +++ b/drivers/usb/gadget/function/uvc_configfs.h @@ -49,6 +49,7 @@ container_of(group_ptr, struct uvcg_color_matching, group) enum uvcg_format_type { UVCG_UNCOMPRESSED =3D 0, UVCG_MJPEG, + UVCG_FRAMEBASED, }; =20 struct uvcg_format { @@ -105,6 +106,7 @@ struct uvcg_frame { u32 dw_max_video_frame_buffer_size; u32 dw_default_frame_interval; u8 b_frame_interval_type; + u32 dw_bytes_perline; } __attribute__((packed)) frame; u32 *dw_frame_interval; }; @@ -142,6 +144,20 @@ static inline struct uvcg_mjpeg *to_uvcg_mjpeg(struct = config_item *item) return container_of(to_uvcg_format(item), struct uvcg_mjpeg, fmt); } =20 +/* -----------------------------------------------------------------------= ------ + * streaming/framebased/ + */ + +struct uvcg_framebased { + struct uvcg_format fmt; + struct uvc_format_framebased desc; +}; + +static inline struct uvcg_framebased *to_uvcg_framebased(struct config_ite= m *item) +{ + return container_of(to_uvcg_format(item), struct uvcg_framebased, fmt); +} + /* -----------------------------------------------------------------------= ------ * control/extensions/ */ diff --git a/drivers/usb/gadget/function/uvc_v4l2.c b/drivers/usb/gadget/fu= nction/uvc_v4l2.c index de1736f834e6..836b91c73f18 100644 --- a/drivers/usb/gadget/function/uvc_v4l2.c +++ b/drivers/usb/gadget/function/uvc_v4l2.c @@ -31,13 +31,22 @@ static const struct uvc_format_desc *to_uvc_format(stru= ct uvcg_format *uformat) { char guid[16] =3D UVC_GUID_FORMAT_MJPEG; const struct uvc_format_desc *format; - struct uvcg_uncompressed *unc; =20 if (uformat->type =3D=3D UVCG_UNCOMPRESSED) { + struct uvcg_uncompressed *unc; + unc =3D to_uvcg_uncompressed(&uformat->group.cg_item); if (!unc) return ERR_PTR(-EINVAL); =20 + memcpy(guid, unc->desc.guidFormat, sizeof(guid)); + } else if (uformat->type =3D=3D UVCG_FRAMEBASED) { + struct uvcg_framebased *unc; + + unc =3D to_uvcg_framebased(&uformat->group.cg_item); + if (!unc) + return ERR_PTR(-EINVAL); + memcpy(guid, unc->desc.guidFormat, sizeof(guid)); } =20 diff --git a/include/uapi/linux/usb/video.h b/include/uapi/linux/usb/video.h index 2ff0e8a3a683..526b5155e23c 100644 --- a/include/uapi/linux/usb/video.h +++ b/include/uapi/linux/usb/video.h @@ -597,5 +597,63 @@ struct UVC_FRAME_MJPEG(n) { \ __le32 dwFrameInterval[n]; \ } __attribute__ ((packed)) =20 +/* Frame Based Payload - 3.1.1. Frame Based Video Format Descriptor */ +struct uvc_format_framebased { + __u8 bLength; + __u8 bDescriptorType; + __u8 bDescriptorSubType; + __u8 bFormatIndex; + __u8 bNumFrameDescriptors; + __u8 guidFormat[16]; + __u8 bBitsPerPixel; + __u8 bDefaultFrameIndex; + __u8 bAspectRatioX; + __u8 bAspectRatioY; + __u8 bmInterfaceFlags; + __u8 bCopyProtect; + __u8 bVariableSize; +} __attribute__((__packed__)); + +#define UVC_DT_FORMAT_FRAMEBASED_SIZE 28 + +/* Frame Based Payload - 3.1.2. Frame Based Video Frame Descriptor */ +struct uvc_frame_framebased { + __u8 bLength; + __u8 bDescriptorType; + __u8 bDescriptorSubType; + __u8 bFrameIndex; + __u8 bmCapabilities; + __u16 wWidth; + __u16 wHeight; + __u32 dwMinBitRate; + __u32 dwMaxBitRate; + __u32 dwDefaultFrameInterval; + __u8 bFrameIntervalType; + __u32 dwBytesPerLine; + __u32 dwFrameInterval[]; +} __attribute__((__packed__)); + +#define UVC_DT_FRAME_FRAMEBASED_SIZE(n) (26+4*(n)) + +#define UVC_FRAME_FRAMEBASED(n) \ + uvc_frame_framebased_##n + +#define DECLARE_UVC_FRAME_FRAMEBASED(n) \ +struct UVC_FRAME_FRAMEBASED(n) { \ + __u8 bLength; \ + __u8 bDescriptorType; \ + __u8 bDescriptorSubType; \ + __u8 bFrameIndex; \ + __u8 bmCapabilities; \ + __u16 wWidth; \ + __u16 wHeight; \ + __u32 dwMinBitRate; \ + __u32 dwMaxBitRate; \ + __u32 dwDefaultFrameInterval; \ + __u8 bFrameIntervalType; \ + __u32 dwBytesPerLine; \ + __u32 dwFrameInterval[n]; \ +} __attribute__ ((packed)) + #endif /* __LINUX_USB_VIDEO_H */ =20 --=20 2.17.1