From patchwork Fri Sep 25 07:50:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Stefan_Riedm=C3=BCller?= X-Patchwork-Id: 11799307 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CCCF0112E for ; Fri, 25 Sep 2020 08:05:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A424820756 for ; Fri, 25 Sep 2020 08:05:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=temperror (0-bit key) header.d=phytec.de header.i=@phytec.de header.b="nHXWGDno" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727132AbgIYIFk (ORCPT ); Fri, 25 Sep 2020 04:05:40 -0400 Received: from mickerik.phytec.de ([195.145.39.210]:61906 "EHLO mickerik.phytec.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727067AbgIYIFk (ORCPT ); Fri, 25 Sep 2020 04:05:40 -0400 X-Greylist: delayed 901 seconds by postgrey-1.27 at vger.kernel.org; Fri, 25 Sep 2020 04:05:40 EDT DKIM-Signature: v=1; a=rsa-sha256; d=phytec.de; s=a1; c=relaxed/simple; q=dns/txt; i=@phytec.de; t=1601020238; x=1603612238; h=From:Sender:Reply-To:Subject:Date:Message-Id:To:Cc:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=j0kqQYL4u8t86vKnzKM+WdGJT8q9+TWpXY5c8+70iWo=; b=nHXWGDnoL6vXSe7HqRozREJDOaivo/1SMXl7Q8O6Lf36syi9AJ1JYKny9Zn4SMN5 kZjKbN5F1oLT8awUjuHE/RtLRisE7GkzqCseDW1EwfYy34eYcRLUum9YgA09rwL0 tIyMag6UvIj7rfOJfnBU0NykQCEyd+0IHJ3g/yjNJgs=; X-AuditID: c39127d2-253ff70000001c25-ef-5f6da14ecba7 Received: from idefix.phytec.de (Unknown_Domain [172.16.0.10]) by mickerik.phytec.de (PHYTEC Mail Gateway) with SMTP id 1C.A5.07205.E41AD6F5; Fri, 25 Sep 2020 09:50:38 +0200 (CEST) Received: from lws-riedmueller.phytec.de ([172.16.23.108]) by idefix.phytec.de (IBM Domino Release 9.0.1FP7) with ESMTP id 2020092509503863-495326 ; Fri, 25 Sep 2020 09:50:38 +0200 From: Stefan Riedmueller To: Laurent Pinchart Cc: Mauro Carvalho Chehab , Sakari Ailus , linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, Christian Hemp , Jan Luebbe , Stefan Riedmueller Subject: [PATCH 1/5] media: mt9p031: Add support for 8 bit and 10 bit formats Date: Fri, 25 Sep 2020 09:50:25 +0200 Message-Id: <20200925075029.32181-1-s.riedmueller@phytec.de> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-MIMETrack: Itemize by SMTP Server on Idefix/Phytec(Release 9.0.1FP7|August 17, 2016) at 25.09.2020 09:50:38, Serialize by Router on Idefix/Phytec(Release 9.0.1FP7|August 17, 2016) at 25.09.2020 09:50:38 X-TNEFEvaluated: 1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrALMWRmVeSWpSXmKPExsWyRoCBS9dvYW68wZVtOhZf58xjteicuITd 4vKuOWwWPRu2slos2/SHyeLTlm9MDmwesztmsnpsWtXJ5jHvZKBH/18Dj8+b5AJYo7hsUlJz MstSi/TtErgy3i8/wFjwWaGis+8MWwNjj0wXIweHhICJxKnDEl2MXBxCAtsYJSZNbmWHcK4x SrT/esjUxcjJwSZgJLFgWiOYLSJgIdG7aDojSBGzQAeTRN+n02wgCWEBX4n3vx4zg9gsAqoS m59vYwexeQVsJM5tngFWIyEgLzHz0neouKDEyZlPWCDiVxglNj7XgLCFJE4vPgs2h1lAW2LZ wtfMExj5ZiFpmYUktYCRaRWjUG5mcnZqUWa2XkFGZUlqsl5K6iZGYCgenqh+aQdj3xyPQ4xM HIyHGCU4mJVEeI9vyIkX4k1JrKxKLcqPLyrNSS0+xCjNwaIkzruBtyRMSCA9sSQ1OzW1ILUI JsvEwSnVwFhQs9N/5qFH/DP0J1eGW3+9ce3FnuV1e5Y2BptoNN5svmZ0aPbqhlOSrae3pOcu U3v0um32p3Wswbpp/Sonkr9dvifoG22XzNywLkSq+v9lkwsfbN0Oi2wVfK63uN6p6LHDi7Qp jdLaZ/ICsnPlVD4KW//imidbvaPv7TKhNT/Wst7PEmVL26LEUpyRaKjFXFScCABGoN4KMwIA AA== Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org From: Christian Hemp Aside from 12 bit monochrome or color format the sensor implicitly supports 10 and 8 bit formats as well by simply dropping the corresponding LSBs. Signed-off-by: Christian Hemp [jlu@pengutronix.de: simplified by dropping v4l2_colorspace handling] Signed-off-by: Jan Luebbe Signed-off-by: Stefan Riedmueller Reported-by: kernel test robot --- drivers/media/i2c/mt9p031.c | 50 +++++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/drivers/media/i2c/mt9p031.c b/drivers/media/i2c/mt9p031.c index dc23b9ed510a..0002dd299ffa 100644 --- a/drivers/media/i2c/mt9p031.c +++ b/drivers/media/i2c/mt9p031.c @@ -116,6 +116,18 @@ enum mt9p031_model { MT9P031_MODEL_MONOCHROME, }; +static const u32 mt9p031_color_fmts[] = { + MEDIA_BUS_FMT_SGRBG8_1X8, + MEDIA_BUS_FMT_SGRBG10_1X10, + MEDIA_BUS_FMT_SGRBG12_1X12, +}; + +static const u32 mt9p031_monochrome_fmts[] = { + MEDIA_BUS_FMT_Y8_1X8, + MEDIA_BUS_FMT_Y10_1X10, + MEDIA_BUS_FMT_Y12_1X12, +}; + struct mt9p031 { struct v4l2_subdev subdev; struct media_pad pad; @@ -138,6 +150,9 @@ struct mt9p031 { struct v4l2_ctrl *blc_auto; struct v4l2_ctrl *blc_offset; + const u32 *fmts; + int num_fmts; + /* Registers cache */ u16 output_control; u16 mode2; @@ -148,6 +163,17 @@ static struct mt9p031 *to_mt9p031(struct v4l2_subdev *sd) return container_of(sd, struct mt9p031, subdev); } +static const u32 mt9p031_find_datafmt(struct mt9p031 *mt9p031, u32 code) +{ + int i; + + for (i = 0; i < mt9p031->num_fmts; i++) + if (mt9p031->fmts[i] == code) + return mt9p031->fmts[i]; + + return mt9p031->fmts[mt9p031->num_fmts-1]; +} + static int mt9p031_read(struct i2c_client *client, u8 reg) { return i2c_smbus_read_word_swapped(client, reg); @@ -476,10 +502,11 @@ static int mt9p031_enum_mbus_code(struct v4l2_subdev *subdev, { struct mt9p031 *mt9p031 = to_mt9p031(subdev); - if (code->pad || code->index) + if (code->pad || code->index >= mt9p031->num_fmts) return -EINVAL; - code->code = mt9p031->format.code; + code->code = mt9p031->fmts[code->index]; + return 0; } @@ -573,6 +600,8 @@ static int mt9p031_set_format(struct v4l2_subdev *subdev, __format->width = __crop->width / hratio; __format->height = __crop->height / vratio; + __format->code = mt9p031_find_datafmt(mt9p031, format->format.code); + format->format = *__format; return 0; @@ -951,10 +980,7 @@ static int mt9p031_open(struct v4l2_subdev *subdev, struct v4l2_subdev_fh *fh) format = v4l2_subdev_get_try_format(subdev, fh->pad, 0); - if (mt9p031->model == MT9P031_MODEL_MONOCHROME) - format->code = MEDIA_BUS_FMT_Y12_1X12; - else - format->code = MEDIA_BUS_FMT_SGRBG12_1X12; + format->code = mt9p031_find_datafmt(mt9p031, 0); format->width = MT9P031_WINDOW_WIDTH_DEF; format->height = MT9P031_WINDOW_HEIGHT_DEF; @@ -1121,10 +1147,14 @@ static int mt9p031_probe(struct i2c_client *client, mt9p031->crop.left = MT9P031_COLUMN_START_DEF; mt9p031->crop.top = MT9P031_ROW_START_DEF; - if (mt9p031->model == MT9P031_MODEL_MONOCHROME) - mt9p031->format.code = MEDIA_BUS_FMT_Y12_1X12; - else - mt9p031->format.code = MEDIA_BUS_FMT_SGRBG12_1X12; + if (mt9p031->model == MT9P031_MODEL_MONOCHROME) { + mt9p031->fmts = mt9p031_monochrome_fmts; + mt9p031->num_fmts = ARRAY_SIZE(mt9p031_monochrome_fmts); + } else { + mt9p031->fmts = mt9p031_color_fmts; + mt9p031->num_fmts = ARRAY_SIZE(mt9p031_color_fmts); + } + mt9p031->format.code = mt9p031_find_datafmt(mt9p031, 0); mt9p031->format.width = MT9P031_WINDOW_WIDTH_DEF; mt9p031->format.height = MT9P031_WINDOW_HEIGHT_DEF;