From patchwork Fri Nov 2 16:38:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Loic Poulain X-Patchwork-Id: 150067 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2289813ljp; Fri, 2 Nov 2018 09:38:49 -0700 (PDT) X-Google-Smtp-Source: AJdET5foTSa3nvpm71z4gNRFdj6liftNZHie1L5u3qhfcAIzNjJybPWnREFDliXRfxcrliSEhjQV X-Received: by 2002:a17:902:82ca:: with SMTP id u10-v6mr11925728plz.146.1541176729111; Fri, 02 Nov 2018 09:38:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541176729; cv=none; d=google.com; s=arc-20160816; b=jFkZk4i2HZrlrAIJFqeUVoUtqXj2JLBMaEsjJNv1pMRfbuX+RwdRsa1WEfuoe0jNf4 vv4boqAQ9s575hVUpIcvYqfrmGPC4O/0+VUQoWWdPZEH5x/Ajcb9GF70fb1RbkidaNuA g662Sw5V7JDGfT9Fh+TU3FcecoHee/8cwrUFnq0B9l5Y2yjBu2D/fo01sK5/9Pklbakw v/iCFoGyAw7charuWn7GvnjKDcr4u7mbanV+NrQxdi+yGqjPpAwi+DXMjgNIzE2dKu1w Ll/uluq+X4mmQPPLW0jvv0zSrmauAHsvV+IU8r6vxjWmeFaJDLX4OcwL4+wT2ZZBIHYB HUgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature; bh=+dG7YZ9Nbqg3GOe5T/kFiHeFjsC/+yDnyWtw8l7FJU0=; b=bvgz7u8E8TI/6njy4Egy6lZejvZQu+PVF+00frbnkS3KvG/ELWR6B+xbqMqUn9Hzqe rcHmitVRvexYl+AXwh7Xb/YdhzNPSV3fDdseCLnWHxB3uB3ffUcvNmsbZiaBTlSA644W ZKmZs3iNyN59ZdE/C45S/hVX2l2/qcqo8ALMvY6NRla96VGHE8fce67sJZo80pYzX4GO g50oq/DGS28N9xWW0wKNbjzC0AL9F0FyJithOPtWw7cqyjM/nGqA1rWtHzkcgd+n1ArQ wrJ7ULsbcQLOgSktg2CnIIRx0WnNmzJ4GlecoYcGlB4Nki2H5ItbIAvXvEQygV+EkwHV yhVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bmQqwsVc; spf=pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 37-v6si34604932pgu.460.2018.11.02.09.38.48; Fri, 02 Nov 2018 09:38:49 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bmQqwsVc; spf=pass (google.com: best guess record for domain of linux-media-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-media-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726700AbeKCBqa (ORCPT + 4 others); Fri, 2 Nov 2018 21:46:30 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50868 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726098AbeKCBqa (ORCPT ); Fri, 2 Nov 2018 21:46:30 -0400 Received: by mail-wm1-f68.google.com with SMTP id h2-v6so2535327wmb.0 for ; Fri, 02 Nov 2018 09:38:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=+dG7YZ9Nbqg3GOe5T/kFiHeFjsC/+yDnyWtw8l7FJU0=; b=bmQqwsVcc7nFHsjOP/PTqyatRy2AfsMw3JCzZSwyhxBiBNpXU/VpD9LPaKueWxegkP 2BI9aJwH5DXx4N7GVMldABcXJoVni9pdS8HeOF52MS1rg8nSFEOay6S+GGOyOplWCjzd WBOkd+PjG3MXxu7OcDLSrtHeEOXCV7Ev0SnTE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=+dG7YZ9Nbqg3GOe5T/kFiHeFjsC/+yDnyWtw8l7FJU0=; b=p0w7ZjnkOwd67M3NtP/McR/3WW15wrJHkZFvY3A3+FkZNvjrF+S4IfChy0KSXHblSu zPJDcYMPUKsZLV6ui6xRsVYu7YqGfzdndsAOYiDf2mTys7SyGfS0WEiRQqDpnWAFN4eq czGBK3mcPf4I+1Vuis9qnsrLEhb83yBqvu8vA2AZojY+dtQ0+4bCv9JT/6klQUdXR2Vn LcHF68nRmKM4uRoGAJPbu+Lqy0fqGptQZy/OYg4Qm/nGnQV68R2/WVL2VQLizdXjXdjp Eb7aFYXlChjdCw5cTSlqMAnZtE1z6izpRYi54MDuRvBPuaOR1Hfuk+MJxtPbHW+PrGqY SBNg== X-Gm-Message-State: AGRZ1gKmCAdjtKSngoXqskY+p0QH96D1pHxHZBMHggIj09UmwfGoNENV OB89iP2W+hnQI0Snw1hKmdD8maplszba+w== X-Received: by 2002:a1c:13d2:: with SMTP id 201-v6mr13055wmt.58.1541176725819; Fri, 02 Nov 2018 09:38:45 -0700 (PDT) Received: from lpoulain-ThinkPad-T470p.home (atoulouse-654-1-394-222.w90-55.abo.wanadoo.fr. [90.55.193.222]) by smtp.gmail.com with ESMTPSA id b8sm23251701wrx.97.2018.11.02.09.38.44 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 02 Nov 2018 09:38:45 -0700 (PDT) From: Loic Poulain To: slongerbeam@gmail.com Cc: linux-media@vger.kernel.org, Loic Poulain Subject: [PATCH] media: ov5640: Add RAW bayer format support Date: Fri, 2 Nov 2018 17:38:43 +0100 Message-Id: <1541176723-20398-1-git-send-email-loic.poulain@linaro.org> X-Mailer: git-send-email 2.7.4 Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org OV5640 sensor supports raw image output (bayer). Configure ISP mux/format registers accordingly. Signed-off-by: Loic Poulain --- drivers/media/i2c/ov5640.c | 58 ++++++++++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 12 deletions(-) -- 2.7.4 diff --git a/drivers/media/i2c/ov5640.c b/drivers/media/i2c/ov5640.c index 071f4bc..e38e05e 100644 --- a/drivers/media/i2c/ov5640.c +++ b/drivers/media/i2c/ov5640.c @@ -116,6 +116,15 @@ enum ov5640_frame_rate { OV5640_NUM_FRAMERATES, }; +enum ov5640_format_mux { + OV5640_FMT_MUX_YUV422 = 0, + OV5640_FMT_MUX_RGB, + OV5640_FMT_MUX_DITHER, + OV5640_FMT_MUX_RAW_DPC, + OV5640_FMT_MUX_SNR_RAW, + OV5640_FMT_MUX_RAW_CIP, +}; + struct ov5640_pixfmt { u32 code; u32 colorspace; @@ -127,6 +136,10 @@ static const struct ov5640_pixfmt ov5640_formats[] = { { MEDIA_BUS_FMT_YUYV8_2X8, V4L2_COLORSPACE_SRGB, }, { MEDIA_BUS_FMT_RGB565_2X8_LE, V4L2_COLORSPACE_SRGB, }, { MEDIA_BUS_FMT_RGB565_2X8_BE, V4L2_COLORSPACE_SRGB, }, + { MEDIA_BUS_FMT_SBGGR8_1X8, V4L2_COLORSPACE_SRGB, }, + { MEDIA_BUS_FMT_SGBRG8_1X8, V4L2_COLORSPACE_SRGB, }, + { MEDIA_BUS_FMT_SGRBG8_1X8, V4L2_COLORSPACE_SRGB, }, + { MEDIA_BUS_FMT_SRGGB8_1X8, V4L2_COLORSPACE_SRGB, }, }; /* @@ -1980,46 +1993,67 @@ static int ov5640_set_framefmt(struct ov5640_dev *sensor, struct v4l2_mbus_framefmt *format) { int ret = 0; - bool is_rgb = false; bool is_jpeg = false; - u8 val; + u8 fmt, mux; switch (format->code) { case MEDIA_BUS_FMT_UYVY8_2X8: /* YUV422, UYVY */ - val = 0x3f; + fmt = 0x3f; + mux = OV5640_FMT_MUX_YUV422; break; case MEDIA_BUS_FMT_YUYV8_2X8: /* YUV422, YUYV */ - val = 0x30; + fmt = 0x30; + mux = OV5640_FMT_MUX_YUV422; break; case MEDIA_BUS_FMT_RGB565_2X8_LE: /* RGB565 {g[2:0],b[4:0]},{r[4:0],g[5:3]} */ - val = 0x6F; - is_rgb = true; + fmt = 0x6F; + mux = OV5640_FMT_MUX_RGB; break; case MEDIA_BUS_FMT_RGB565_2X8_BE: /* RGB565 {r[4:0],g[5:3]},{g[2:0],b[4:0]} */ - val = 0x61; - is_rgb = true; + fmt = 0x61; + mux = OV5640_FMT_MUX_RGB; break; case MEDIA_BUS_FMT_JPEG_1X8: /* YUV422, YUYV */ - val = 0x30; + fmt = 0x30; + mux = OV5640_FMT_MUX_YUV422; is_jpeg = true; break; + case MEDIA_BUS_FMT_SBGGR8_1X8: + /* Raw, BGBG... / GRGR... */ + fmt = 0x00; + mux = OV5640_FMT_MUX_RAW_DPC; + break; + case MEDIA_BUS_FMT_SGBRG8_1X8: + /* Raw bayer, GBGB... / RGRG... */ + fmt = 0x01; + mux = OV5640_FMT_MUX_RAW_DPC; + break; + case MEDIA_BUS_FMT_SGRBG8_1X8: + /* Raw bayer, GRGR... / BGBG... */ + fmt = 0x02; + mux = OV5640_FMT_MUX_RAW_DPC; + break; + case MEDIA_BUS_FMT_SRGGB8_1X8: + /* Raw bayer, RGRG... / GBGB... */ + fmt = 0x03; + mux = OV5640_FMT_MUX_RAW_DPC; + break; default: return -EINVAL; } /* FORMAT CONTROL00: YUV and RGB formatting */ - ret = ov5640_write_reg(sensor, OV5640_REG_FORMAT_CONTROL00, val); + ret = ov5640_write_reg(sensor, OV5640_REG_FORMAT_CONTROL00, fmt); if (ret) return ret; /* FORMAT MUX CONTROL: ISP YUV or RGB */ - ret = ov5640_write_reg(sensor, OV5640_REG_ISP_FORMAT_MUX_CTRL, - is_rgb ? 0x01 : 0x00); + ret = ov5640_write_reg(sensor, OV5640_REG_ISP_FORMAT_MUX_CTRL, mux); if (ret) return ret;