Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp99224pxb; Fri, 29 Oct 2021 06:30:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAROIGfG/HvepxICchaJq0Y1TjNMsP+uGuGS1jRytNiFP2qbZYTvT0fDC39uNCiGRRKlov X-Received: by 2002:a17:906:4c8b:: with SMTP id q11mr3197223eju.404.1635514254867; Fri, 29 Oct 2021 06:30:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635514254; cv=none; d=google.com; s=arc-20160816; b=mB/o5n7K4cOOWe+QJ4Z4LQhh7VXJbfIcme0DvD43QOA3frPPqzzgfZ1nlhEoG9rx1H aDIcZF5PA5Q177VH/FIdDwDoO6i1SWQgOBGzAbDzQGUQH7hCghgXOaveZaUbpsxSvXQV JqXyEHUAVTuFVLA1DIPbye2aaSukXelIi+owsi1EAp3Po1vTPIZSmo+vZOEOanM8mcSD fKO8f1EmPx3S8iv1a/WzNxHDehaGoBz4NpYz4Tt9SUDYlMUfAguxlOGRYoLOjQvFq1w8 9sWZLb2Wk8guYU1xRlGwKixZjxwWhFRecsFs4gmLj6Pc3ymvAiBhH6ySbO2oZb27yDiT DzYg== 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 :message-id:date:subject:cc:from:dkim-signature; bh=Nk62RPzNC3xS2SXWxNGKDU8tbzSNXyEO4vhS6jjBn1g=; b=giwAzP03FqaRAK8ips9TZhQOQONLn/tRUbqi6YdJb6dK33A13tt2+8+L6q1SwW08qO YRYSpvheDrPMEZOsQDsh0KVX5+XkQ9CtPeYoacExAoWtvZq2yREAYOKmh7ld08TbYGOb Ao51ydI950WMzR44XetmrYrlfthJtSmHmdmCX8GpkgIyeDUDP1cE+m+5qqcdQtEz9KL+ onG4n1vnxQGvp9YoIGM+6LEc9zgcIxWF//HUGC9khnHXTo2uqN7uCOl56/BcIZOLpxpq AlI67K418zvCM5OwJ0YsGW+E2WYgWpV1AbzJgY5OY9PWBMg9AKmDv57s7YOJPqDIWUfd 9dIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel.org header.s=k20201202 header.b=ZHTmh4AN; 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 r24si9159896ejy.432.2021.10.29.06.30.30; Fri, 29 Oct 2021 06:30:54 -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=ZHTmh4AN; 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 S231504AbhJ2N2A (ORCPT + 99 others); Fri, 29 Oct 2021 09:28:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:41576 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229603AbhJ2N16 (ORCPT ); Fri, 29 Oct 2021 09:27:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 3E5B561167; Fri, 29 Oct 2021 13:25:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1635513930; bh=+RnqNEo86g+pwCtg0yvYRDENv2czIXcrxcwDKdiKWQc=; h=From:To:Cc:Subject:Date:From; b=ZHTmh4ANXu+8xmhlyByehrapbXIB9HbHpGKkqcVSSjt21DxYm/olgb8iVQvi7V2Xt QuGqY05qQjWaAZ+ewQPqWKGbMPZ80zIvmAkZDx49zaKiWz41xt6DLICQ5rgdBv3Zt2 XrrulEiHtpSvrabRFuMesVf+99okZ5vT1o4cwzROLkMsOHytrtGoOQPUXS1uB51Am1 w/hJRlRnDDvrAFFQQCMyErEEsP2uixOqyG3/jvyxEw6Uoczaw000O5lttF/PldDwAL 9LqZDwWAXNTmVPS6Yv+4fSl4SrATU5HeiQH3Qm2VVOaJmoCj9hSttTne/hVTmaB4WY d9nlksYhQRpJw== Received: by mail.kernel.org with local (Exim 4.94.2) (envelope-from ) id 1mgRst-0032Ic-DE; Fri, 29 Oct 2021 14:25:27 +0100 From: Mauro Carvalho Chehab Cc: linuxarm@huawei.com, mauro.chehab@huawei.com, Mauro Carvalho Chehab , Alex Dewar , Aline Santana Cordeiro , Andy Shevchenko , Arnd Bergmann , Dan Carpenter , Greg Kroah-Hartman , Hans Verkuil , Kaixu Xia , Mauro Carvalho Chehab , Peter Zijlstra , Sakari Ailus , Thomas Gleixner , Tomi Valkeinen , Tsuchiya Yuto , Yang Li , linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-staging@lists.linux.dev Subject: [PATCH] media: atomisp: properly implement g_fmt Date: Fri, 29 Oct 2021 14:25:23 +0100 Message-Id: <7be615799148168ca454df998aaa1e0b224b4328.1635513916.git.mchehab+huawei@kernel.org> X-Mailer: git-send-email 2.31.1 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 current logic only initializes pipe->pix after setting up a pipeline - e. g. after start streaming. While it makes sense to get the format of the pipeline, when it is set, this breaks support for generic applications, as they rely on getting the current sensor format (which is usually the highest resolution format). So, implement a call to the sensor's get_fmt, when this is called before setting up a pipeline. Signed-off-by: Mauro Carvalho Chehab --- .../staging/media/atomisp/pci/atomisp_cmd.c | 13 +----- .../staging/media/atomisp/pci/atomisp_cmd.h | 4 +- .../staging/media/atomisp/pci/atomisp_ioctl.c | 44 +++++++++++++++++-- 3 files changed, 45 insertions(+), 16 deletions(-) diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.c b/drivers/staging/media/atomisp/pci/atomisp_cmd.c index 70c8e86c3205..6b308c81ef77 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_cmd.c +++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.c @@ -2034,7 +2034,7 @@ static int raw_output_format_match_input(u32 input, u32 output) return -EINVAL; } -static u32 get_pixel_depth(u32 pixelformat) +u32 atomisp_get_pixel_depth(u32 pixelformat) { switch (pixelformat) { case V4L2_PIX_FMT_YUV420: @@ -4816,15 +4816,6 @@ int atomisp_get_sensor_mode_data(struct atomisp_sub_device *asd, return 0; } -int atomisp_get_fmt(struct video_device *vdev, struct v4l2_format *f) -{ - struct atomisp_video_pipe *pipe = atomisp_to_video_pipe(vdev); - - f->fmt.pix = pipe->pix; - - return 0; -} - static void __atomisp_update_stream_env(struct atomisp_sub_device *asd, u16 stream_index, struct atomisp_input_stream_info *stream_info) { @@ -4973,7 +4964,7 @@ atomisp_try_fmt_file(struct atomisp_device *isp, struct v4l2_format *f) return -EINVAL; } - depth = get_pixel_depth(pixelformat); + depth = atomisp_get_pixel_depth(pixelformat); if (field == V4L2_FIELD_ANY) { field = V4L2_FIELD_NONE; diff --git a/drivers/staging/media/atomisp/pci/atomisp_cmd.h b/drivers/staging/media/atomisp/pci/atomisp_cmd.h index e8bdd264d31b..fb848d716947 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_cmd.h +++ b/drivers/staging/media/atomisp/pci/atomisp_cmd.h @@ -266,8 +266,6 @@ int atomisp_compare_grid(struct atomisp_sub_device *asd, int atomisp_get_sensor_mode_data(struct atomisp_sub_device *asd, struct atomisp_sensor_mode_data *config); -int atomisp_get_fmt(struct video_device *vdev, struct v4l2_format *f); - /* This function looks up the closest available resolution. */ int atomisp_try_fmt(struct video_device *vdev, struct v4l2_pix_format *f, bool *res_overflow); @@ -341,6 +339,8 @@ enum atomisp_metadata_type atomisp_get_metadata_type(struct atomisp_sub_device *asd, enum ia_css_pipe_id pipe_id); +u32 atomisp_get_pixel_depth(u32 pixelformat); + /* Function for HAL to inject a fake event to wake up poll thread */ int atomisp_inject_a_fake_event(struct atomisp_sub_device *asd, int *event); diff --git a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c index 29826f8e4143..37542ea17a38 100644 --- a/drivers/staging/media/atomisp/pci/atomisp_ioctl.c +++ b/drivers/staging/media/atomisp/pci/atomisp_ioctl.c @@ -838,15 +838,53 @@ static int atomisp_enum_fmt_cap(struct file *file, void *fh, static int atomisp_g_fmt_cap(struct file *file, void *fh, struct v4l2_format *f) { + struct v4l2_subdev_format fmt = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE + }; struct video_device *vdev = video_devdata(file); struct atomisp_device *isp = video_get_drvdata(vdev); - + struct v4l2_fmtdesc fmtdesc = { 0 }; + struct atomisp_video_pipe *pipe; + struct atomisp_sub_device *asd; + struct v4l2_subdev *camera; + u32 depth; int ret; rt_mutex_lock(&isp->mutex); - ret = atomisp_get_fmt(vdev, f); + pipe = atomisp_to_video_pipe(vdev); rt_mutex_unlock(&isp->mutex); - return ret; + + f->fmt.pix = pipe->pix; + if (!f->fmt.pix.width) { + asd = atomisp_to_video_pipe(vdev)->asd; + if (!asd) + return -EINVAL; + + camera = isp->inputs[asd->input_curr].camera; + if(!camera) + return -EINVAL; + + ret = atomisp_enum_fmt_cap(file, fh, &fmtdesc); + if (ret) + return ret; + + rt_mutex_lock(&isp->mutex); + ret = v4l2_subdev_call(isp->inputs[asd->input_curr].camera, + pad, get_fmt, NULL, &fmt); + rt_mutex_unlock(&isp->mutex); + if (ret) + return ret; + + v4l2_fill_pix_format(&f->fmt.pix, &fmt.format); + + f->fmt.pix.pixelformat = fmtdesc.pixelformat; + } + + depth = atomisp_get_pixel_depth(f->fmt.pix.pixelformat); + f->fmt.pix.bytesperline = (f->fmt.pix.width * depth) >> 3; + f->fmt.pix.sizeimage = f->fmt.pix.height * f->fmt.pix.bytesperline; + + return 0; } static int atomisp_g_fmt_file(struct file *file, void *fh, -- 2.31.1