From patchwork Wed May 4 22:30:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 569451 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F5EAC433EF for ; Wed, 4 May 2022 22:30:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378987AbiEDWe1 (ORCPT ); Wed, 4 May 2022 18:34:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237672AbiEDWeZ (ORCPT ); Wed, 4 May 2022 18:34:25 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F32CF2CC9F for ; Wed, 4 May 2022 15:30:43 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id q23so3819219wra.1 for ; Wed, 04 May 2022 15:30:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wjKT8/HtIvRRldjfymBu3g/MFDvJOLJj7QZZaQyz0Z4=; b=QfCRzAWPD+U+Fj98hpID6uvoCtvZyffpcCcrlPlDr8Krr8q2aXjKKSNuPvTWnVCeyx esOhqM4jCWJLR9NSzFbInXd/7uzh53WUq2CYibdArgjRFmp7pkhoxrO+jw4PuewyI7Fb lGcEPO9FU1rSt4VfXhevLf+L/5cLoY/aXEI6rNwBL7CG3v2LyzbXSRvwjaQasN3sZbL5 OET+Odedl07quLz1JBRsPVTC+hxFE5fyicOeO5lywQMKrG8GSKPlv5GFIgRPHsJPDUm8 MRLEC7Pv9/9DiDQwtC+K2xSnohBsBr8z09+fhcx0grHvAbg0ZubElkhIyzDB5W2ZR2E7 qqxg== 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=wjKT8/HtIvRRldjfymBu3g/MFDvJOLJj7QZZaQyz0Z4=; b=jmMdc09cIuUQrIFFvtEWZhumZrIbm5X/58n0JNYIwNFPq7+sTfaJGdhvyOVyImpOVd +m5SKiHVyMa5DeYWeZ3BDzQUrQ2ehSQMO+vNt4aZDh1oAW2YYlXapB/HaaowOA2PPoA3 cSJZybb48lNN4jlYhHbFzX3ElyWgYsf7vqanKV3wArtW6U/xsUvQeLPhD4I/ZIXroHKL kcirqQQkbkx/gJJtJbKIBocjU5MWSmyGVJtzR4FNSanz3OCSm2FLBLv+Hrf8vIOaWx3t c5OGDUQ+xres7RDDvUu6eDqkxrIxcDlNh8hAQijIfwzeNVxZe6liLMdCe86b5Rxhpxg9 A3PA== X-Gm-Message-State: AOAM530sTWiaoZ638xD5W1s/HDTEC8/NzeU90vm+g5RwrR0aohg8qwdD xd1EQ18RQUibsDbCFiZcS+Xt+D+1fdE= X-Google-Smtp-Source: ABdhPJzPdMadfFAKMlQWfSqX5Zv9FNlMD3OaxlPWGjg3aosSS2Q4pJYjcUazvA+OBz4hjDkRgSI7Yg== X-Received: by 2002:a5d:59a5:0:b0:20c:5603:c0c3 with SMTP id p5-20020a5d59a5000000b0020c5603c0c3mr16964624wrr.521.1651703442617; Wed, 04 May 2022 15:30:42 -0700 (PDT) Received: from localhost.localdomain (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161]) by smtp.gmail.com with ESMTPSA id h29-20020adfaa9d000000b0020c5253d913sm12501442wrc.95.2022.05.04.15.30.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 15:30:42 -0700 (PDT) From: Daniel Scally To: linux-media@vger.kernel.org Cc: yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, andriy.shevchenko@linux.intel.com, hverkuil-cisco@xs4all.nl Subject: [PATCH v3 02/15] media: ipu3-cio2: Add support for V4L2_PIX_FMT_IPU3_Y10 Date: Wed, 4 May 2022 23:30:14 +0100 Message-Id: <20220504223027.3480287-3-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220504223027.3480287-1-djrscally@gmail.com> References: <20220504223027.3480287-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org We have platforms where a camera sensor transmits Y10 data to the CIO2 device - add support for that (packed) format to the ipu3-cio2 driver. Signed-off-by: Daniel Scally --- Changes in v3: - None Changes in v2: - None drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c index 0e9b0503b62a..93cc0577b6db 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c @@ -65,6 +65,11 @@ static const struct ipu3_cio2_fmt formats[] = { .fourcc = V4L2_PIX_FMT_IPU3_SRGGB10, .mipicode = 0x2b, .bpp = 10, + }, { + .mbus_code = MEDIA_BUS_FMT_Y10_1X10, + .fourcc = V4L2_PIX_FMT_IPU3_Y10, + .mipicode = 0x2b, + .bpp = 10, }, }; From patchwork Wed May 4 22:30:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 569448 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DF9F1C433EF for ; Wed, 4 May 2022 22:30:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379014AbiEDWef (ORCPT ); Wed, 4 May 2022 18:34:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378999AbiEDWe0 (ORCPT ); Wed, 4 May 2022 18:34:26 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BF722CE12 for ; Wed, 4 May 2022 15:30:44 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id t6so3813766wra.4 for ; Wed, 04 May 2022 15:30:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LtBY2N5TqXr61LjPKGIkUGFKcHrrJ6M9YgKf43sWM2Y=; b=oWLAhudozGakxnM7+JelipPSPGMO7VGIkAgZBtCJiGO5hk1AkFB74UFg984TMe6eZD cZ+d7zaYT4C+a2x/DLD8w/a2oGHqPCH4ya1eAabb6PCtqgoIjjaRGhUEVK4AB5ZQy9n3 FlGcAbj+viAfD/Kyfq+7/vzsNaMD/sq2lJD/WxPDIujrxrPTee28FpE+zpv6lXYI0MrE dgGmw1WSOhE6Oaco/65bKcKOliwWlSrC1vuLw7wa5uIA4Ld7wqf3lZRfhomeE8aQWCC3 CORltZkGfBDYkpcN7Vy6FPGSklD5cJ5mXrueI6pwVSa3AvANkblpaW5lhOGMIZ296KQJ eNtw== 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=LtBY2N5TqXr61LjPKGIkUGFKcHrrJ6M9YgKf43sWM2Y=; b=agH3FjRqXToPdJ8+Op1pAhJSNB2C7F6rQFfJvS23Ri8sSRkPHl41eYeQj4/1OrknN3 ukGee8VAL7DiuREPxQO4b+F+zKYLqDOP3VMa/s8N3eGjEcvaSyYbHNF37FP9D/L/krga WuJamINAXUqb/T6tJmgW7ce/HSo4cyCeAPrcC/JaYm2dAvJ1PvTF7ufEuFJakhbGsomm u3SYuBtFnfuRi2qbTAsWahvhErTu6WyDZe0GVWkPZvwy0HJ5MTQuVwtH/yGL2F5esSw3 PXFOHUxc1fUaNnXODdrbW9umkAluKPTS9oBevVMWvGPzlV0g13J7rff/4fy1RKeBtRMK 7kJw== X-Gm-Message-State: AOAM533CYc1PWqqJpBFNnT5BciCZ3ukfbUYXBucGx4jHU56kOGw9tJgs qBtpkHIkS3EGMSfTWVE/yEyZku/gWbI= X-Google-Smtp-Source: ABdhPJzvoyzuQCyl7USfFZ54Cl3rpgjBcrz7Ok3tbgeF/tiRfmoTkHe2RqXYtpYM8oy0RzxUjLMdeA== X-Received: by 2002:a5d:5887:0:b0:20c:83c9:b72 with SMTP id n7-20020a5d5887000000b0020c83c90b72mr3373093wrf.588.1651703443477; Wed, 04 May 2022 15:30:43 -0700 (PDT) Received: from localhost.localdomain (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161]) by smtp.gmail.com with ESMTPSA id h29-20020adfaa9d000000b0020c5253d913sm12501442wrc.95.2022.05.04.15.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 15:30:43 -0700 (PDT) From: Daniel Scally To: linux-media@vger.kernel.org Cc: yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, andriy.shevchenko@linux.intel.com, hverkuil-cisco@xs4all.nl Subject: [PATCH v3 03/15] media: i2c: Add acpi support to ov7251 Date: Wed, 4 May 2022 23:30:15 +0100 Message-Id: <20220504223027.3480287-4-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220504223027.3480287-1-djrscally@gmail.com> References: <20220504223027.3480287-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add support for enumeration through ACPI to the ov7251 driver Signed-off-by: Daniel Scally --- Changes in v3: - None Changes in v2: - None drivers/media/i2c/ov7251.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index ebb299f207e5..d6fe574cb9e0 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -1490,9 +1491,16 @@ static const struct of_device_id ov7251_of_match[] = { }; MODULE_DEVICE_TABLE(of, ov7251_of_match); +static const struct acpi_device_id ov7251_acpi_match[] = { + { "INT347E" }, + { } +}; +MODULE_DEVICE_TABLE(acpi, ov7251_acpi_match); + static struct i2c_driver ov7251_i2c_driver = { .driver = { .of_match_table = ov7251_of_match, + .acpi_match_table = ov7251_acpi_match, .name = "ov7251", }, .probe_new = ov7251_probe, From patchwork Wed May 4 22:30:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 569450 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A1C0C4332F for ; Wed, 4 May 2022 22:30:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378998AbiEDWe3 (ORCPT ); Wed, 4 May 2022 18:34:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1378988AbiEDWe0 (ORCPT ); Wed, 4 May 2022 18:34:26 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0ECB2D1F0 for ; Wed, 4 May 2022 15:30:46 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id i20-20020a05600c355400b0039456976dcaso1801345wmq.1 for ; Wed, 04 May 2022 15:30:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=P1QaVmRJwjnZ2MMq/nBSQV6D5HxzClMsYDbecLw36iM=; b=XwL7y4wF5rduiDiOFUQEY+paA6pTmohOZ50RCWP1KL3jIEUXG3f0xfeZvRfE4uZNN2 z6h1PbqP8TX3fA+xxG8H8Pm1rKkP86ayKykQpEg24Cb1nwTHCJWQe92z+3nQ1Lo1QpM4 2cvtO2GoAy9qqTnksRIv7yzrtrkmwhLfFTphTC1cbVYDleEjNLy/9zoI2+TDIaubgsWg YIKA/Wf7onD1WOCye7d/vxIkk8I5/nOpntHrbidLnNR8Px8Y1g6ysRmsKk/eKsrSbtvA nA8A3hILCyWOYLeMj6StDDoZqc2IdpeJBWLEPNPcvIgfJtKNAK0Dac+fSdxQ+2BV/DR5 imEw== 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=P1QaVmRJwjnZ2MMq/nBSQV6D5HxzClMsYDbecLw36iM=; b=ZHpplxPqymPz3U7sw/LRMZHu9J5PQR2JEtN3SVY5A9hjtxz5E4Od0r4CqCuyDhyRL8 0gAVNwqMDixoP7H8wAjzaot54FT0cOI78icuH45M3mwMKMlMbAszoNi2fjjdCsS3OgAW AGvCNFDE1UJf5OPMFsL1vxBibB47HVnhbyod8WS5RIRY0+3w7OkzQmqt5PqvZUlfWZ3c 2rizHdG3CPvcW5P6amiopO51j6Xf8d01zW/caGqR7o4ue2o2KS1fuytEacJOAma5bjeN Qvjz3//m28fyWl9YEYdSU22JPTugM4kbwAG5x+hNLE2Eo76kRW0MY0iDgMnv7DqqfcIQ G8aQ== X-Gm-Message-State: AOAM533j691O2IXoVZCxvlsgBFjhVLePFTtGqJY1AVH+yYRcfB3jiRzg BvmT1Z+vgAvXUiBA/8Vmy1kQrYZfKS8= X-Google-Smtp-Source: ABdhPJxLPw2NId/q65eP1+zxSCCwhOYxHM9EE6rqHbpDkfmGSHhHy60xDfkB/4YXQV/jsNM/rU3K6w== X-Received: by 2002:a05:600c:3d96:b0:38f:fbc6:da44 with SMTP id bi22-20020a05600c3d9600b0038ffbc6da44mr1465171wmb.93.1651703445418; Wed, 04 May 2022 15:30:45 -0700 (PDT) Received: from localhost.localdomain (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161]) by smtp.gmail.com with ESMTPSA id h29-20020adfaa9d000000b0020c5253d913sm12501442wrc.95.2022.05.04.15.30.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 15:30:44 -0700 (PDT) From: Daniel Scally To: linux-media@vger.kernel.org Cc: yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, andriy.shevchenko@linux.intel.com, hverkuil-cisco@xs4all.nl Subject: [PATCH v3 05/15] media: i2c: Remove per-mode frequencies from ov7251 Date: Wed, 4 May 2022 23:30:17 +0100 Message-Id: <20220504223027.3480287-6-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220504223027.3480287-1-djrscally@gmail.com> References: <20220504223027.3480287-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Each of the defined modes in the ov7251 driver uses the same link frequency and pixel rate; just drop those members of the modes and set the controls to read only during initialisation. Add a new table defining the supported pixel rates to substitue for the values hardcoded in the modes. Signed-off-by: Daniel Scally --- Changes in v3: - None Changes in v2: - New patch drivers/media/i2c/ov7251.c | 43 +++++++++++++------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index f1965c8adbd7..f21119064b2d 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -526,7 +526,11 @@ static const struct reg_value ov7251_setting_vga_90fps[] = { }; static const s64 link_freq[] = { - 240000000, + [OV7251_LINK_FREQ_240_MHZ] = 240000000, +}; + +static const s64 pixel_rates[] = { + [OV7251_LINK_FREQ_240_MHZ] = 48000000, }; static const struct ov7251_mode_info ov7251_mode_info_data[] = { @@ -535,8 +539,6 @@ static const struct ov7251_mode_info ov7251_mode_info_data[] = { .height = 480, .data = ov7251_setting_vga_30fps, .data_size = ARRAY_SIZE(ov7251_setting_vga_30fps), - .pixel_clock = 48000000, - .link_freq = 0, /* an index in link_freq[] */ .exposure_max = 1704, .exposure_def = 504, .timeperframe = { @@ -549,8 +551,6 @@ static const struct ov7251_mode_info ov7251_mode_info_data[] = { .height = 480, .data = ov7251_setting_vga_60fps, .data_size = ARRAY_SIZE(ov7251_setting_vga_60fps), - .pixel_clock = 48000000, - .link_freq = 0, /* an index in link_freq[] */ .exposure_max = 840, .exposure_def = 504, .timeperframe = { @@ -563,8 +563,6 @@ static const struct ov7251_mode_info ov7251_mode_info_data[] = { .height = 480, .data = ov7251_setting_vga_90fps, .data_size = ARRAY_SIZE(ov7251_setting_vga_90fps), - .pixel_clock = 48000000, - .link_freq = 0, /* an index in link_freq[] */ .exposure_max = 552, .exposure_def = 504, .timeperframe = { @@ -1059,16 +1057,6 @@ static int ov7251_set_format(struct v4l2_subdev *sd, __crop->height = new_mode->height; if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) { - ret = __v4l2_ctrl_s_ctrl_int64(ov7251->pixel_clock, - new_mode->pixel_clock); - if (ret < 0) - goto exit; - - ret = __v4l2_ctrl_s_ctrl(ov7251->link_freq, - new_mode->link_freq); - if (ret < 0) - goto exit; - ret = __v4l2_ctrl_modify_range(ov7251->exposure, 1, new_mode->exposure_max, 1, new_mode->exposure_def); @@ -1199,16 +1187,6 @@ static int ov7251_set_frame_interval(struct v4l2_subdev *subdev, new_mode = ov7251_find_mode_by_ival(ov7251, &fi->interval); if (new_mode != ov7251->current_mode) { - ret = __v4l2_ctrl_s_ctrl_int64(ov7251->pixel_clock, - new_mode->pixel_clock); - if (ret < 0) - goto exit; - - ret = __v4l2_ctrl_s_ctrl(ov7251->link_freq, - new_mode->link_freq); - if (ret < 0) - goto exit; - ret = __v4l2_ctrl_modify_range(ov7251->exposure, 1, new_mode->exposure_max, 1, new_mode->exposure_def); @@ -1317,6 +1295,7 @@ static int ov7251_probe(struct i2c_client *client) struct device *dev = &client->dev; struct ov7251 *ov7251; u8 chip_id_high, chip_id_low, chip_rev; + s64 pixel_rate; int ret; ov7251 = devm_kzalloc(dev, sizeof(struct ov7251), GFP_KERNEL); @@ -1398,17 +1377,23 @@ static int ov7251_probe(struct i2c_client *client) V4L2_CID_TEST_PATTERN, ARRAY_SIZE(ov7251_test_pattern_menu) - 1, 0, 0, ov7251_test_pattern_menu); + + pixel_rate = pixel_rates[ov7251->link_freq_idx]; ov7251->pixel_clock = v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops, V4L2_CID_PIXEL_RATE, - 1, INT_MAX, 1, 1); + pixel_rate, INT_MAX, + pixel_rate, pixel_rate); ov7251->link_freq = v4l2_ctrl_new_int_menu(&ov7251->ctrls, &ov7251_ctrl_ops, V4L2_CID_LINK_FREQ, ARRAY_SIZE(link_freq) - 1, - 0, link_freq); + ov7251->link_freq_idx, + link_freq); if (ov7251->link_freq) ov7251->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY; + if (ov7251->pixel_clock) + ov7251->pixel_clock->flags |= V4L2_CTRL_FLAG_READ_ONLY; ov7251->sd.ctrl_handler = &ov7251->ctrls; From patchwork Wed May 4 22:30:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 569449 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BB825C433EF for ; Wed, 4 May 2022 22:30:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379011AbiEDWec (ORCPT ); Wed, 4 May 2022 18:34:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379015AbiEDWe1 (ORCPT ); Wed, 4 May 2022 18:34:27 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A4E49443C3 for ; Wed, 4 May 2022 15:30:48 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id v64-20020a1cac43000000b0038cfd1b3a6dso4043955wme.5 for ; Wed, 04 May 2022 15:30:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1uO8WW4DUmEYruAHcfAsIJmtYfQBEGH8W1J8oG3Wjow=; b=fwtJpFr6G0jswIa+pWu4w48ikHrg0n91Yp/ELhQUtFRGNQrVDm20X7JyvRCM4y7KAx 8v6L0UhP0u+ZLIM8FVLBir/vPmKPgubiIsLL0KgYJSs+LpA0NU9hNiZR9B9R8LhBW8DR OUtLmCNGebaN+oSYcxbSalUS4IEjpPB//895q3cHcTn3Qlk83NFl2/lNCpmVCGfQmD2E 9iXeLAEdrglHXbyEUof2hJ/EtsXTYfe6lSVus+vL5pZTqdHY9rvz5c80QeVMIVZSdprs IzuGsjc1CUOaEydTd9crXTXLk4mDXjTFqCecIgF0YY9DkYzgkLb45xIhR1XU3lMNYJXz eJ3g== 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=1uO8WW4DUmEYruAHcfAsIJmtYfQBEGH8W1J8oG3Wjow=; b=re37F5QhitTSVlTpaXzRY+buNkAbr73cemt6Fvy/iST8iL98ld9j7d4eAmh7tNFrqD u2cGgqvZ2eG4wXSTmT5nF8gobgFlTTZfIBOErGxY4Dhk4s7zwUzImLmyuJrHZgt2JiyX BmSTw5th7LEwyHi5ZGZ7p2sm5aAdqrMmSS3TDuCOYMu7hyMz/PpUmIWZ05NUUef2tqhV H+5LYVazHRcrrAbGZjvzh4gruOGVT8nBtmAOTkF4y21c9aOuNyuIAdwLj95o+LFbx4iD 3cv+JXKQKSyEfij219l1lkLjn3MjuLGcZLj264Z/HPS0ETB9HQ6VtpKF5MadHGjC26+8 8INQ== X-Gm-Message-State: AOAM533tXLPd0yUH1+nYhwD5Ujidqnm86P4c4izGEMwKkIgh2sjDVLk4 m+nkNbIpeFHXhMInSMRucPpVIIMrlOc= X-Google-Smtp-Source: ABdhPJyh9AQL8EEadS3PNF7TMkSgQCLrJRfq2ZeEaH456/pdDJEPYLgWhJNIDLMR3AsbLgeZxFkD9w== X-Received: by 2002:a05:600c:4fce:b0:394:5f8e:8124 with SMTP id o14-20020a05600c4fce00b003945f8e8124mr1483265wmq.107.1651703447207; Wed, 04 May 2022 15:30:47 -0700 (PDT) Received: from localhost.localdomain (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161]) by smtp.gmail.com with ESMTPSA id h29-20020adfaa9d000000b0020c5253d913sm12501442wrc.95.2022.05.04.15.30.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 15:30:46 -0700 (PDT) From: Daniel Scally To: linux-media@vger.kernel.org Cc: yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, andriy.shevchenko@linux.intel.com, hverkuil-cisco@xs4all.nl Subject: [PATCH v3 07/15] media: i2c: Add support for new frequencies to ov7251 Date: Wed, 4 May 2022 23:30:19 +0100 Message-Id: <20220504223027.3480287-8-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220504223027.3480287-1-djrscally@gmail.com> References: <20220504223027.3480287-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The OV7251 sensor is used as the IR camera sensor on the Microsoft Surface line of tablets; this provides a 19.2MHz external clock, and the Windows driver for this sensor configures a 319.2MHz link freq to the CSI-2 receiver. Add the ability to support those rate to the driver by defining a new set of PLL configs. Signed-off-by: Daniel Scally --- Changes in v3: - Added commas to last items in arrays (Andy) Changes in v2: - Added support for 319.2MHz link frequency drivers/media/i2c/ov7251.c | 93 +++++++++++++++++++++++++++++--------- 1 file changed, 72 insertions(+), 21 deletions(-) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index 3440077e8ba9..9a026354a1bd 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -96,12 +96,14 @@ struct ov7251_pll_cfgs { }; enum xclk_rate { + OV7251_19_2_MHZ, OV7251_24_MHZ, OV7251_NUM_SUPPORTED_RATES }; enum supported_link_freqs { OV7251_LINK_FREQ_240_MHZ, + OV7251_LINK_FREQ_319_2_MHZ, OV7251_NUM_SUPPORTED_LINK_FREQS }; @@ -147,6 +149,22 @@ static inline struct ov7251 *to_ov7251(struct v4l2_subdev *sd) return container_of(sd, struct ov7251, sd); } +static const struct ov7251_pll1_cfg ov7251_pll1_cfg_19_2_mhz_240_mhz = { + .pre_div = 0x03, + .mult = 0x4b, + .div = 0x01, + .pix_div = 0x0a, + .mipi_div = 0x05, +}; + +static const struct ov7251_pll1_cfg ov7251_pll1_cfg_19_2_mhz_319_2_mhz = { + .pre_div = 0x01, + .mult = 0x85, + .div = 0x04, + .pix_div = 0x0a, + .mipi_div = 0x05, +}; + static const struct ov7251_pll1_cfg ov7251_pll1_cfg_24_mhz_240_mhz = { .pre_div = 0x03, .mult = 0x64, @@ -155,6 +173,22 @@ static const struct ov7251_pll1_cfg ov7251_pll1_cfg_24_mhz_240_mhz = { .mipi_div = 0x05, }; +static const struct ov7251_pll1_cfg ov7251_pll1_cfg_24_mhz_319_2_mhz = { + .pre_div = 0x05, + .mult = 0x85, + .div = 0x02, + .pix_div = 0x0a, + .mipi_div = 0x05, +}; + +static const struct ov7251_pll2_cfg ov7251_pll2_cfg_19_2_mhz = { + .pre_div = 0x04, + .mult = 0x32, + .div = 0x00, + .sys_div = 0x05, + .adc_div = 0x04, +}; + static const struct ov7251_pll2_cfg ov7251_pll2_cfg_24_mhz = { .pre_div = 0x04, .mult = 0x28, @@ -163,14 +197,24 @@ static const struct ov7251_pll2_cfg ov7251_pll2_cfg_24_mhz = { .adc_div = 0x04, }; +static const struct ov7251_pll_cfgs ov7251_pll_cfgs_19_2_mhz = { + .pll2 = &ov7251_pll2_cfg_19_2_mhz, + .pll1 = { + [OV7251_LINK_FREQ_240_MHZ] = &ov7251_pll1_cfg_19_2_mhz_240_mhz, + [OV7251_LINK_FREQ_319_2_MHZ] = &ov7251_pll1_cfg_19_2_mhz_319_2_mhz, + }, +}; + static const struct ov7251_pll_cfgs ov7251_pll_cfgs_24_mhz = { .pll2 = &ov7251_pll2_cfg_24_mhz, .pll1 = { [OV7251_LINK_FREQ_240_MHZ] = &ov7251_pll1_cfg_24_mhz_240_mhz, + [OV7251_LINK_FREQ_319_2_MHZ] = &ov7251_pll1_cfg_19_2_mhz_319_2_mhz, }, }; static const struct ov7251_pll_cfgs *ov7251_pll_cfgs[] = { + [OV7251_19_2_MHZ] = &ov7251_pll_cfgs_19_2_mhz, [OV7251_24_MHZ] = &ov7251_pll_cfgs_24_mhz, }; @@ -564,15 +608,18 @@ static const struct reg_value ov7251_setting_vga_90fps[] = { }; static const unsigned long supported_xclk_rates[] = { + [OV7251_19_2_MHZ] = 19200000, [OV7251_24_MHZ] = 24000000, }; static const s64 link_freq[] = { [OV7251_LINK_FREQ_240_MHZ] = 240000000, + [OV7251_LINK_FREQ_319_2_MHZ] = 319200000, }; static const s64 pixel_rates[] = { [OV7251_LINK_FREQ_240_MHZ] = 48000000, + [OV7251_LINK_FREQ_319_2_MHZ] = 63840000, }; static const struct ov7251_mode_info ov7251_mode_info_data[] = { @@ -1399,6 +1446,7 @@ static int ov7251_probe(struct i2c_client *client) struct device *dev = &client->dev; struct ov7251 *ov7251; u8 chip_id_high, chip_id_low, chip_rev; + unsigned int rate = 0, clk_rate = 0; s64 pixel_rate; int ret; int i; @@ -1415,31 +1463,34 @@ static int ov7251_probe(struct i2c_client *client) return ret; /* get system clock (xclk) */ - ov7251->xclk = devm_clk_get(dev, "xclk"); - if (IS_ERR(ov7251->xclk)) { - dev_err(dev, "could not get xclk"); - return PTR_ERR(ov7251->xclk); - } - + ov7251->xclk = devm_clk_get_optional(dev, NULL); + if (IS_ERR(ov7251->xclk)) + return dev_err_probe(dev, PTR_ERR(ov7251->xclk), + "could not get xclk"); + + /* + * We could have either a 24MHz or 19.2MHz clock rate from either DT or + * ACPI. We also need to support the IPU3 case which will have both an + * external clock AND a clock-frequency property. + */ ret = fwnode_property_read_u32(dev_fwnode(dev), "clock-frequency", - &ov7251->xclk_freq); - if (ret) { - dev_err(dev, "could not get xclk frequency\n"); - return ret; - } + &rate); + if (ret && !ov7251->xclk) + return dev_err_probe(dev, ret, "invalid clock config\n"); - /* external clock must be 24MHz, allow 1% tolerance */ - if (ov7251->xclk_freq < 23760000 || ov7251->xclk_freq > 24240000) { - dev_err(dev, "external clock frequency %u is not supported\n", - ov7251->xclk_freq); - return -EINVAL; - } + clk_rate = clk_get_rate(ov7251->xclk); + ov7251->xclk_freq = clk_rate ? clk_rate : rate; - ret = clk_set_rate(ov7251->xclk, ov7251->xclk_freq); - if (ret) { - dev_err(dev, "could not set xclk frequency\n"); - return ret; + if (ov7251->xclk_freq == 0) + return dev_err_probe(dev, -EINVAL, "invalid clock frequency\n"); + + if (!ret && ov7251->xclk) { + ret = clk_set_rate(ov7251->xclk, rate); + if (ret) + return dev_err_probe(dev, ret, + "failed to set clock rate\n"); } + for (i = 0; i < ARRAY_SIZE(supported_xclk_rates); i++) if (ov7251->xclk_freq == supported_xclk_rates[i]) break; From patchwork Wed May 4 22:30:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 569447 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37D0EC433FE for ; Wed, 4 May 2022 22:31:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379022AbiEDWeg (ORCPT ); Wed, 4 May 2022 18:34:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379017AbiEDWe1 (ORCPT ); Wed, 4 May 2022 18:34:27 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 466FE2CCB2 for ; Wed, 4 May 2022 15:30:49 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id q23so3819219wra.1 for ; Wed, 04 May 2022 15:30:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QaTy596hjpCuJ4YtlTzP5tm8cIDyNQDsq0OFIc7xRfU=; b=h/Kvzn4FHfNyrxUAhRrPTO9fryIxl/c608jum2ANU7QZ7cUDcLTr8S84coVIEOXAaI HV5NKoCsoWD4B5fNircPIITR4I2ddUhBQhbO7xIJA1NTQ1AWVJD3daGvnhukoqPo/CwL v4cvF7/NZxDXD+hfeldWiaei03YJaJH0KafKzEm8LBGAS420EONEdc1zdYz629weorIw nKvnBXpISRc7PFbUw3mLaT5EU5IJ8C4mPXQetLeMXb5aSb9LWFvy6QaEg48Erum249JT Gh0xPY+DvLDOx7EYuV7jGcZVUWaRqg7T4bPo7mArx9Kbfn2RApLbWYRM/UggbHXyIYlt CePA== 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=QaTy596hjpCuJ4YtlTzP5tm8cIDyNQDsq0OFIc7xRfU=; b=nvu5zyPrx4wyoQBRn74naKgHtGlYyaRTUP7Lmsh5AQnoGvjlNg7YzkLJfjbl6WqKi6 AyyQKXnTYK/tjpbWTQmeTnCKMYg8EPXyNyHppyZFLa4b7Vrpo+oKZZ1wfZgz5vCil4SV ZEcDzJQCoGSZRGh69ETW+sHEZ+qoVtO/WIupPm6S3kdnjooi4DTcHcD87aINNDAVfzP7 +GK5e1ZDJvtkvKUMkQ90VC88gUFaas3xina2pFzvfzxA5nwfUjWcQYD7/ZhdFBrpxI43 eddxUtwaCiBFmhNhcjOS4N6gCwxXF9+H+n5IDb1qO9W/+5vKXY87+1BB736Hh7IZ6KKy MjBg== X-Gm-Message-State: AOAM532QkZKMFsrOzOR1b7goymk3H4hDeLCO3M8DmmQKgMvVFID9BRxv 1mxroaMDrr81ufKA34jWFEG/igdtIQI= X-Google-Smtp-Source: ABdhPJw5UTX+aSBxpoBVJP8+YFq2T8R10qOwXAsPnlTZmO8yzxkQbjFLfHQbheoyxseKtlMxf84bOw== X-Received: by 2002:a5d:6d0b:0:b0:20c:4ec7:8e84 with SMTP id e11-20020a5d6d0b000000b0020c4ec78e84mr18001779wrq.281.1651703448882; Wed, 04 May 2022 15:30:48 -0700 (PDT) Received: from localhost.localdomain (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161]) by smtp.gmail.com with ESMTPSA id h29-20020adfaa9d000000b0020c5253d913sm12501442wrc.95.2022.05.04.15.30.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 15:30:48 -0700 (PDT) From: Daniel Scally To: linux-media@vger.kernel.org Cc: yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, andriy.shevchenko@linux.intel.com, hverkuil-cisco@xs4all.nl Subject: [PATCH v3 09/15] media: i2c: Add pm_runtime support to ov7251 Date: Wed, 4 May 2022 23:30:21 +0100 Message-Id: <20220504223027.3480287-10-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220504223027.3480287-1-djrscally@gmail.com> References: <20220504223027.3480287-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add pm_runtime support to the ov7251 driver. Signed-off-by: Daniel Scally --- Changes in v3: - None Changes in v2: - Switched ov7251_set_power_[on|off]() to take a struct device * as the input parameter and used those functions for pm_runtime instead of adding wrappers (Sakari) drivers/media/i2c/ov7251.c | 81 ++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 21 deletions(-) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index ff31629839f9..a9e890181200 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -883,8 +884,11 @@ static int ov7251_set_register_array(struct ov7251 *ov7251, return 0; } -static int ov7251_set_power_on(struct ov7251 *ov7251) +static int ov7251_set_power_on(struct device *dev) { + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct v4l2_subdev *sd = i2c_get_clientdata(client); + struct ov7251 *ov7251 = to_ov7251(sd); int ret; u32 wait_us; @@ -909,11 +913,17 @@ static int ov7251_set_power_on(struct ov7251 *ov7251) return 0; } -static void ov7251_set_power_off(struct ov7251 *ov7251) +static int ov7251_set_power_off(struct device *dev) { + struct i2c_client *client = container_of(dev, struct i2c_client, dev); + struct v4l2_subdev *sd = i2c_get_clientdata(client); + struct ov7251 *ov7251 = to_ov7251(sd); + clk_disable_unprepare(ov7251->xclk); gpiod_set_value_cansleep(ov7251->enable_gpio, 0); ov7251_regulators_disable(ov7251); + + return 0; } static int ov7251_s_power(struct v4l2_subdev *sd, int on) @@ -928,7 +938,7 @@ static int ov7251_s_power(struct v4l2_subdev *sd, int on) goto exit; if (on) { - ret = ov7251_set_power_on(ov7251); + ret = ov7251_set_power_on(ov7251->dev); if (ret < 0) goto exit; @@ -937,13 +947,13 @@ static int ov7251_s_power(struct v4l2_subdev *sd, int on) ARRAY_SIZE(ov7251_global_init_setting)); if (ret < 0) { dev_err(ov7251->dev, "could not set init registers\n"); - ov7251_set_power_off(ov7251); + ov7251_set_power_off(ov7251->dev); goto exit; } ov7251->power_on = true; } else { - ov7251_set_power_off(ov7251); + ov7251_set_power_off(ov7251->dev); ov7251->power_on = false; } @@ -1017,7 +1027,7 @@ static int ov7251_s_ctrl(struct v4l2_ctrl *ctrl) /* v4l2_ctrl_lock() locks our mutex */ - if (!ov7251->power_on) + if (!pm_runtime_get_if_in_use(ov7251->dev)) return 0; switch (ctrl->id) { @@ -1041,6 +1051,8 @@ static int ov7251_s_ctrl(struct v4l2_ctrl *ctrl) break; } + pm_runtime_put(ov7251->dev); + return ret; } @@ -1283,10 +1295,15 @@ static int ov7251_s_stream(struct v4l2_subdev *subdev, int enable) mutex_lock(&ov7251->lock); if (enable) { + ret = pm_runtime_get_sync(ov7251->dev); + if (ret < 0) + goto unlock_out; + ret = ov7251_pll_configure(ov7251); - if (ret) - return dev_err_probe(ov7251->dev, ret, - "error configuring PLLs\n"); + if (ret) { + dev_err(ov7251->dev, "error configuring PLLs\n"); + goto err_power_down; + } ret = ov7251_set_register_array(ov7251, ov7251->current_mode->data, @@ -1295,23 +1312,29 @@ static int ov7251_s_stream(struct v4l2_subdev *subdev, int enable) dev_err(ov7251->dev, "could not set mode %dx%d\n", ov7251->current_mode->width, ov7251->current_mode->height); - goto exit; + goto err_power_down; } ret = __v4l2_ctrl_handler_setup(&ov7251->ctrls); if (ret < 0) { dev_err(ov7251->dev, "could not sync v4l2 controls\n"); - goto exit; + goto err_power_down; } ret = ov7251_write_reg(ov7251, OV7251_SC_MODE_SELECT, OV7251_SC_MODE_SELECT_STREAMING); + if (ret) + goto err_power_down; } else { ret = ov7251_write_reg(ov7251, OV7251_SC_MODE_SELECT, OV7251_SC_MODE_SELECT_SW_STANDBY); + pm_runtime_put(ov7251->dev); } -exit: +unlock_out: mutex_unlock(&ov7251->lock); + return ret; +err_power_down: + pm_runtime_put_noidle(ov7251->dev); return ret; } @@ -1614,23 +1637,24 @@ static int ov7251_probe(struct i2c_client *client) goto free_ctrl; } - ret = ov7251_s_power(&ov7251->sd, true); - if (ret < 0) { - dev_err(dev, "could not power up OV7251\n"); + ret = ov7251_set_power_on(ov7251->dev); + if (ret) goto free_entity; - } ret = ov7251_detect_chip(ov7251); if (ret) goto power_down; + pm_runtime_set_active(&client->dev); + pm_runtime_get_noresume(&client->dev); + pm_runtime_enable(&client->dev); ret = ov7251_read_reg(ov7251, OV7251_PRE_ISP_00, &ov7251->pre_isp_00); if (ret < 0) { dev_err(dev, "could not read test pattern value\n"); ret = -ENODEV; - goto power_down; + goto err_pm_runtime; } ret = ov7251_read_reg(ov7251, OV7251_TIMING_FORMAT1, @@ -1638,7 +1662,7 @@ static int ov7251_probe(struct i2c_client *client) if (ret < 0) { dev_err(dev, "could not read vflip value\n"); ret = -ENODEV; - goto power_down; + goto err_pm_runtime; } ret = ov7251_read_reg(ov7251, OV7251_TIMING_FORMAT2, @@ -1646,10 +1670,12 @@ static int ov7251_probe(struct i2c_client *client) if (ret < 0) { dev_err(dev, "could not read hflip value\n"); ret = -ENODEV; - goto power_down; + goto err_pm_runtime; } - ov7251_s_power(&ov7251->sd, false); + pm_runtime_set_autosuspend_delay(&client->dev, 1000); + pm_runtime_use_autosuspend(&client->dev); + pm_runtime_put_autosuspend(&client->dev); ret = v4l2_async_register_subdev(&ov7251->sd); if (ret < 0) { @@ -1661,8 +1687,11 @@ static int ov7251_probe(struct i2c_client *client) return 0; +err_pm_runtime: + pm_runtime_disable(ov7251->dev); + pm_runtime_put_noidle(ov7251->dev); power_down: - ov7251_s_power(&ov7251->sd, false); + ov7251_set_power_off(ov7251->dev); free_entity: media_entity_cleanup(&ov7251->sd.entity); free_ctrl: @@ -1682,9 +1711,18 @@ static int ov7251_remove(struct i2c_client *client) v4l2_ctrl_handler_free(&ov7251->ctrls); mutex_destroy(&ov7251->lock); + pm_runtime_disable(ov7251->dev); + if (!pm_runtime_status_suspended(ov7251->dev)) + ov7251_set_power_off(ov7251->dev); + pm_runtime_set_suspended(ov7251->dev); + return 0; } +static const struct dev_pm_ops ov7251_pm_ops = { + SET_RUNTIME_PM_OPS(ov7251_set_power_off, ov7251_set_power_on, NULL) +}; + static const struct of_device_id ov7251_of_match[] = { { .compatible = "ovti,ov7251" }, { /* sentinel */ } @@ -1702,6 +1740,7 @@ static struct i2c_driver ov7251_i2c_driver = { .of_match_table = ov7251_of_match, .acpi_match_table = ov7251_acpi_match, .name = "ov7251", + .pm = &ov7251_pm_ops, }, .probe_new = ov7251_probe, .remove = ov7251_remove, From patchwork Wed May 4 22:30:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 569446 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93BA3C433F5 for ; Wed, 4 May 2022 22:31:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230058AbiEDWei (ORCPT ); Wed, 4 May 2022 18:34:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237672AbiEDWe3 (ORCPT ); Wed, 4 May 2022 18:34:29 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA6B72B1A9 for ; Wed, 4 May 2022 15:30:51 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id j15so3824577wrb.2 for ; Wed, 04 May 2022 15:30:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WHkXA0eWimFClf7wSQc2ZrjEMI+cQiIgeyRQAJkX8CA=; b=TfS2izcwGf47DyV64epBDbX/zwrWVe7vCWYHk0cGa6rr+ABcy26O8bIjEZq/hoOym/ RQgSrJexTFcE9XLZ4AJKc1N8WZYQwVW1CrUPZ7U5c7yMtyzj+wfXSpRDlBY/DuRdQFuC 4TerNxxr8iCAlUnR9yegnh6lga1CbqhdwzEDDkJg6u/HgnAO7Km6wE3wdp5o0M6Rddm8 DbcufTFlWDHiNuhyC81Bj8cJH6f4grmIStWw1hfYlJRNpyUu3sR+ZRqeyTxGNYYvFm5P zgKswJ8M53sISq7KuyDFAG3IBpC96uzu7uIW8LddhTdgZ44yhot4urjfHurfjJ+YEVMe 1qTQ== 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=WHkXA0eWimFClf7wSQc2ZrjEMI+cQiIgeyRQAJkX8CA=; b=akWWVvhpdLjauirYqchNC2fvAWidFoXbfZ/gtL//l3coC2Ww7Pucw8B3UmdBZi1ZOE O6v5KBvOlV5mzL9vIL65ctP0hqf8xbe99fkagFS3BkM+OVhhy9mKJkIlVoLA33a7e6JX +vOHsxnb8mquY7CY+ysrU1uDT0lf4ESUl4mZPe/rMqrh6VzR3s165pNar/ECAhYhdlC3 EMvc8JiF8s1kzWVaGqhEYqrVw5KHwIbA1DjIjkghsvOdr8nStC4noMeu6VqEO8/HoLRP eLTtd63jnVb7LCeFPhCvOsZmg5HvQofgSKTi4A3dKuJ29FXEwe5BXhRNes220+XF1rEf l6mA== X-Gm-Message-State: AOAM5318AP1o3XxTdxBI3arxrEz/nzIgRpZ+C118Ky7jgOu5vPkLDr+z /ke2olNgYWSoQWiUlCEc8pOHUPydHNY= X-Google-Smtp-Source: ABdhPJxxMa4UpqpSPQP6SYzdaE5jFYbEuQe6teDjFZm90JOelcwqFLz/G2gMnmXciJnvif853OckFg== X-Received: by 2002:a5d:608b:0:b0:20c:7a44:d8c1 with SMTP id w11-20020a5d608b000000b0020c7a44d8c1mr6488064wrt.287.1651703450609; Wed, 04 May 2022 15:30:50 -0700 (PDT) Received: from localhost.localdomain (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161]) by smtp.gmail.com with ESMTPSA id h29-20020adfaa9d000000b0020c5253d913sm12501442wrc.95.2022.05.04.15.30.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 15:30:50 -0700 (PDT) From: Daniel Scally To: linux-media@vger.kernel.org Cc: yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, andriy.shevchenko@linux.intel.com, hverkuil-cisco@xs4all.nl Subject: [PATCH v3 11/15] media: ipu3-cio2: Add INT347E to cio2-bridge Date: Wed, 4 May 2022 23:30:23 +0100 Message-Id: <20220504223027.3480287-12-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220504223027.3480287-1-djrscally@gmail.com> References: <20220504223027.3480287-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The OVTI7251 sensor can be found on x86 laptops with an IPU3, and so needs to be supported by the cio2-bridge. Add it to the table of supported sensors. Signed-off-by: Daniel Scally --- Changes in v3: - None Changes in v2: - Switched to 319.2MHz link frequency drivers/media/pci/intel/ipu3/cio2-bridge.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/media/pci/intel/ipu3/cio2-bridge.c b/drivers/media/pci/intel/ipu3/cio2-bridge.c index 7ccb7b6eaa82..df6c94da2f6a 100644 --- a/drivers/media/pci/intel/ipu3/cio2-bridge.c +++ b/drivers/media/pci/intel/ipu3/cio2-bridge.c @@ -25,6 +25,8 @@ static const struct cio2_sensor_config cio2_supported_sensors[] = { CIO2_SENSOR_CONFIG("INT33BE", 1, 419200000), /* Omnivision OV8865 */ CIO2_SENSOR_CONFIG("INT347A", 1, 360000000), + /* Omnivision OV7251 */ + CIO2_SENSOR_CONFIG("INT347E", 1, 319200000), /* Omnivision OV2680 */ CIO2_SENSOR_CONFIG("OVTI2680", 0), }; From patchwork Wed May 4 22:30:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 569445 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E11DC4332F for ; Wed, 4 May 2022 22:31:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379029AbiEDWej (ORCPT ); Wed, 4 May 2022 18:34:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379016AbiEDWec (ORCPT ); Wed, 4 May 2022 18:34:32 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C69A22B1A9 for ; Wed, 4 May 2022 15:30:53 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id b19so3785968wrh.11 for ; Wed, 04 May 2022 15:30:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2eDW0BkW1kWUmwBj+d757dRPQwwJ5Jr+wGnJbIglmFg=; b=InoEXzoXVvu7ohM2j2+wJT8HuS+AQnwtelUDMJXdtwPo4rsaT2HwDPEpIPsA98xvgN YG183eMB3JGFl25kN+yj652N3M1SEMgKkRX6LkZkjf9kAW0mZuEfKuGeg+VDLUS/0/cA a+4YcQc26Dw0cj5SgjBLZmNLVp2GnYJK9dEIJHJv79azvMCj4/9ajsjokB4YY6iwbCsC 45H8g1mS/9m2KPcfm9D8DswxmkR5AcVSMYyaPOJu26h01t6+yfRcVLIxGtVx3BmK0nf4 HTywfu76dU5xTP0lu/q9xGXkQ4/SOsvHjGKcYX5AhUop+2+WG2o1S1w3EPQ9VcTTXGrV kAnw== 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=2eDW0BkW1kWUmwBj+d757dRPQwwJ5Jr+wGnJbIglmFg=; b=EQxUbRSp1X/dfvtr4Po2+e1jWDd08hirruXNyn9hOMjiw2eWkhsg9Yj9Ql19oAl5B6 5RwGwyunovTvTM9f1F/ezebNC2oV3XAlrj9EEflt4XScQypNZ/YgiWpbNelQ+UfzfBWU wIkxPSyXOgD6COQ/7jcUFTjMCqyFqauKaAro545vr7agWueuF6eL3mWu5NhAH4luFX/4 oTm6gQYIZi9PnT8gUma28OyocqZe4uaetJBiRpgTx+OyEq14OyG219DZ8fifUNHSXhBn 8w1bc3Z2qfqqrzD8zsXuLnf/NqHHyz+Q76Jn+5sZLmka/3bG+7Qjn7xvXpKtU/fN/WxF 3blw== X-Gm-Message-State: AOAM530Gpk6iDgOncPFgr+EZ5de0swgxHFp0KhDIqV4THb/baEyk4i5d na7GeOP0P07o8u/FgZ+nSh1m74TWzKk= X-Google-Smtp-Source: ABdhPJx1e1vcc9pEHZm7rmVpoiyyVBt83QaVuvecgsh1f2nsh/1B+RBf5ZBvWFp8x1Y9K/2buQG9HA== X-Received: by 2002:a5d:60c3:0:b0:20c:4fa3:c63e with SMTP id x3-20020a5d60c3000000b0020c4fa3c63emr18371944wrt.191.1651703453398; Wed, 04 May 2022 15:30:53 -0700 (PDT) Received: from localhost.localdomain (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161]) by smtp.gmail.com with ESMTPSA id h29-20020adfaa9d000000b0020c5253d913sm12501442wrc.95.2022.05.04.15.30.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 15:30:53 -0700 (PDT) From: Daniel Scally To: linux-media@vger.kernel.org Cc: yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, andriy.shevchenko@linux.intel.com, hverkuil-cisco@xs4all.nl Subject: [PATCH v3 14/15] media: i2c: Add hblank control to ov7251 Date: Wed, 4 May 2022 23:30:26 +0100 Message-Id: <20220504223027.3480287-15-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220504223027.3480287-1-djrscally@gmail.com> References: <20220504223027.3480287-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add a hblank control to the ov7251 driver. This necessitates setting a default mode, for which I am simply picking the first available. Signed-off-by: Daniel Scally --- Changes in v3: - New patch drivers/media/i2c/ov7251.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index b7d89ad49887..003a7a5ae038 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -61,6 +61,8 @@ #define OV7251_ACTIVE_WIDTH 648 #define OV7251_ACTIVE_HEIGHT 488 +#define OV7251_FIXED_PPL 928 + struct reg_value { u16 reg; u8 val; @@ -139,6 +141,7 @@ struct ov7251 { struct v4l2_ctrl *link_freq; struct v4l2_ctrl *exposure; struct v4l2_ctrl *gain; + struct v4l2_ctrl *hblank; /* Cached register values */ u8 aec_pk_manual; @@ -1490,6 +1493,7 @@ static int ov7251_detect_chip(struct ov7251 *ov7251) static int ov7251_init_ctrls(struct ov7251 *ov7251) { s64 pixel_rate; + int hblank; v4l2_ctrl_handler_init(&ov7251->ctrls, 7); ov7251->ctrls.lock = &ov7251->lock; @@ -1524,6 +1528,13 @@ static int ov7251_init_ctrls(struct ov7251 *ov7251) if (ov7251->pixel_clock) ov7251->pixel_clock->flags |= V4L2_CTRL_FLAG_READ_ONLY; + hblank = OV7251_FIXED_PPL - ov7251->current_mode->width; + ov7251->hblank = v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops, + V4L2_CID_HBLANK, hblank, hblank, 1, + hblank); + if (ov7251->hblank) + ov7251->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; + ov7251->sd.ctrl_handler = &ov7251->ctrls; if (ov7251->ctrls.error) { @@ -1619,6 +1630,7 @@ static int ov7251_probe(struct i2c_client *client) mutex_init(&ov7251->lock); + ov7251->current_mode = &ov7251_mode_info_data[0]; ret = ov7251_init_ctrls(ov7251); if (ret) { dev_err_probe(dev, ret, "error during v4l2 ctrl init\n"); From patchwork Wed May 4 22:30:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 569444 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5356AC433EF for ; Wed, 4 May 2022 22:31:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235162AbiEDWem (ORCPT ); Wed, 4 May 2022 18:34:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1354265AbiEDWef (ORCPT ); Wed, 4 May 2022 18:34:35 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA1542B24F for ; Wed, 4 May 2022 15:30:54 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id w4so3786136wrg.12 for ; Wed, 04 May 2022 15:30:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wi29Ap2zgAim6yF6i/K40HPuBvWXM5rGaocel2NVWbk=; b=WFYdXcicFf+w7uqHvwNP2KiitwYLQufA3VTmr1qMNPqbo75gYhiFP1gu0tHkdzvMRc pV85j+0oeB7eL4KY/RPM7MIefy2zm4zvS1IOnILlTEAEknI3ITdM9+rEytCpjxXFxV1R ZSadH2pR0iKC0vsCa7ec4iTExFrU1v6FxJnydYKkxeSbxD7LYSQv6jBG+GeBVIYDcf6U aZY4Rbrdx+aqvH3YHypEXMczimycDVb/tCsETwECgsF86s1bEiW71XYneRdD4byTY8kr vgjg4Q62OLvnlD9XDvL6jBjm5P/wlPJQRv7BAOQNK5LUW6ibvCXoMULSo0Pbwl0PNNy/ kK9A== 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=wi29Ap2zgAim6yF6i/K40HPuBvWXM5rGaocel2NVWbk=; b=DknUlCl0YRahQAFJRFC4Viljdtg1zMwpKjrPKW8UEkYYztCGiNs3DBHUKkEhxhi4vj LTROeZIuCXwuXzgXyOE1hraL6VGoEN/8OGaQfF/GsNY6oN/cFQmH0RtpTQd66aYmTdoT 0YHtTv0v9nWq8evh3t0nH9jKh8u01fv2vxlpn/Pe/lKGgq1TQ6Ni0MhS7SBOrUjLXlZe bJZ3lubB7Z1sExUgLh7J2nrRrqHC1liGVagX4vNiHOlZUrQgVs2+/B+GRzBac0xPsElM Gav+6ExC9uTXxu7FOIHeqlue4uX434R12K+VBdNRpY5oUoxfUOYiwURhz/5aQzylS+t7 aK6A== X-Gm-Message-State: AOAM5319f1simIygza9ZKO/YsNZgBdrvCY8wvpnOKDV3fzuaukpfn2ue xA4QCeFeT7uhNEU8MlS1ggX0/6DredA= X-Google-Smtp-Source: ABdhPJwGsbesHhAeitfwFQNOJ0B2hpa+3C5VAcEAyshQgbxgLC+b+BcQullao8RFZKQmi+VR1Ln7pg== X-Received: by 2002:a5d:414a:0:b0:20a:d5f9:8b62 with SMTP id c10-20020a5d414a000000b0020ad5f98b62mr18431961wrq.492.1651703454291; Wed, 04 May 2022 15:30:54 -0700 (PDT) Received: from localhost.localdomain (cpc141996-chfd3-2-0-cust928.12-3.cable.virginm.net. [86.13.91.161]) by smtp.gmail.com with ESMTPSA id h29-20020adfaa9d000000b0020c5253d913sm12501442wrc.95.2022.05.04.15.30.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 May 2022 15:30:53 -0700 (PDT) From: Daniel Scally To: linux-media@vger.kernel.org Cc: yong.zhi@intel.com, sakari.ailus@linux.intel.com, bingbu.cao@intel.com, tian.shu.qiu@intel.com, andriy.shevchenko@linux.intel.com, hverkuil-cisco@xs4all.nl Subject: [PATCH v3 15/15] media: i2c: Add vblank control to ov7251 driver Date: Wed, 4 May 2022 23:30:27 +0100 Message-Id: <20220504223027.3480287-16-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220504223027.3480287-1-djrscally@gmail.com> References: <20220504223027.3480287-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Add a vblank control to the ov7251 driver. Signed-off-by: Daniel Scally --- Changes in v3: - New patch drivers/media/i2c/ov7251.c | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index 003a7a5ae038..dc9d4e08efae 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -62,6 +62,10 @@ #define OV7251_ACTIVE_HEIGHT 488 #define OV7251_FIXED_PPL 928 +#define OV7251_TIMING_VTS_REG 0x380e +#define OV7251_TIMING_MIN_VTS 1 +#define OV7251_TIMING_MAX_VTS 0xffff +#define OV7251_INTEGRATION_MARGIN 20 struct reg_value { u16 reg; @@ -71,6 +75,7 @@ struct reg_value { struct ov7251_mode_info { u32 width; u32 height; + u32 vts; const struct reg_value *data; u32 data_size; u32 pixel_clock; @@ -142,6 +147,7 @@ struct ov7251 { struct v4l2_ctrl *exposure; struct v4l2_ctrl *gain; struct v4l2_ctrl *hblank; + struct v4l2_ctrl *vblank; /* Cached register values */ u8 aec_pk_manual; @@ -637,6 +643,7 @@ static const struct ov7251_mode_info ov7251_mode_info_data[] = { { .width = 640, .height = 480, + .vts = 1724, .data = ov7251_setting_vga_30fps, .data_size = ARRAY_SIZE(ov7251_setting_vga_30fps), .exposure_max = 1704, @@ -649,6 +656,7 @@ static const struct ov7251_mode_info ov7251_mode_info_data[] = { { .width = 640, .height = 480, + .vts = 860, .data = ov7251_setting_vga_60fps, .data_size = ARRAY_SIZE(ov7251_setting_vga_60fps), .exposure_max = 840, @@ -661,6 +669,7 @@ static const struct ov7251_mode_info ov7251_mode_info_data[] = { { .width = 640, .height = 480, + .vts = 572, .data = ov7251_setting_vga_90fps, .data_size = ARRAY_SIZE(ov7251_setting_vga_90fps), .exposure_max = 552, @@ -1001,12 +1010,36 @@ static const char * const ov7251_test_pattern_menu[] = { "Vertical Pattern Bars", }; +static int ov7251_vts_configure(struct ov7251 *ov7251, s32 vblank) +{ + u8 vts[2]; + + vts[0] = ((ov7251->current_mode->height + vblank) & 0xff00) >> 8; + vts[1] = ((ov7251->current_mode->height + vblank) & 0x00ff); + + return ov7251_write_seq_regs(ov7251, OV7251_TIMING_VTS_REG, vts, 2); +} + static int ov7251_s_ctrl(struct v4l2_ctrl *ctrl) { struct ov7251 *ov7251 = container_of(ctrl->handler, struct ov7251, ctrls); int ret; + /* If VBLANK is altered we need to update exposure to compensate */ + if (ctrl->id == V4L2_CID_VBLANK) { + int exposure_max; + + exposure_max = ov7251->current_mode->height + ctrl->val - + OV7251_INTEGRATION_MARGIN; + __v4l2_ctrl_modify_range(ov7251->exposure, + ov7251->exposure->minimum, + exposure_max, + ov7251->exposure->step, + min(ov7251->exposure->val, + exposure_max)); + } + /* v4l2_ctrl_lock() locks our mutex */ if (!pm_runtime_get_if_in_use(ov7251->dev)) @@ -1028,6 +1061,9 @@ static int ov7251_s_ctrl(struct v4l2_ctrl *ctrl) case V4L2_CID_VFLIP: ret = ov7251_set_vflip(ov7251, ctrl->val); break; + case V4L2_CID_VBLANK: + ret = ov7251_vts_configure(ov7251, ctrl->val); + break; default: ret = -EINVAL; break; @@ -1179,6 +1215,7 @@ static int ov7251_set_format(struct v4l2_subdev *sd, { struct ov7251 *ov7251 = to_ov7251(sd); struct v4l2_mbus_framefmt *__format; + int vblank_max, vblank_def; struct v4l2_rect *__crop; const struct ov7251_mode_info *new_mode; int ret = 0; @@ -1212,6 +1249,14 @@ static int ov7251_set_format(struct v4l2_subdev *sd, if (ret < 0) goto exit; + vblank_max = OV7251_TIMING_MAX_VTS - new_mode->height; + vblank_def = new_mode->vts - new_mode->height; + ret = __v4l2_ctrl_modify_range(ov7251->vblank, + OV7251_TIMING_MIN_VTS, + vblank_max, 1, vblank_max); + if (ret < 0) + goto exit; + ov7251->current_mode = new_mode; } @@ -1492,6 +1537,7 @@ static int ov7251_detect_chip(struct ov7251 *ov7251) static int ov7251_init_ctrls(struct ov7251 *ov7251) { + int vblank_max, vblank_def; s64 pixel_rate; int hblank; @@ -1535,6 +1581,13 @@ static int ov7251_init_ctrls(struct ov7251 *ov7251) if (ov7251->hblank) ov7251->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY; + vblank_max = OV7251_TIMING_MAX_VTS - ov7251->current_mode->height; + vblank_def = ov7251->current_mode->vts - ov7251->current_mode->height; + ov7251->vblank = v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops, + V4L2_CID_VBLANK, + OV7251_TIMING_MIN_VTS, vblank_max, 1, + vblank_def); + ov7251->sd.ctrl_handler = &ov7251->ctrls; if (ov7251->ctrls.error) {