Received: by 2002:a05:6a10:d5a5:0:0:0:0 with SMTP id gn37csp1204480pxb; Fri, 1 Oct 2021 05:58:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwZJRkfRwEjN1+0RRq6/ygs1WBCsExwmH0tOfvS8bL/zMExfD7CvJf75I90FdGIFt0m4tWR X-Received: by 2002:a50:9d44:: with SMTP id j4mr14381653edk.173.1633093081957; Fri, 01 Oct 2021 05:58:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633093081; cv=none; d=google.com; s=arc-20160816; b=oqW8BNHo6TT8Uv2rTEWuUL3AymfwOuQ2KT2Usl/2BoDTLPCW/o1Po3z8H809aWD0pZ sCrbtbZCjXhTUVgjMmF5o93qxNoCrpBNAl6sOun5E649YoArDAHvn5gFDT8d6CIf2CeB sEwmdqhIyA8ZksAe073n/sOP8N/p4TlOqUr5zCw+r/34RJZGoFWyobdEBsLXCHXRsyhU Tup+3hnX8gFRc9wR4jPIHK/saRJYgHMLEjugIe6z6UnyzNqcmSBuCtNChPbYaYc1pj8Y yPLuLFOqF+k8jsAsRfMvl72wR1y0hi0iCtBtNBfFTIdjYIegY60x47HwV35gwwd1HEzi 0D/Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3POZSfd3i3rRjFBmejsX8EHhkanjDD2SzvXm5wj7xu0=; b=j1F/Su3h7RN4Q23eajRSl2BEjyZYv3kOZB06wqWKyUjGw0EoD4PS+DMEbfB+zuCjbq b0+bxEXOrTKtEnPPSoywfELJV54ufqDdildlk/2vUeRnTmFEXfEI9KsrPhrgW2Y7kkv0 +okgO0pvk2CvSEHL7vQwrP+ocPDle+/kU0JSxcMmZ4hPAA7JLAXFu71zxitKK5gGMYOc oogZnEyQDDyM1vGUZcV9oa/UIh8HHh2rewdWCrKLBeZbZ1JsuRmaZSYM4blRBCpgqwPN KS22aa34Vrf3VeywfVg1twBI9Colvo8tkOsM7AeOWm1DwE+kasN3NBpN/K8zvrf9SDBT xeTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Lf4FLJqg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u4si8294462ejt.53.2021.10.01.05.57.37; Fri, 01 Oct 2021 05:58:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Lf4FLJqg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353850AbhJAL1c (ORCPT + 99 others); Fri, 1 Oct 2021 07:27:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353751AbhJAL1L (ORCPT ); Fri, 1 Oct 2021 07:27:11 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 373B7C06177B for ; Fri, 1 Oct 2021 04:25:27 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id j27so6997863wms.0 for ; Fri, 01 Oct 2021 04:25:27 -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 :mime-version:content-transfer-encoding; bh=3POZSfd3i3rRjFBmejsX8EHhkanjDD2SzvXm5wj7xu0=; b=Lf4FLJqg3BajSlJoxu2QV1n7yHssEl/qRsfWd1c5h3WshXNw9lFtXjnRubG0B6Vzwr mKXy0eGlKZfRrAxmCq1mQ3Qz/XQauR0Tiv1o0Vt+DtbDPN9O+NudL2pEft+fC36oKO7r nU9v/QiYzjXg/QXm9AOX5pjBUOeCax2YsZaNE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3POZSfd3i3rRjFBmejsX8EHhkanjDD2SzvXm5wj7xu0=; b=1WfpI8dsMYBDov9w7AiuF6SYvrX6rclJkvHnJyg+9sJBV6JNS832yrd+NXx62iA2od Yrpj5tYx3+zWaAJrhju8+ObO3m3NydSA8bUE8WrsRXgLSYKm0AF9NZajOfANjB8epCjS 5G9rHfz9kxQw6UdcMls566pNbg9PKNSe+T99pbnoLeKbAce04gtHvWMY6KufTDpHDDov NXOQinsuJ/JOcBxW0uWAvg+PAp/HmGDElYjsdXCurjWoJJdnB//sgcnb4yHJ/D3E2yHV ccknnoRe0dTkZp8dDNtH2lZrbckRaUT5/Po0KW0I69rtQsqxmFdVSAZJ8DSbx4b51JMG tGRA== X-Gm-Message-State: AOAM530nA8N5iaqEyJIikg4nvnkHtsgGHx5NWGWCvI0AUKT56XzsOBTL QkvI5Y2YkKoQbTv8Yq/d7pJWuw== X-Received: by 2002:a05:600c:1c93:: with SMTP id k19mr3955263wms.80.1633087525831; Fri, 01 Oct 2021 04:25:25 -0700 (PDT) Received: from beni.c.googlers.com.com (216.131.76.34.bc.googleusercontent.com. [34.76.131.216]) by smtp.gmail.com with ESMTPSA id x17sm5530958wrc.51.2021.10.01.04.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 01 Oct 2021 04:25:25 -0700 (PDT) From: Ricardo Ribalda To: Mauro Carvalho Chehab , Yong Zhi , Bingbu Cao , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Chiranjeevi Rapolu , Sakari Ailus Cc: Ricardo Ribalda Subject: [PATCH v3 2/8] media: ipu3-imgu: Refactor bytesperpixel calculation Date: Fri, 1 Oct 2021 11:25:16 +0000 Message-Id: <20211001112522.2839602-3-ribalda@chromium.org> X-Mailer: git-send-email 2.33.0.800.g4c38ced690-goog In-Reply-To: <20211001112522.2839602-1-ribalda@chromium.org> References: <20211001112522.2839602-1-ribalda@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Move the calculation to an inline function, to it can be used by other parts of the driver. Signed-off-by: Ricardo Ribalda --- drivers/staging/media/ipu3/ipu3-css.c | 19 +++---------------- drivers/staging/media/ipu3/ipu3-css.h | 1 - drivers/staging/media/ipu3/ipu3.h | 12 ++++++++++++ 3 files changed, 15 insertions(+), 17 deletions(-) diff --git a/drivers/staging/media/ipu3/ipu3-css.c b/drivers/staging/media/ipu3/ipu3-css.c index 608dcacf12b2c..8c70497d744c9 100644 --- a/drivers/staging/media/ipu3/ipu3-css.c +++ b/drivers/staging/media/ipu3/ipu3-css.c @@ -5,6 +5,7 @@ #include #include +#include "ipu3.h" #include "ipu3-css.h" #include "ipu3-css-fw.h" #include "ipu3-css-params.h" @@ -53,7 +54,6 @@ static const struct imgu_css_format imgu_css_formats[] = { .frame_format = IMGU_ABI_FRAME_FORMAT_NV12, .osys_format = IMGU_ABI_OSYS_FORMAT_NV12, .osys_tiling = IMGU_ABI_OSYS_TILING_NONE, - .bytesperpixel_num = 1 * IPU3_CSS_FORMAT_BPP_DEN, .chroma_decim = 4, .width_align = IPU3_UAPI_ISP_VEC_ELEMS, .flags = IPU3_CSS_FORMAT_FL_OUT | IPU3_CSS_FORMAT_FL_VF, @@ -64,7 +64,6 @@ static const struct imgu_css_format imgu_css_formats[] = { .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED, .bayer_order = IMGU_ABI_BAYER_ORDER_BGGR, .bit_depth = 10, - .bytesperpixel_num = 64, .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS, .flags = IPU3_CSS_FORMAT_FL_IN, }, { @@ -73,7 +72,6 @@ static const struct imgu_css_format imgu_css_formats[] = { .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED, .bayer_order = IMGU_ABI_BAYER_ORDER_GBRG, .bit_depth = 10, - .bytesperpixel_num = 64, .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS, .flags = IPU3_CSS_FORMAT_FL_IN, }, { @@ -82,7 +80,6 @@ static const struct imgu_css_format imgu_css_formats[] = { .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED, .bayer_order = IMGU_ABI_BAYER_ORDER_GRBG, .bit_depth = 10, - .bytesperpixel_num = 64, .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS, .flags = IPU3_CSS_FORMAT_FL_IN, }, { @@ -91,7 +88,6 @@ static const struct imgu_css_format imgu_css_formats[] = { .frame_format = IMGU_ABI_FRAME_FORMAT_RAW_PACKED, .bayer_order = IMGU_ABI_BAYER_ORDER_RGGB, .bit_depth = 10, - .bytesperpixel_num = 64, .width_align = 2 * IPU3_UAPI_ISP_VEC_ELEMS, .flags = IPU3_CSS_FORMAT_FL_IN, }, @@ -150,17 +146,8 @@ static int imgu_css_queue_init(struct imgu_css_queue *queue, f->height = ALIGN(clamp_t(u32, f->height, IPU3_CSS_MIN_RES, IPU3_CSS_MAX_H), 2); queue->width_pad = ALIGN(f->width, queue->css_fmt->width_align); - if (queue->css_fmt->frame_format != IMGU_ABI_FRAME_FORMAT_RAW_PACKED) - f->plane_fmt[0].bytesperline = DIV_ROUND_UP(queue->width_pad * - queue->css_fmt->bytesperpixel_num, - IPU3_CSS_FORMAT_BPP_DEN); - else - /* For packed raw, alignment for bpl is by 50 to the width */ - f->plane_fmt[0].bytesperline = - DIV_ROUND_UP(f->width, - IPU3_CSS_FORMAT_BPP_DEN) * - queue->css_fmt->bytesperpixel_num; - + f->plane_fmt[0].bytesperline = + imgu_bytesperline(f->width, queue->css_fmt->frame_format); sizeimage = f->height * f->plane_fmt[0].bytesperline; if (queue->css_fmt->chroma_decim) sizeimage += 2 * sizeimage / queue->css_fmt->chroma_decim; diff --git a/drivers/staging/media/ipu3/ipu3-css.h b/drivers/staging/media/ipu3/ipu3-css.h index 6108a068b228f..ab64e95212032 100644 --- a/drivers/staging/media/ipu3/ipu3-css.h +++ b/drivers/staging/media/ipu3/ipu3-css.h @@ -82,7 +82,6 @@ struct imgu_css_format { enum imgu_abi_bayer_order bayer_order; enum imgu_abi_osys_format osys_format; enum imgu_abi_osys_tiling osys_tiling; - u32 bytesperpixel_num; /* Bytes per pixel in first plane * 50 */ u8 bit_depth; /* Effective bits per pixel */ u8 chroma_decim; /* Chroma plane decimation, 0=no chroma plane */ u8 width_align; /* Alignment requirement for width_pad */ diff --git a/drivers/staging/media/ipu3/ipu3.h b/drivers/staging/media/ipu3/ipu3.h index eb46b527dd233..d2ad0a95c5aab 100644 --- a/drivers/staging/media/ipu3/ipu3.h +++ b/drivers/staging/media/ipu3/ipu3.h @@ -164,4 +164,16 @@ void imgu_v4l2_buffer_done(struct vb2_buffer *vb, enum vb2_buffer_state state); int imgu_s_stream(struct imgu_device *imgu, int enable); +static inline u32 imgu_bytesperline(const unsigned int width, + enum imgu_abi_frame_format frame_format) +{ + if (frame_format == IMGU_ABI_FRAME_FORMAT_NV12) + return ALIGN(width, IPU3_UAPI_ISP_VEC_ELEMS); + /* + * 64 bytes for every 50 pixels, the line length + * in bytes is multiple of 64 (line end alignment). + */ + return DIV_ROUND_UP(width, 50) * 64; +} + #endif -- 2.33.0.800.g4c38ced690-goog