Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1591130pxb; Thu, 4 Nov 2021 05:13:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxl3xw0rAnes6IyT9Y2I9iZrR5vmKJUcI/iCqYDNeqvqwq842/CZo0InUWjUxXnGIBErvKS X-Received: by 2002:a05:600c:1549:: with SMTP id f9mr101212wmg.118.1636027982202; Thu, 04 Nov 2021 05:13:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636027982; cv=none; d=google.com; s=arc-20160816; b=RucIIoU6F/uVv2mz9f49x1xjKSh3FfZGb3vbR5ZZ6tk68JkUfqpa14K+vsmvmhBOTs 1mfzw7rFKTJwM5FEKPoHZjEJbDUqZGi9Tr36Wq+1NbrlULG2tL6xSiS824Th+6iwUGio pPhU0zW6jwA/5J3l0s+vP+zHuyT3uV+2SQOiFx2JAbmzCbby3Y5d3Te8KVTvxbA77eCd LsHBWs9+688R+OHTFYLEwW2XlY3mtAJK5uW/Ekmxq8tWmvw+0/KwZ8JPtjgB+QPqDPiV nyERRRnLJ9dW3EeD9bxNT62ErU9NXkAAkTco0gAVJc+cKbHdiWh9CCvmsJrz9/cZjizu iOWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=WgHaQFKP35V2mof0pLz1SjfxYyzSg36jKsWjiyKpHfw=; b=uwzcyW4Se6daFrl2dx28yYXJbm1Z+Ej8tU2o0KOd05AY702Gb4T/ZcNMaUhRGGtTvx hOj0KXpLMGy6M15vCabvm5QvhroyZokXrG2UVZQMMiq0gOus0tAHUYf5xpOV98bOwoRc ArxOjm2M71M+oLzEbg8PBqwW02VefUbaWGuP+2dg5gZeTmgRlW0OB9BnAL3GL1WxtnSi evv307mWuF3DroapFDgi4x8WGH22zGE+SHp4Aw+vRFc3+gBw7sS18Xw+dbIy081/emWh JDsn1qiqI0qL9K2nOYeyn+WmB2hT12lWtekOs5M0a1WJjS7+ZskYRAXiDDo6oIv3OeDp IhEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b="pC/fzFjR"; 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=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a15si7357332edr.394.2021.11.04.05.12.36; Thu, 04 Nov 2021 05:13:02 -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=fail header.i=@kernel.org header.s=k20201202 header.b="pC/fzFjR"; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231650AbhKDMI4 (ORCPT + 99 others); Thu, 4 Nov 2021 08:08:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:37180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231388AbhKDMIj (ORCPT ); Thu, 4 Nov 2021 08:08:39 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id C6EDA6124B; Thu, 4 Nov 2021 12:06:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1636027560; bh=IThQxwfyehbyQQVThBSABMWOyISpIRIGY2xGviVkzn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=pC/fzFjRU/qvzCBiIwT8mhaWIDEANwwYHo6yvHS3/LccCdMGHKTV1Oq6K0pXjcpix EZiKSRNNXrHTnsYiynYYeDaPkxNAPZe2yzNsMEivbvcjZxrs2+Se1noK3cg6UGsEQn Cw6tBEPbZ31LMcSWekob9X1Z9ZjLC92TuNFuUQd2o1qpDX2gKyoDXOiiokAdr0zHMi 9UUjU43y28R/dHUTLhBl9j0zrOVCYleRGUC0rK5jKaHvBFdPcSktAOD7UJSjIcxNBx ZmIyZf8TUoHaS5RaLQJEX58Vo3xpQSJxL0UfuDPXb09g/El0B/n7GiqdczEyie8Nne zRoGemWqxysHg== Received: by mail.kernel.org with local (Exim 4.94.2) (envelope-from ) id 1mibVG-005nHt-7j; Thu, 04 Nov 2021 12:05:58 +0000 From: Mauro Carvalho Chehab Cc: linuxarm@huawei.com, mauro.chehab@huawei.com, Mauro Carvalho Chehab , Alex Dewar , Aline Santana Cordeiro , Arnd Bergmann , Greg Kroah-Hartman , Hans Verkuil , Kaixu Xia , Mauro Carvalho Chehab , Peter Zijlstra , Sakari Ailus , Thomas Gleixner , Tomi Valkeinen , Tsuchiya Yuto , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH 6/7] media: atomisp: fix try_fmt logic Date: Thu, 4 Nov 2021 12:05:55 +0000 Message-Id: <44f582252dd16b512075167530b3d592689c7376.1636026959.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: Mauro Carvalho Chehab To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The internal try_fmt logic is not meant to provide everything that the V4L2 API should provide. Also, it doesn't decrement the pads that are used only internally by the driver, but aren't part of the device's output. Fix it. Signed-off-by: Mauro Carvalho Chehab --- To mailbombing on a large number of people, only mailing lists were C/C on the cover. See [PATCH 0/7] at: https://lore.kernel.org/all/cover.1636026959.git.mchehab+huawei@kernel.org/ .../staging/media/atomisp/pci/atomisp_cmd.c | 7 -- .../staging/media/atomisp/pci/atomisp_ioctl.c | 72 ++++++++++++++++++- 2 files changed, 71 insertions(+), 8 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp_cmd.c index 851046ecbdbf..0ddee36cdcd7 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_cmd.c +++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.c @@ -4918,13 +4918,6 @@ int atomisp_try_fmt(struct video_device *vdev, struct v4l2_pix_format *f, } f->pixelformat = fmt->pixelformat; - /* - * FIXME: do we need to setup this differently, depending on the - * sensor or the pipeline? - */ - f->colorspace = V4L2_COLORSPACE_REC709; - f->ycbcr_enc = V4L2_YCBCR_ENC_709; - f->xfer_func = V4L2_XFER_FUNC_709; /* * If the format is jpeg or custom RAW, then the width and height will diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c index 84ff97dabbed..1e6da6116a06 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c +++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c @@ -847,6 +847,72 @@ static int atomisp_g_fmt_file(struct file *file, void *fh, return 0; } +static int atomisp_adjust_fmt(struct v4l2_format *f) +{ + const struct atomisp_format_bridge *format_bridge; + u32 padded_width; + + format_bridge = atomisp_get_format_bridge(f->fmt.pix.pixelformat); + + padded_width = f->fmt.pix.width + pad_w; + + if (format_bridge->planar) { + f->fmt.pix.bytesperline = padded_width; + f->fmt.pix.sizeimage = PAGE_ALIGN(f->fmt.pix.height * + DIV_ROUND_UP(format_bridge->depth * + padded_width, 8)); + } else { + f->fmt.pix.bytesperline = DIV_ROUND_UP(format_bridge->depth * + padded_width, 8); + f->fmt.pix.sizeimage = PAGE_ALIGN(f->fmt.pix.height * f->fmt.pix.bytesperline); + } + + if (f->fmt.pix.field == V4L2_FIELD_ANY) + f->fmt.pix.field = V4L2_FIELD_NONE; + + format_bridge = atomisp_get_format_bridge(f->fmt.pix.pixelformat); + if (!format_bridge) + return -EINVAL; + + /* Currently, raw formats are broken!!! */ + if (format_bridge->sh_fmt == IA_CSS_FRAME_FORMAT_RAW) { + f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUV420; + + format_bridge = atomisp_get_format_bridge(f->fmt.pix.pixelformat); + if (!format_bridge) + return -EINVAL; + } + + padded_width = f->fmt.pix.width + pad_w; + + if (format_bridge->planar) { + f->fmt.pix.bytesperline = padded_width; + f->fmt.pix.sizeimage = PAGE_ALIGN(f->fmt.pix.height * + DIV_ROUND_UP(format_bridge->depth * + padded_width, 8)); + } else { + f->fmt.pix.bytesperline = DIV_ROUND_UP(format_bridge->depth * + padded_width, 8); + f->fmt.pix.sizeimage = PAGE_ALIGN(f->fmt.pix.height * f->fmt.pix.bytesperline); + } + + if (f->fmt.pix.field == V4L2_FIELD_ANY) + f->fmt.pix.field = V4L2_FIELD_NONE; + + /* + * FIXME: do we need to setup this differently, depending on the + * sensor or the pipeline? + */ + f->fmt.pix.colorspace = V4L2_COLORSPACE_REC709; + f->fmt.pix.ycbcr_enc = V4L2_YCBCR_ENC_709; + f->fmt.pix.xfer_func = V4L2_XFER_FUNC_709; + + f->fmt.pix.width -= pad_w; + f->fmt.pix.height -= pad_h; + + return 0; +} + /* This function looks up the closest available resolution. */ static int atomisp_try_fmt_cap(struct file *file, void *fh, struct v4l2_format *f) @@ -858,7 +924,11 @@ static int atomisp_try_fmt_cap(struct file *file, void *fh, rt_mutex_lock(&isp->mutex); ret = atomisp_try_fmt(vdev, &f->fmt.pix, NULL); rt_mutex_unlock(&isp->mutex); - return ret; + + if (ret) + return ret; + + return atomisp_adjust_fmt(f); } static int atomisp_g_fmt_cap(struct file *file, void *fh, -- 2.31.1