From patchwork Fri Aug 30 02:17:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pawel Osciak X-Patchwork-Id: 2851727 Return-Path: X-Original-To: patchwork-linux-media@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id BD25CC0AB5 for ; Fri, 30 Aug 2013 02:18:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id C5B38201CD for ; Fri, 30 Aug 2013 02:18:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2F3B42018D for ; Fri, 30 Aug 2013 02:18:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754885Ab3H3CRo (ORCPT ); Thu, 29 Aug 2013 22:17:44 -0400 Received: from mail-pd0-f172.google.com ([209.85.192.172]:50501 "EHLO mail-pd0-f172.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754297Ab3H3CRn (ORCPT ); Thu, 29 Aug 2013 22:17:43 -0400 Received: by mail-pd0-f172.google.com with SMTP id z10so1228841pdj.17 for ; Thu, 29 Aug 2013 19:17:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=mSIcuAi4dT2jP78Yrr98FEtjDHnpnsvOADYpGtDhblU=; b=XigDv5/xJgC22U4t15ymyHwDqRsj0EpCgFHinKEZt7zngzf9nR2Bpn1ouZna5f2rxd 7/RpLHIN65WyXDJ3sibeiR9nvLa4+9nhuqlN+icKo9IX51lzUWVEkt2XJxGF9+22CKTm HDcyh88FfMaX7ZfieQHgqu85TMZRTlHg+6NNU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=mSIcuAi4dT2jP78Yrr98FEtjDHnpnsvOADYpGtDhblU=; b=gjWBXEebBxd+LI2pTSyd/HJD27J2eYWMWvIEfjQY2kVoAKLUM3DEmFBGmYZMSoNGZE P45eZgDFEWXo1agCaiI7TjMYnuDPSAKwZ0Tgl8XY6VF9RDgiD+zCIGYmr7QNgPQEvb2o reeJt9pvvBFpUQ0MBiAuKy6JD1VW6xc/7z+OG4aRg6BuIiooF4t5abgUOE0n1GiV06XN w2coAfbBnVOJvUHEOw2SosmSkEpLr1T7QRZu3ctwyhAoOGY+8uuDho2ulZbRWwAqlyTF juX0zl48hZT4qxb5QW7FYNRrd+f/TzPA+kD7KsawjzG0IQoKXLvPr5CUrbXRDJ6YOTls e47g== X-Gm-Message-State: ALoCoQn1s94xAjey+loVSUQwQ+KfB5UitMz30QXeABDQydw9I89f5NqupCgxJT5OSJzK8mhnSjIx X-Received: by 10.66.191.5 with SMTP id gu5mr7559889pac.126.1377829062870; Thu, 29 Aug 2013 19:17:42 -0700 (PDT) Received: from kawagoe.tok.corp.google.com (kawagoe.tok.corp.google.com [172.30.88.114]) by mx.google.com with ESMTPSA id ye1sm27935254pab.19.1969.12.31.16.00.00 (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 29 Aug 2013 19:17:42 -0700 (PDT) From: Pawel Osciak To: linux-media@vger.kernel.org Cc: laurent.pinchart@ideasonboard.com, Pawel Osciak Subject: [PATCH v1 09/19] uvcvideo: Reorganize uvc_{get,set}_le_value. Date: Fri, 30 Aug 2013 11:17:08 +0900 Message-Id: <1377829038-4726-10-git-send-email-posciak@chromium.org> X-Mailer: git-send-email 1.8.4 In-Reply-To: <1377829038-4726-1-git-send-email-posciak@chromium.org> References: <1377829038-4726-1-git-send-email-posciak@chromium.org> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Spam-Status: No, score=-9.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Pawel Osciak --- drivers/media/usb/uvc/uvc_ctrl.c | 62 ++++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/drivers/media/usb/uvc/uvc_ctrl.c b/drivers/media/usb/uvc/uvc_ctrl.c index 72d6724..d735c88 100644 --- a/drivers/media/usb/uvc/uvc_ctrl.c +++ b/drivers/media/usb/uvc/uvc_ctrl.c @@ -707,18 +707,12 @@ static inline void uvc_clear_bit(__u8 *data, int bit) data[bit >> 3] &= ~(1 << (bit & 7)); } -/* Extract the bit string specified by mapping->offset and mapping->size - * from the little-endian data stored at 'data' and return the result as - * a signed 32bit integer. Sign extension will be performed if the mapping - * references a signed data type. - */ -static __s32 uvc_get_le_value(struct uvc_control_mapping *mapping, - __u8 query, const __u8 *data) +static int __uvc_get_le_value(int bits, int offset, const __u8 *data, + __u32 data_type) { - int bits = mapping->size; - int offset = mapping->offset; __s32 value = 0; __u8 mask; + int size = bits; data += offset / 8; offset &= 7; @@ -733,22 +727,49 @@ static __s32 uvc_get_le_value(struct uvc_control_mapping *mapping, } /* Sign-extend the value if needed. */ - if (mapping->data_type == UVC_CTRL_DATA_TYPE_SIGNED) - value |= -(value & (1 << (mapping->size - 1))); + if (data_type == UVC_CTRL_DATA_TYPE_SIGNED) + value |= -(value & (1 << (size - 1))); return value; } +/* Extract the bit string specified by mapping->offset and mapping->size + * from the little-endian data stored at 'data' and return the result as + * a signed 32bit integer. Sign extension will be performed if the mapping + * references a signed data type. + */ +static __s32 uvc_get_le_value(struct uvc_control_mapping *mapping, + __u8 query, const __u8 *data) +{ + return __uvc_get_le_value(mapping->size, mapping->offset, data, + mapping->data_type); +} + +static void __uvc_set_le_value(int bits, int offset, __s32 value, __u8 *data, + bool keep_existing) +{ + __u8 mask; + + data += offset / 8; + offset &= 7; + + for (; bits > 0; data++) { + mask = ((1LL << bits) - 1) << offset; + if (!keep_existing) + *data = (*data & ~mask); + *data |= ((value << offset) & mask); + value >>= (8 - offset); + bits -= 8 - offset; + offset = 0; + } +} + /* Set the bit string specified by mapping->offset and mapping->size * in the little-endian data stored at 'data' to the value 'value'. */ static void uvc_set_le_value(struct uvc_control_mapping *mapping, __s32 value, __u8 *data) { - int bits = mapping->size; - int offset = mapping->offset; - __u8 mask; - /* According to the v4l2 spec, writing any value to a button control * should result in the action belonging to the button control being * triggered. UVC devices however want to see a 1 written -> override @@ -757,16 +778,7 @@ static void uvc_set_le_value(struct uvc_control_mapping *mapping, if (mapping->v4l2_type == V4L2_CTRL_TYPE_BUTTON) value = -1; - data += offset / 8; - offset &= 7; - - for (; bits > 0; data++) { - mask = ((1LL << bits) - 1) << offset; - *data = (*data & ~mask) | ((value << offset) & mask); - value >>= offset ? offset : 8; - bits -= 8 - offset; - offset = 0; - } + __uvc_set_le_value(mapping->size, mapping->offset, value, data, false); } /* ------------------------------------------------------------------------