From patchwork Thu May 5 23:03:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12840298 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 13FCDC433EF for ; Thu, 5 May 2022 23:04:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386539AbiEEXH4 (ORCPT ); Thu, 5 May 2022 19:07:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1376753AbiEEXHz (ORCPT ); Thu, 5 May 2022 19:07:55 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 392685EDC5 for ; Thu, 5 May 2022 16:04:14 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id c11so7862281wrn.8 for ; Thu, 05 May 2022 16:04:14 -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=3yRBimETvMKoEZ9GRMhY+DUHxkl2xKneFEksDYjOGEs=; b=luVxLs/m6lasuWakg4kbOVdqxYVR5rasM0ggCAvNg5hqGpPO1fQvjP6d+wRQ/9b+ap oASlbcTxxmLlfiHCWjqzRT3VoDn9WJ1XSaAuUmlKlrzWUMIPElky9UR6GxT1gGo/yYoH Ub8238Jk5Ees50FNDU+ysSs9KKCn/rhZpnnHkwd0sjjd9toSqU9ean6Ir+Q7w1362o1F ATxUbLKAcxldTBcRVH+xCCm85yR8PcFS2xi35bEzh5BcD9YK8fL50oV57MX2TL/iSPFf znBhtdpxplh94wierwSvvuw4/4AFwBgJ7GiQRWX9qNFBiOm451rhdz1f7zWdg/vSwn/0 4/mA== 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=3yRBimETvMKoEZ9GRMhY+DUHxkl2xKneFEksDYjOGEs=; b=FhkTJaJwpeX36GzWZ4K6T3SypVAYrVI7jLQKF44b7gV+cnrQZ+hPDStlTiSS279YQA Za7qSl7Oll/fz8M3AzV9VKyy+jVUQC+4RTMKQEaryPHSQcuCnFVQYtM5JT/a92JkTbbt rJJT/6vjVcwT9SYaAV7vNMjFjUlAF4S0+dVtsMciiLEF27Ef0KwoFeivaJXhoncvaBB5 n+YAxc7l8Xe4M58HXY5axMbjcp+ozxgciHkcz2Zw8Mr6A/ND9aauzf9E+gr9iFp3pwbM wg/cDUXp0X9hh/ujU8ZzFK6fs2BETKJXIuQeSaZkhwyLlWxS55h1Rpb2R9grtV9BzfYw qnAQ== X-Gm-Message-State: AOAM531DqM+auQ/h5PeYLJDSUwIf6v8ujX0VrTPxF/D5fOaHm+oVi1Yn STX5857I3rVHrtbMKXXK/qP98w8k0Uw= X-Google-Smtp-Source: ABdhPJxAmVNgxQnnIGSM7P7JO8VCP3BtgPgJJDwDUM5dX1WEDA1NUlhjkzv2bnng9frXlk453M+VGA== X-Received: by 2002:adf:f6d1:0:b0:20a:d5ca:6dc0 with SMTP id y17-20020adff6d1000000b0020ad5ca6dc0mr311135wrp.292.1651791852726; Thu, 05 May 2022 16:04:12 -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 o20-20020a05600c339400b003942a244f33sm6782130wmp.12.2022.05.05.16.04.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 16:04:12 -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 v4 01/15] media: uapi: Add IPU3 packed Y10 format Date: Fri, 6 May 2022 00:03:48 +0100 Message-Id: <20220505230402.449643-2-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505230402.449643-1-djrscally@gmail.com> References: <20220505230402.449643-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Some platforms with an Intel IPU3 have an IR sensor producing 10 bit greyscale format data that is transmitted over a CSI-2 bus to a CIO2 device - this packs the data into 32 bytes per 25 pixels. Add an entry to the uAPI header defining that format. Signed-off-by: Daniel Scally --- Changes in v4: - None Changes in v3: - None Changes in v2: - Switched away from using the fourcc in the explanatory note for pixfmt-yuv-luma.rst (Nicolas) .../userspace-api/media/v4l/pixfmt-yuv-luma.rst | 14 +++++++++++++- drivers/media/v4l2-core/v4l2-ioctl.c | 1 + include/uapi/linux/videodev2.h | 3 ++- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/Documentation/userspace-api/media/v4l/pixfmt-yuv-luma.rst b/Documentation/userspace-api/media/v4l/pixfmt-yuv-luma.rst index 8ebd58c3588f..6a387f9df3ba 100644 --- a/Documentation/userspace-api/media/v4l/pixfmt-yuv-luma.rst +++ b/Documentation/userspace-api/media/v4l/pixfmt-yuv-luma.rst @@ -48,6 +48,17 @@ are often referred to as greyscale formats. - ... - ... + * .. _V4L2-PIX-FMT-IPU3-Y10: + + - ``V4L2_PIX_FMT_IPU3_Y10`` + - 'ip3y' + + - Y'\ :sub:`0`\ [7:0] + - Y'\ :sub:`1`\ [5:0] Y'\ :sub:`0`\ [9:8] + - Y'\ :sub:`2`\ [3:0] Y'\ :sub:`1`\ [9:6] + - Y'\ :sub:`3`\ [1:0] Y'\ :sub:`2`\ [9:4] + - Y'\ :sub:`3`\ [9:2] + * .. _V4L2-PIX-FMT-Y10: - ``V4L2_PIX_FMT_Y10`` @@ -133,4 +144,5 @@ are often referred to as greyscale formats. For the Y16 and Y16_BE formats, the actual sampling precision may be lower than 16 bits. For example, 10 bits per pixel uses values in the range 0 to - 1023. + 1023. For the IPU3_Y10 format 25 pixels are packed into 32 bytes, which + leaves the 6 most significant bits of the last byte padded with 0. diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 642cb90f457c..89691bbb372d 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -1265,6 +1265,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt) case V4L2_PIX_FMT_Y16_BE: descr = "16-bit Greyscale BE"; break; case V4L2_PIX_FMT_Y10BPACK: descr = "10-bit Greyscale (Packed)"; break; case V4L2_PIX_FMT_Y10P: descr = "10-bit Greyscale (MIPI Packed)"; break; + case V4L2_PIX_FMT_IPU3_Y10: descr = "10-bit greyscale (IPU3 Packed)"; break; case V4L2_PIX_FMT_Y8I: descr = "Interleaved 8-bit Greyscale"; break; case V4L2_PIX_FMT_Y12I: descr = "Interleaved 12-bit Greyscale"; break; case V4L2_PIX_FMT_Z16: descr = "16-bit Depth"; break; diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index df8b9c486ba1..34329f4655e0 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -569,6 +569,7 @@ struct v4l2_pix_format { /* Grey bit-packed formats */ #define V4L2_PIX_FMT_Y10BPACK v4l2_fourcc('Y', '1', '0', 'B') /* 10 Greyscale bit-packed */ #define V4L2_PIX_FMT_Y10P v4l2_fourcc('Y', '1', '0', 'P') /* 10 Greyscale, MIPI RAW10 packed */ +#define V4L2_PIX_FMT_IPU3_Y10 v4l2_fourcc('i', 'p', '3', 'y') /* IPU3 packed 10-bit greyscale */ /* Palette formats */ #define V4L2_PIX_FMT_PAL8 v4l2_fourcc('P', 'A', 'L', '8') /* 8 8-bit palette */ @@ -745,7 +746,7 @@ struct v4l2_pix_format { #define V4L2_PIX_FMT_CNF4 v4l2_fourcc('C', 'N', 'F', '4') /* Intel 4-bit packed depth confidence information */ #define V4L2_PIX_FMT_HI240 v4l2_fourcc('H', 'I', '2', '4') /* BTTV 8-bit dithered RGB */ -/* 10bit raw bayer packed, 32 bytes for every 25 pixels, last LSB 6 bits unused */ +/* 10bit raw packed, 32 bytes for every 25 pixels, last LSB 6 bits unused */ #define V4L2_PIX_FMT_IPU3_SBGGR10 v4l2_fourcc('i', 'p', '3', 'b') /* IPU3 packed 10-bit BGGR bayer */ #define V4L2_PIX_FMT_IPU3_SGBRG10 v4l2_fourcc('i', 'p', '3', 'g') /* IPU3 packed 10-bit GBRG bayer */ #define V4L2_PIX_FMT_IPU3_SGRBG10 v4l2_fourcc('i', 'p', '3', 'G') /* IPU3 packed 10-bit GRBG bayer */ From patchwork Thu May 5 23:03:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12840300 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 9BE28C433F5 for ; Thu, 5 May 2022 23:04:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386544AbiEEXH5 (ORCPT ); Thu, 5 May 2022 19:07:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386537AbiEEXH4 (ORCPT ); Thu, 5 May 2022 19:07:56 -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 F297E5EDC4 for ; Thu, 5 May 2022 16:04:14 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id e2so7867106wrh.7 for ; Thu, 05 May 2022 16:04:14 -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=1mOFZVAVxl7g10hAI7IzlpJUn6DPse6wOzh3kxxLU+Y=; b=nHSvwpz4zVnOxsKgT1TyjyCdXNT9+2+S6zof06xnlNeweAwBwN7x5cvLMcdAF3Q5rh AMWGpb0Gp2c/JAKO9GQQLNPrFdz54uE/g2GMB25hxBYx9IiXs4IQo4VmUqPI0xrXuOy/ anxHE0qNXHF70Bk4R7C6Zxg9+Owo9unaqGUaNgDK8IUWfvtGgToydwOM+Weivc/P9EOc XwUAjSBGtVZ7ggL1kpJPMSWk7dBHhh6Z5XHfOnRoyw/oONuQCZTzUS5kKuwyuC1OkZP5 NmtlXmTAVQ9bGHkUg6EVMrY8pTXqqoewP7tPamZ/iDund70DPTaqJL6wHPTjCX1t2quz 1F/A== 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=1mOFZVAVxl7g10hAI7IzlpJUn6DPse6wOzh3kxxLU+Y=; b=HtIylMgXernGXWxpi6rXyo4sn+Z9PZUVFrPXPc2CsEtqLwsLwG6tx5504rLOsBnBd4 PY8gsnULJt7Z8q8xNiu03ifL+zLVdZjQm6GaFg1Y0ZMvLluLPDW1O4eWjuxi/lfD06Yl 8/zgp34KVlsnXzlrNydcc9bKcwQQawEN2ym7IOasG7N+NQ95hOieBAbPdw0h1R9/pyg+ Y21vo9pCH+i7LGgRM2ONOCwI6d6sJKBjhepH40V3K5iqwRnNCdA0U13qOxdk3dOJoJRt I5FmPz+DOE6dPvXN7Mq3YP8o3jqdPr7wZMUC/7zFBgR2h3pL+nIZ9m6p3iXtVfBHWdUM P+fQ== X-Gm-Message-State: AOAM532DTTZKrLuyRYskI9vrR1h9HEoD9S6RGDiwHeuHGEdHwcZgJ+9d ZxuXQXsrEFhf8FQHBBtWUajGtrjLOWI= X-Google-Smtp-Source: ABdhPJzGHWGG1VQVCFU1ONbiNferA32w658N9GWR74DlDzAaGibmi8kXFRWHHHnX2axzPCOVeO9y7g== X-Received: by 2002:a5d:564c:0:b0:20a:d53c:70e3 with SMTP id j12-20020a5d564c000000b0020ad53c70e3mr315177wrw.0.1651791853629; Thu, 05 May 2022 16:04:13 -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 o20-20020a05600c339400b003942a244f33sm6782130wmp.12.2022.05.05.16.04.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 16:04:13 -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 v4 02/15] media: ipu3-cio2: Add support for V4L2_PIX_FMT_IPU3_Y10 Date: Fri, 6 May 2022 00:03:49 +0100 Message-Id: <20220505230402.449643-3-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505230402.449643-1-djrscally@gmail.com> References: <20220505230402.449643-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 v4: - None 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 Thu May 5 23:03:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12840299 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 18228C433FE for ; Thu, 5 May 2022 23:04:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386541AbiEEXH5 (ORCPT ); Thu, 5 May 2022 19:07:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44680 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386535AbiEEXH4 (ORCPT ); Thu, 5 May 2022 19:07:56 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13E765EDCA for ; Thu, 5 May 2022 16:04:15 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id i133-20020a1c3b8b000000b003946c466c17so586501wma.4 for ; Thu, 05 May 2022 16:04:15 -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=LwE0qGkmiPjneH2DbDMhC+unsy48LGyAbwLZRv++e6Y=; b=MeG2ksdLjesAZbVvWNmBOa36TqdtnEzyvGERMp4MO1yovXw/yh8lu66Hr6/P3BYjYW Pf+MUYbVS5JJrphpox5UDvBL/JQprhh/UJpmfGv9IAuTx3rvlPM6L++IZGQEATftOLnR VmWLs8W/WYIgAbFd91XAgkThB+NaiQB0ICfdAEMMZW6WOprF/Ra+SZ7pPbVN3kF5KWKJ mLQOj8SJ3aUcIeXMSXjziILTRR352zERrtAiPAvWMgNpK/Ke0Jtv2IOak7xyKEOlH9AB OuBfHY9v8Wl3Z5O40vLU/lEDSevh5wUw/z0d8MVIqVSCtJmqXY3KktyVFWUnzfFJRpiR KBww== 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=LwE0qGkmiPjneH2DbDMhC+unsy48LGyAbwLZRv++e6Y=; b=NMRkutExI+/z9cxKQc4NXX764rngtvUSiHH3I5p6bBC/SEBbhkQFWl8K7ZJwXKAnFn q1Eldgn812/7GQiTomGfBS0MVXG7JGoWArNOzSE0IFGEmtXIhJYMGkc9YMe1wGutq6oI hE2y9qc1Rx0/aAWJv2IaH3qCOCNjL5ujfI+FFzwNcRgo5tNL/YwqFx9hURw9hDM9cu27 fzNsDfjNbZ9Qxo1I7ulz1nBPPmnryPiwL/q9PdvHynffzglzGKuMeF+eNUfXS+aUDnD4 IYtSiqVHnZJ8qPJRN8ZhkMbTIRF7tAJXKWd8SpksVpSS0+QasnICHtaeSIJOUzCAM1uy eNtw== X-Gm-Message-State: AOAM533pGa0IZh9AEfHUvuYDoNouhHOfseKwRN0T+POihVw4UjyOp+Dl 7GkKU5xv/DsRf4H9hSK+AJBW0mdLeXQ= X-Google-Smtp-Source: ABdhPJwIK47X7LX0NsaMeINp9AfCJ2OpUaXoXcYru8/FayFhLWc4L6W3pUh6tzRBcnZhf/EWQNwjjw== X-Received: by 2002:a1c:19c3:0:b0:392:9cef:e32b with SMTP id 186-20020a1c19c3000000b003929cefe32bmr477687wmz.116.1651791854729; Thu, 05 May 2022 16:04:14 -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 o20-20020a05600c339400b003942a244f33sm6782130wmp.12.2022.05.05.16.04.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 16:04:14 -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 v4 03/15] media: i2c: Add acpi support to ov7251 Date: Fri, 6 May 2022 00:03:50 +0100 Message-Id: <20220505230402.449643-4-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505230402.449643-1-djrscally@gmail.com> References: <20220505230402.449643-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 v4: - None 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 Thu May 5 23:03:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12840301 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 A03B4C433EF for ; Thu, 5 May 2022 23:04:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386546AbiEEXH7 (ORCPT ); Thu, 5 May 2022 19:07:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386537AbiEEXH6 (ORCPT ); Thu, 5 May 2022 19:07:58 -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 04A255EDC5 for ; Thu, 5 May 2022 16:04:17 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id i5so7855977wrc.13 for ; Thu, 05 May 2022 16:04:16 -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=p991ONNHq387h8+TGxMod6UhA12KlgGHC0aWWdyIYEk=; b=ZIeT9NqqYiqSTvqUSSd4/FrqoPifRIBzrqpmeOPsN5bLMwtKlQCpMxPOhwn04lnoCM qHTZ7FKpCJ2khISrW0CBP4LcWRa8bEWhFRQ1cy74LUDSEEZuW+oz5bulPztQHxEwL5+8 N8gSVxWm6u/Gq8PIdRHbqtXG1/+7FVw1Tp3ubzicHCI8hodCkGF+vpia1ffCwcdEIL/o QO2cEtAhnSaZCZHM/G9dycWxjUESRX2VJFYqhAuz65MNyPks/ar5T+puM3Uk9B3uiP3g nEsv0Y0h9FmaOjP+bpfuDDDyyqeAOXAaH6AYYFw+x4Cw26nDZrMI20qITNFoOr/aHvRZ qkzA== 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=p991ONNHq387h8+TGxMod6UhA12KlgGHC0aWWdyIYEk=; b=lRUdwoqT74LBcaXUTn0HLRf1o5sOaVYMyFjJa25MvWitm0pl+1Hcfw40D2g6h6Mmw3 jdndZw7nAABc71+9QP+XKsYFODxMev8Zgnn1UD9wAve/Qq/GvDF+o3B/zEUn1I/74vOJ eAWIFjDOa4+dwVUfGyTmXjZCzS+/ghLayn65RbymiYy/BXp5pa5/FA6HW8QZUXEG+Nq6 THBTKBLvnzUjfMLp1/MNzPsMjDpSqpxZ0fTfskHk47f6LOaEjPN7M2b+x4AbA4s+lH7k f+Yj+ozni3y4q3FA/jNts32Vty3C0yYldckwAFRJC4SlX1Y+doEpRCg9KoWWPJ1qnqN4 dKEA== X-Gm-Message-State: AOAM530EsxJ3hmWKoqFGilZHluPWSim4SzZgHRqBscxVywcZgLmr7bTu ZrIQq+BgbvP3HYuQiau7J5kUsSLNXE0= X-Google-Smtp-Source: ABdhPJwdVDLsubdklz1U2XwW5OrrruoOs5k81m0wwbMZZBwnSyGRttuOoDGc9hQmC4okIgUjBhFvaA== X-Received: by 2002:a5d:4307:0:b0:207:9f82:e238 with SMTP id h7-20020a5d4307000000b002079f82e238mr312859wrq.430.1651791855568; Thu, 05 May 2022 16:04:15 -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 o20-20020a05600c339400b003942a244f33sm6782130wmp.12.2022.05.05.16.04.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 16:04:15 -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 v4 04/15] media: i2c: Provide ov7251_check_hwcfg() Date: Fri, 6 May 2022 00:03:51 +0100 Message-Id: <20220505230402.449643-5-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505230402.449643-1-djrscally@gmail.com> References: <20220505230402.449643-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Move the endpoint checking from .probe() to a dedicated function, and additionally check that the firmware provided link frequencies are a match for those supported by the driver. Store the index to the matching link frequency so it can be easily identified later. Signed-off-by: Daniel Scally --- Changes in v4: - Used dev_err_probe() to set ret (Andy) Changes in v3: - Replaced freq_found variable (Andy) Changes in v2: - Switched to use unsigned int (Sakari) - Dropped the checks for bus_type and number of data lanes (Sakari) - Fixed the double-loop break (Dave) - Stored the index to the configured link frequency so it can be used later on. drivers/media/i2c/ov7251.c | 75 +++++++++++++++++++++++++++++--------- 1 file changed, 57 insertions(+), 18 deletions(-) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index d6fe574cb9e0..177b99eef3a5 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -60,6 +60,11 @@ struct ov7251_mode_info { struct v4l2_fract timeperframe; }; +enum supported_link_freqs { + OV7251_LINK_FREQ_240_MHZ, + OV7251_NUM_SUPPORTED_LINK_FREQS +}; + struct ov7251 { struct i2c_client *i2c_client; struct device *dev; @@ -75,6 +80,7 @@ struct ov7251 { struct regulator *core_regulator; struct regulator *analog_regulator; + enum supported_link_freqs link_freq_idx; const struct ov7251_mode_info *current_mode; struct v4l2_ctrl_handler ctrls; @@ -1255,10 +1261,58 @@ static const struct v4l2_subdev_ops ov7251_subdev_ops = { .pad = &ov7251_subdev_pad_ops, }; +static int ov7251_check_hwcfg(struct ov7251 *ov7251) +{ + struct fwnode_handle *fwnode = dev_fwnode(ov7251->dev); + struct v4l2_fwnode_endpoint bus_cfg = { + .bus_type = V4L2_MBUS_CSI2_DPHY, + }; + struct fwnode_handle *endpoint; + unsigned int i, j; + int ret; + + endpoint = fwnode_graph_get_next_endpoint(fwnode, NULL); + if (!endpoint) + return -EPROBE_DEFER; /* could be provided by cio2-bridge */ + + ret = v4l2_fwnode_endpoint_alloc_parse(endpoint, &bus_cfg); + fwnode_handle_put(endpoint); + if (ret) + return dev_err_probe(ov7251->dev, ret, + "parsing endpoint node failed\n"); + + if (!bus_cfg.nr_of_link_frequencies) { + ret = dev_err_probe(ov7251->dev, -EINVAL, + "no link frequencies defined\n"); + goto out_free_bus_cfg; + } + + for (i = 0; i < bus_cfg.nr_of_link_frequencies; i++) { + for (j = 0; j < ARRAY_SIZE(link_freq); j++) + if (bus_cfg.link_frequencies[i] == link_freq[j]) + break; + + if (j < ARRAY_SIZE(link_freq)) + break; + } + + if (i == bus_cfg.nr_of_link_frequencies) { + ret = dev_err_probe(ov7251->dev, -EINVAL, + "no supported link freq found\n"); + goto out_free_bus_cfg; + } + + ov7251->link_freq_idx = i; + +out_free_bus_cfg: + v4l2_fwnode_endpoint_free(&bus_cfg); + + return ret; +} + static int ov7251_probe(struct i2c_client *client) { struct device *dev = &client->dev; - struct fwnode_handle *endpoint; struct ov7251 *ov7251; u8 chip_id_high, chip_id_low, chip_rev; int ret; @@ -1270,24 +1324,9 @@ static int ov7251_probe(struct i2c_client *client) ov7251->i2c_client = client; ov7251->dev = dev; - endpoint = fwnode_graph_get_next_endpoint(dev_fwnode(dev), NULL); - if (!endpoint) { - dev_err(dev, "endpoint node not found\n"); - return -EINVAL; - } - - ret = v4l2_fwnode_endpoint_parse(endpoint, &ov7251->ep); - fwnode_handle_put(endpoint); - if (ret < 0) { - dev_err(dev, "parsing endpoint node failed\n"); + ret = ov7251_check_hwcfg(ov7251); + if (ret) return ret; - } - - if (ov7251->ep.bus_type != V4L2_MBUS_CSI2_DPHY) { - dev_err(dev, "invalid bus type (%u), must be CSI2 (%u)\n", - ov7251->ep.bus_type, V4L2_MBUS_CSI2_DPHY); - return -EINVAL; - } /* get system clock (xclk) */ ov7251->xclk = devm_clk_get(dev, "xclk"); From patchwork Thu May 5 23:03:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12840302 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 E6545C433F5 for ; Thu, 5 May 2022 23:04:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386548AbiEEXH7 (ORCPT ); Thu, 5 May 2022 19:07:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386547AbiEEXH7 (ORCPT ); Thu, 5 May 2022 19:07:59 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F12B95EDCB for ; Thu, 5 May 2022 16:04:17 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id d5so7866507wrb.6 for ; Thu, 05 May 2022 16:04:17 -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=+FA1HuzrAkUutuEywbGVeEDJxd7dNUrp3TJdDuNCkCs=; b=N35mVl5yJGmgfFJtBagPmJpHhgEsakttcGl1N+IXYoGXdNbAr6T9YVzRicSTwFO1Jp EaVI3X611PtHSDJKZmNIhZk+azTxy+A0vgVHiv+cclu+xuC91lGMEOkFbDSDxDRSNaPs /6v5pOahoHbgjb4n5a9wSFdEo0rFogDKTN79ddsx1aRQQeHEcZ4enJakH575nmMoGs8j mgK0Sz7+eb9aLqfBTb/MusHu/zDN0lG7Tz/+ElZH7Kjhl2Vngakgzd41lgFwfJViIKX2 wuKWyCkotOn+4sC8tbqZs9jM/+fpB+aR1928nTdFtXDm+CVK2io+jBhCCMTHnLAUxgwN UYpw== 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=+FA1HuzrAkUutuEywbGVeEDJxd7dNUrp3TJdDuNCkCs=; b=DPPoTH4pKkaeNEzHIgLNdG4l6ptlfmbjjRgnCWmTRgfKUIzRiRMavk2s0nMRm0AaeV 2W95N44QW//FnrB0ETpzoJuoktiUvo53PMKZOtpQtLTE6aGmgLu/eAXCASY2H8s4Avuk GOEeLZfVfUviEBsUrecQhfRQBVGR46ovvf0sj3K38Ey6o4V8PyhDaek2y8eoYrbLTiZ8 EtLFoHeYxHdBjsiEJ0kFZq+YKW2FWuzwXOAG+vSY2BUsBKRUBqyPZAl485f9HUn7TLps S+7EC/sIXsuL82ia4VCTikbh1geF9lloG1czMpQ1lml/M2/NLkRTt1vk0HakNTXolgMt jqBA== X-Gm-Message-State: AOAM530SHP3oTBm31aM5dxG0Y2ESkKvjPHKHsVsg55GHqBgrh0TRngQi +E1uJGoE5IA13Nf6Df483f8DJEv4IG0= X-Google-Smtp-Source: ABdhPJwOE9TsG5VBT6LgHARIuD8Km43iKWc6DIN/DvRx1bELcdo+yjO9XGN9M1UbVogAWhwu/4T/jg== X-Received: by 2002:a05:6000:156e:b0:20c:4fd5:f780 with SMTP id 14-20020a056000156e00b0020c4fd5f780mr266896wrz.561.1651791856607; Thu, 05 May 2022 16:04:16 -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 o20-20020a05600c339400b003942a244f33sm6782130wmp.12.2022.05.05.16.04.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 16:04:16 -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 v4 05/15] media: i2c: Remove per-mode frequencies from ov7251 Date: Fri, 6 May 2022 00:03:52 +0100 Message-Id: <20220505230402.449643-6-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505230402.449643-1-djrscally@gmail.com> References: <20220505230402.449643-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 v4: - None 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 177b99eef3a5..4f51e6258988 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); @@ -1315,6 +1293,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); @@ -1396,17 +1375,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 Thu May 5 23:03:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12840303 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 7B469C433F5 for ; Thu, 5 May 2022 23:04:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386557AbiEEXIC (ORCPT ); Thu, 5 May 2022 19:08:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386547AbiEEXIA (ORCPT ); Thu, 5 May 2022 19:08:00 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF7645F8D6 for ; Thu, 5 May 2022 16:04:18 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id u3so7889480wrg.3 for ; Thu, 05 May 2022 16:04:18 -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=spWU9HxjH8HokQ7ZKcm+0VT1n70/8aIRKz2S2zHk1rk=; b=dj9AL+9eVD2TyUJ9vRZANbZMOmr2v39kP0kqgQT3xczH2Mrn+IFPUXPrDksK+ejJA5 mvDvKRi50GaxhA/Eh0Iki0RGrRWKSHELuTbnZOCs+uRLk7jj4vadDBIrYTevm6t0XZ1C s+iykUGcDIcMhvrsTIw1zXOTxyPoiX9ulJO+rXrkhVqOCowPc5e0O9yDdVrnbLuEITL1 iGk3GpIPz3EqSzfsWVh/TtWPWpMacqMaWHhvGA/O6pZk3mxXeBiGUncUXzChg4MmkZ8t P2kOdEbI7g6IdQZYOVLcoW3q3KoliyoNTy9Um4ZINbcXlns22GzQUo199GKgx0Amqnvp lwCA== 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=spWU9HxjH8HokQ7ZKcm+0VT1n70/8aIRKz2S2zHk1rk=; b=yGFNZLqNFNHcyS6UCHV7YkJHVklP+xnT5Phke4XSBZZU02BXzEMprx7X5JLj4m7dew cj2tdSvnxufHWYwEJmT9jvXI8flVyVo37O/kgZA/2h3Wh1nk2vIg/DIdZOJbEcMKehmn TTKLvgHIXz0UWTJ6/GTJ/zVF9JswrusNqE7KW2+tdExj0O3XHrr6boRi98fxsL/ivr9d Ap1WkrlXx9c4UlC5ntk24ID+xfwLRUioV2SABsSTzG5s5YdVwToj6UvG+5SBNgGtrFm9 WKvnRDn9QcplKGUiA7Y19j8awnTssn18vUID8nuPMwh1BiZ4EupOllh8pygm5SP5uGT+ NPbw== X-Gm-Message-State: AOAM5302X0zssr//rQP20qwufyblEoDm2xW+LOFWkB/ceDbiS2jXjjTI uCruFjzUWl98xrF3x/bY6B+wtG3/1zs= X-Google-Smtp-Source: ABdhPJzbhwOtBXXYykb4SEIECJibHma1132x4nasd0KoFMPNu/NFKLPyXT80OuAiI2gEF+6xawYXDA== X-Received: by 2002:adf:d1cf:0:b0:20c:a6c4:98f5 with SMTP id b15-20020adfd1cf000000b0020ca6c498f5mr126713wrd.501.1651791857515; Thu, 05 May 2022 16:04:17 -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 o20-20020a05600c339400b003942a244f33sm6782130wmp.12.2022.05.05.16.04.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 16:04:17 -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 v4 06/15] media: i2c: Add ov7251_pll_configure() Date: Fri, 6 May 2022 00:03:53 +0100 Message-Id: <20220505230402.449643-7-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505230402.449643-1-djrscally@gmail.com> References: <20220505230402.449643-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Rather than having the pll settings hidden inside mode blobs, define them in structs and use a dedicated function to set them. This makes it simpler to extend the driver to support other frequencies for both the external clock and desired link frequency. Signed-off-by: Daniel Scally --- Changes in v4: - None Changes in v3: - Added commas to last items in arrays (Andy) Changes in v2: - Updated to support different link-frequencies in addition to different external clock frequencies. drivers/media/i2c/ov7251.c | 175 ++++++++++++++++++++++++++++++------- 1 file changed, 145 insertions(+), 30 deletions(-) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index 4f51e6258988..484c9f13fe97 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -42,6 +42,16 @@ #define OV7251_TIMING_FORMAT2_MIRROR BIT(2) #define OV7251_PRE_ISP_00 0x5e00 #define OV7251_PRE_ISP_00_TEST_PATTERN BIT(7) +#define OV7251_PLL1_PRE_DIV_REG 0x30b4 +#define OV7251_PLL1_MULT_REG 0x30b3 +#define OV7251_PLL1_DIVIDER_REG 0x30b1 +#define OV7251_PLL1_PIX_DIV_REG 0x30b0 +#define OV7251_PLL1_MIPI_DIV_REG 0x30b5 +#define OV7251_PLL2_PRE_DIV_REG 0x3098 +#define OV7251_PLL2_MULT_REG 0x3099 +#define OV7251_PLL2_DIVIDER_REG 0x309d +#define OV7251_PLL2_SYS_DIV_REG 0x309a +#define OV7251_PLL2_ADC_DIV_REG 0x309b struct reg_value { u16 reg; @@ -60,6 +70,36 @@ struct ov7251_mode_info { struct v4l2_fract timeperframe; }; +struct ov7251_pll1_cfg { + unsigned int pre_div; + unsigned int mult; + unsigned int div; + unsigned int pix_div; + unsigned int mipi_div; +}; + +struct ov7251_pll2_cfg { + unsigned int pre_div; + unsigned int mult; + unsigned int div; + unsigned int sys_div; + unsigned int adc_div; +}; + +/* + * Rubbish ordering, but only PLL1 needs to have a separate configuration per + * link frequency and the array member needs to be last. + */ +struct ov7251_pll_cfgs { + const struct ov7251_pll2_cfg *pll2; + const struct ov7251_pll1_cfg *pll1[]; +}; + +enum xclk_rate { + OV7251_24_MHZ, + OV7251_NUM_SUPPORTED_RATES +}; + enum supported_link_freqs { OV7251_LINK_FREQ_240_MHZ, OV7251_NUM_SUPPORTED_LINK_FREQS @@ -80,6 +120,7 @@ struct ov7251 { struct regulator *core_regulator; struct regulator *analog_regulator; + const struct ov7251_pll_cfgs *pll_cfgs; enum supported_link_freqs link_freq_idx; const struct ov7251_mode_info *current_mode; @@ -106,6 +147,33 @@ 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_24_mhz_240_mhz = { + .pre_div = 0x03, + .mult = 0x64, + .div = 0x01, + .pix_div = 0x0a, + .mipi_div = 0x05, +}; + +static const struct ov7251_pll2_cfg ov7251_pll2_cfg_24_mhz = { + .pre_div = 0x04, + .mult = 0x28, + .div = 0x00, + .sys_div = 0x05, + .adc_div = 0x04, +}; + +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, + }, +}; + +static const struct ov7251_pll_cfgs *ov7251_pll_cfgs[] = { + [OV7251_24_MHZ] = &ov7251_pll_cfgs_24_mhz, +}; + static const struct reg_value ov7251_global_init_setting[] = { { 0x0103, 0x01 }, { 0x303b, 0x02 }, @@ -124,16 +192,6 @@ static const struct reg_value ov7251_setting_vga_30fps[] = { { 0x301c, 0xf0 }, { 0x3023, 0x05 }, { 0x3037, 0xf0 }, - { 0x3098, 0x04 }, /* pll2 pre divider */ - { 0x3099, 0x28 }, /* pll2 multiplier */ - { 0x309a, 0x05 }, /* pll2 sys divider */ - { 0x309b, 0x04 }, /* pll2 adc divider */ - { 0x309d, 0x00 }, /* pll2 divider */ - { 0x30b0, 0x0a }, /* pll1 pix divider */ - { 0x30b1, 0x01 }, /* pll1 divider */ - { 0x30b3, 0x64 }, /* pll1 multiplier */ - { 0x30b4, 0x03 }, /* pll1 pre divider */ - { 0x30b5, 0x05 }, /* pll1 mipi divider */ { 0x3106, 0xda }, { 0x3503, 0x07 }, { 0x3509, 0x10 }, @@ -262,16 +320,6 @@ static const struct reg_value ov7251_setting_vga_60fps[] = { { 0x301c, 0x00 }, { 0x3023, 0x05 }, { 0x3037, 0xf0 }, - { 0x3098, 0x04 }, /* pll2 pre divider */ - { 0x3099, 0x28 }, /* pll2 multiplier */ - { 0x309a, 0x05 }, /* pll2 sys divider */ - { 0x309b, 0x04 }, /* pll2 adc divider */ - { 0x309d, 0x00 }, /* pll2 divider */ - { 0x30b0, 0x0a }, /* pll1 pix divider */ - { 0x30b1, 0x01 }, /* pll1 divider */ - { 0x30b3, 0x64 }, /* pll1 multiplier */ - { 0x30b4, 0x03 }, /* pll1 pre divider */ - { 0x30b5, 0x05 }, /* pll1 mipi divider */ { 0x3106, 0xda }, { 0x3503, 0x07 }, { 0x3509, 0x10 }, @@ -400,16 +448,6 @@ static const struct reg_value ov7251_setting_vga_90fps[] = { { 0x301c, 0x00 }, { 0x3023, 0x05 }, { 0x3037, 0xf0 }, - { 0x3098, 0x04 }, /* pll2 pre divider */ - { 0x3099, 0x28 }, /* pll2 multiplier */ - { 0x309a, 0x05 }, /* pll2 sys divider */ - { 0x309b, 0x04 }, /* pll2 adc divider */ - { 0x309d, 0x00 }, /* pll2 divider */ - { 0x30b0, 0x0a }, /* pll1 pix divider */ - { 0x30b1, 0x01 }, /* pll1 divider */ - { 0x30b3, 0x64 }, /* pll1 multiplier */ - { 0x30b4, 0x03 }, /* pll1 pre divider */ - { 0x30b5, 0x05 }, /* pll1 mipi divider */ { 0x3106, 0xda }, { 0x3503, 0x07 }, { 0x3509, 0x10 }, @@ -525,6 +563,10 @@ static const struct reg_value ov7251_setting_vga_90fps[] = { { 0x5001, 0x80 }, }; +static const unsigned long supported_xclk_rates[] = { + [OV7251_24_MHZ] = 24000000, +}; + static const s64 link_freq[] = { [OV7251_LINK_FREQ_240_MHZ] = 240000000, }; @@ -696,6 +738,63 @@ static int ov7251_read_reg(struct ov7251 *ov7251, u16 reg, u8 *val) return 0; } +static int ov7251_pll_configure(struct ov7251 *ov7251) +{ + const struct ov7251_pll_cfgs *configs; + int ret; + + configs = ov7251->pll_cfgs; + + ret = ov7251_write_reg(ov7251, OV7251_PLL1_PRE_DIV_REG, + configs->pll1[ov7251->link_freq_idx]->pre_div); + if (ret < 0) + return ret; + + ret = ov7251_write_reg(ov7251, OV7251_PLL1_MULT_REG, + configs->pll1[ov7251->link_freq_idx]->mult); + if (ret < 0) + return ret; + ret = ov7251_write_reg(ov7251, OV7251_PLL1_DIVIDER_REG, + configs->pll1[ov7251->link_freq_idx]->div); + if (ret < 0) + return ret; + + ret = ov7251_write_reg(ov7251, OV7251_PLL1_PIX_DIV_REG, + configs->pll1[ov7251->link_freq_idx]->pix_div); + if (ret < 0) + return ret; + + ret = ov7251_write_reg(ov7251, OV7251_PLL1_MIPI_DIV_REG, + configs->pll1[ov7251->link_freq_idx]->mipi_div); + if (ret < 0) + return ret; + + ret = ov7251_write_reg(ov7251, OV7251_PLL2_PRE_DIV_REG, + configs->pll2->pre_div); + if (ret < 0) + return ret; + + ret = ov7251_write_reg(ov7251, OV7251_PLL2_MULT_REG, + configs->pll2->mult); + if (ret < 0) + return ret; + + ret = ov7251_write_reg(ov7251, OV7251_PLL2_DIVIDER_REG, + configs->pll2->div); + if (ret < 0) + return ret; + + ret = ov7251_write_reg(ov7251, OV7251_PLL2_SYS_DIV_REG, + configs->pll2->sys_div); + if (ret < 0) + return ret; + + ret = ov7251_write_reg(ov7251, OV7251_PLL2_ADC_DIV_REG, + configs->pll2->adc_div); + + return ret; +} + static int ov7251_set_exposure(struct ov7251 *ov7251, s32 exposure) { u16 reg; @@ -1137,6 +1236,11 @@ static int ov7251_s_stream(struct v4l2_subdev *subdev, int enable) mutex_lock(&ov7251->lock); if (enable) { + ret = ov7251_pll_configure(ov7251); + if (ret) + return dev_err_probe(ov7251->dev, ret, + "error configuring PLLs\n"); + ret = ov7251_set_register_array(ov7251, ov7251->current_mode->data, ov7251->current_mode->data_size); @@ -1295,6 +1399,7 @@ static int ov7251_probe(struct i2c_client *client) u8 chip_id_high, chip_id_low, chip_rev; s64 pixel_rate; int ret; + int i; ov7251 = devm_kzalloc(dev, sizeof(struct ov7251), GFP_KERNEL); if (!ov7251) @@ -1333,6 +1438,16 @@ static int ov7251_probe(struct i2c_client *client) dev_err(dev, "could not set xclk frequency\n"); return ret; } + for (i = 0; i < ARRAY_SIZE(supported_xclk_rates); i++) + if (ov7251->xclk_freq == supported_xclk_rates[i]) + break; + + if (i == ARRAY_SIZE(supported_xclk_rates)) + return dev_err_probe(dev, -EINVAL, + "clock rate %u Hz is unsupported\n", + ov7251->xclk_freq); + + ov7251->pll_cfgs = ov7251_pll_cfgs[i]; ov7251->io_regulator = devm_regulator_get(dev, "vdddo"); if (IS_ERR(ov7251->io_regulator)) { From patchwork Thu May 5 23:03:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12840304 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 9B445C433F5 for ; Thu, 5 May 2022 23:04:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386558AbiEEXIF (ORCPT ); Thu, 5 May 2022 19:08:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386549AbiEEXIA (ORCPT ); Thu, 5 May 2022 19:08:00 -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 C3EA05EDCA for ; Thu, 5 May 2022 16:04:19 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id w4so7848240wrg.12 for ; Thu, 05 May 2022 16:04:19 -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=4QnDOy68DEZab1Oa8M/WsGaHMMp+EPQkeloWsfecpE8=; b=l8sCO4iXimDrRRGKYFS7Pm4oubZ7s/QjbW8EF2VAFY278a2zU5Td8BecitXPbmXTJs 7B2Rvb1cNRCROjYAwPLbTy1fHoRzirWN46E07dlRWCrKNyc3lu9ASWQ1mudI4lhrOasO WJxK1coVas2XyEHY1hIGvBa+W0Jus5W/zRbvmTg6jJ3fIxMClb0lfz17TUhYnT/EUWjz dHihXt+PpfWh6cKhbuQowfs+SixXmZt4hcOXRe2vpyMkgbXV8WXN8iaM0L446T3ZHZbA swUUQ1tEYGo1ALbXreKNEkLGXVY/O1xkeKWriat+MX8QENZmLED6B5QV23KOcQrVL3EV v6CA== 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=4QnDOy68DEZab1Oa8M/WsGaHMMp+EPQkeloWsfecpE8=; b=6e/gAmkkR6s8MvYtbpGY1e0w1+PVKNQJN/KlJr2yyJlcobMY0Xj/mN6/bbC9jACHaB 0WihdclqbdPZOZ76Ck+0kRIdeKckiFghidYCsZSnyOpNuIoNw3TfWGDn56BWpMoTR5HU nRdnIO+B3b7ZY4cnwfAyo6jsU6T5hnpH2NYNCFQ3JfUtAlCyVA+OQwwr+M0uiu0mCzUn S1y1+ouZB2U5dlwMudtoC4Gp4Me9YYPr69PH4dU6DBltb4Ap9yzSw6RwkphBeDo/TEII TDVR/cl6maqGMI9ak8I369y11aYpDvhyxX8PF38SVPFLzQ0Hsn4u6kV7ujsNblTGDiTN swZA== X-Gm-Message-State: AOAM533SzgVT8pPG7kgnaJnU3g/anfZVB1f/6kBcbfg8n8W2B090BhpV IrEIRF+rrxhadI4as4R3eq3oT6eRItQ= X-Google-Smtp-Source: ABdhPJxvZbpgJea7z/IaAfGrHQi9mSvvtceHKL/mKteRM8veBO9vu03VPR4ArU7gVyCZhwRjU3jQhQ== X-Received: by 2002:adf:dd92:0:b0:20a:d831:222f with SMTP id x18-20020adfdd92000000b0020ad831222fmr266068wrl.401.1651791858413; Thu, 05 May 2022 16:04:18 -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 o20-20020a05600c339400b003942a244f33sm6782130wmp.12.2022.05.05.16.04.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 16:04:18 -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 v4 07/15] media: i2c: Add support for new frequencies to ov7251 Date: Fri, 6 May 2022 00:03:54 +0100 Message-Id: <20220505230402.449643-8-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505230402.449643-1-djrscally@gmail.com> References: <20220505230402.449643-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 v4: - Fixed the unused variable 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 484c9f13fe97..98848b3f62a9 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_24_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[] = { @@ -1397,6 +1444,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; @@ -1413,31 +1461,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 Thu May 5 23:03:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12840305 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 75040C433EF for ; Thu, 5 May 2022 23:04:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386564AbiEEXII (ORCPT ); Thu, 5 May 2022 19:08:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44774 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386552AbiEEXIB (ORCPT ); Thu, 5 May 2022 19:08:01 -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 B849660064 for ; Thu, 5 May 2022 16:04:20 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id j15so7891662wrb.2 for ; Thu, 05 May 2022 16:04:20 -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=pFsplmqpkvecT13lJ82Se/URsi87L0nPXT/CCiqFbSI=; b=Gpf/jxQoLDuoYqNr5rFqYgWQTDdmjNb9xrJ0VwgtGm4qI5OZgCXPRBr1ymB8IFSb0m rouqytRq83Eyl4fMK1c7duL5sKVWMnT8XG2U+uilq468e3eoqMKnHWeNJhzdaj/vlliD FkvJAFGVFpYjDTD+N43DSXYPC/x89l35UKSxbEE/41q9IzE/9r2EsimTBzXO8Fh7t5I5 ybDaPIGMFORPTMMGYNXoIJft6E7LLLrDeoZ3m7YJ4wb/EHESM1/w91qpkPbyB775BxOh hIGdpY60ybod9YsyWXWMLCBJ8BbAgkiRqRdS9yEgFu96rR1lSSnZe28RG5nVHSPF7WyM 57qQ== 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=pFsplmqpkvecT13lJ82Se/URsi87L0nPXT/CCiqFbSI=; b=Enu8cJANIE78SZhRpFEpbZWrk6/Ogocj0M/oYGh92Zvfw740gTZSjnEv5/K4Hn76kx OvbP2WUl6I6rgEvMX26lLGC3qDmv7ynZzdw+fjo6IMNmy781Bd0b7Mb5WRAwTw9VIA3S uo3fS5a3CGjS/zybRxUXcOR/+jOPlX2/EIupc/3QcA1yOVyrtNFdBbW6bvk2D5EX6gJG 2E1SqXTX8ji65TDQua5VPY4e23HNRO6XtqAUEpYc3uLYvcJBZ2m3nzufNTH7jEAIZ6cm OuJCDbWPgu4Tkg8gqhgIRtpSMjtFYxOYIwxs1ArtWxxydstV8RALHYWjFsCHOPSQaJpZ BUaw== X-Gm-Message-State: AOAM533pxcXxfOgwLzTm2h0+dHqSwRx/khIoEhsb/UY8e6wBGem+6xUB XT0JPCToK7v3yBlSkpca2bKacb5v/Aw= X-Google-Smtp-Source: ABdhPJz+fL4tjj6UXP9DM5aYrbvAzC2aP8RKDZQFIOFa+KZt9vimwhGma/uPWE0IOWhyZQP0AHMCPQ== X-Received: by 2002:a5d:4686:0:b0:20a:e8dc:fd99 with SMTP id u6-20020a5d4686000000b0020ae8dcfd99mr295488wrq.478.1651791859356; Thu, 05 May 2022 16:04:19 -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 o20-20020a05600c339400b003942a244f33sm6782130wmp.12.2022.05.05.16.04.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 16:04:18 -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 v4 08/15] media: i2c: Add ov7251_detect_chip() Date: Fri, 6 May 2022 00:03:55 +0100 Message-Id: <20220505230402.449643-9-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505230402.449643-1-djrscally@gmail.com> References: <20220505230402.449643-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org .probe() is quite busy for this driver; make it cleaner by moving the chip verification to a dedicated function. Signed-off-by: Daniel Scally --- Changes in v4: - None Changes in v3: - None Changes in v2: - None drivers/media/i2c/ov7251.c | 62 +++++++++++++++++++++----------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index 98848b3f62a9..88875275b7b4 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -1439,11 +1439,43 @@ static int ov7251_check_hwcfg(struct ov7251 *ov7251) return ret; } +static int ov7251_detect_chip(struct ov7251 *ov7251) +{ + u8 chip_id_high, chip_id_low, chip_rev; + int ret; + + ret = ov7251_read_reg(ov7251, OV7251_CHIP_ID_HIGH, &chip_id_high); + if (ret < 0 || chip_id_high != OV7251_CHIP_ID_HIGH_BYTE) + return dev_err_probe(ov7251->dev, -ENODEV, + "could not read ID high\n"); + + ret = ov7251_read_reg(ov7251, OV7251_CHIP_ID_LOW, &chip_id_low); + if (ret < 0 || chip_id_low != OV7251_CHIP_ID_LOW_BYTE) + return dev_err_probe(ov7251->dev, -ENODEV, + "could not read ID low\n"); + + ret = ov7251_read_reg(ov7251, OV7251_SC_GP_IO_IN1, &chip_rev); + if (ret < 0) + return dev_err_probe(ov7251->dev, -ENODEV, + "could not read revision\n"); + chip_rev >>= 4; + + dev_info(ov7251->dev, + "OV7251 revision %x (%s) detected at address 0x%02x\n", + chip_rev, + chip_rev == 0x4 ? "1A / 1B" : + chip_rev == 0x5 ? "1C / 1D" : + chip_rev == 0x6 ? "1E" : + chip_rev == 0x7 ? "1F" : "unknown", + ov7251->i2c_client->addr); + + return 0; +} + 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; @@ -1586,34 +1618,10 @@ static int ov7251_probe(struct i2c_client *client) goto free_entity; } - ret = ov7251_read_reg(ov7251, OV7251_CHIP_ID_HIGH, &chip_id_high); - if (ret < 0 || chip_id_high != OV7251_CHIP_ID_HIGH_BYTE) { - dev_err(dev, "could not read ID high\n"); - ret = -ENODEV; - goto power_down; - } - ret = ov7251_read_reg(ov7251, OV7251_CHIP_ID_LOW, &chip_id_low); - if (ret < 0 || chip_id_low != OV7251_CHIP_ID_LOW_BYTE) { - dev_err(dev, "could not read ID low\n"); - ret = -ENODEV; - goto power_down; - } - - ret = ov7251_read_reg(ov7251, OV7251_SC_GP_IO_IN1, &chip_rev); - if (ret < 0) { - dev_err(dev, "could not read revision\n"); - ret = -ENODEV; + ret = ov7251_detect_chip(ov7251); + if (ret) goto power_down; - } - chip_rev >>= 4; - dev_info(dev, "OV7251 revision %x (%s) detected at address 0x%02x\n", - chip_rev, - chip_rev == 0x4 ? "1A / 1B" : - chip_rev == 0x5 ? "1C / 1D" : - chip_rev == 0x6 ? "1E" : - chip_rev == 0x7 ? "1F" : "unknown", - client->addr); ret = ov7251_read_reg(ov7251, OV7251_PRE_ISP_00, &ov7251->pre_isp_00); From patchwork Thu May 5 23:03:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12840311 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 64281C433EF for ; Thu, 5 May 2022 23:04:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386576AbiEEXIO (ORCPT ); Thu, 5 May 2022 19:08:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386559AbiEEXIF (ORCPT ); Thu, 5 May 2022 19:08:05 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8BA605EDCA for ; Thu, 5 May 2022 16:04:21 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id x18so7905999wrc.0 for ; Thu, 05 May 2022 16:04:21 -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=v2ntq5+o84ys/7XkopTay1Bh9yp01vCZFVX0Ak5FvkY=; b=BzeP0UuLloeAwqzyr7L9C5Fc9fFt8rgs5xtNfRKeiQfYxeV1R32dEiXZzeyKabP/Ks 72vWkNn2yjLrOnCamtNk/NY6IHsILqzg4MUXsYSmT2hFVczGl9Ln5tM3J8UERoVDoweu +ZHSMhf7npE+tHg2pYzEGpjSpW38x2ggHgBQJG9eseREF0uQLNaceFHQxRJjt3bLmjh/ c4URzPbnb/4JyL+sLE2WEh089rDQmx654oDxWE4qLpjhskFPDNrMbc2Y68QalE02qmGc LpSHIGtUAbwNxsctOXIi8+yspElOjg0FDKLGG6LNvKJD0IBaRtUBKF2vWn/I3hc8vDAR xOyQ== 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=v2ntq5+o84ys/7XkopTay1Bh9yp01vCZFVX0Ak5FvkY=; b=1YeKsAPF5J+rd26hQJpWL3QgxMKUeCoNrjSoNAhJIc2+Gpl97PtbRRWyOw6RpH6tTp Ie+Vs57POJpU8ZqnAGXnea7k6Gh69+OYQ2Nn3+cuVIY55h7Hqq606XpdRAeUrK84+su6 vU80BnELqx/AJuZ1V7B2L7/qjAaCKdWTdFjWOPUvmQzPBp+DGi4IKH7elmNIKk+sTi3N Lw8uTehHVAufigEll9bhFld9/JTIkBdvgEloD8QpcxnreVpuN0XaOHLGcvxTchOeOpRw /K+yi14TBxFH8jxGqYaVfzPCpcRApyjwFwEG+SdAiAQ0L2WXTsABy4RJKBs3Q8NppK7U W1cg== X-Gm-Message-State: AOAM5327b5VxlefEKmHgJj4JlbjKFuLYl+VqWIDdtGZOYjva3qcbZhJt DfXGAqBBIyBEkKyfj/SGlHvWIPrZQbs= X-Google-Smtp-Source: ABdhPJyGxvidO5nHU3A6dy2UY9oV2Qnml6MTD01I7IoJ3M998pblQLSNE/KYDrbRQ7veIMv/iUcYkw== X-Received: by 2002:adf:d22f:0:b0:20a:d8e7:41ae with SMTP id k15-20020adfd22f000000b0020ad8e741aemr284001wrh.708.1651791860178; Thu, 05 May 2022 16:04:20 -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 o20-20020a05600c339400b003942a244f33sm6782130wmp.12.2022.05.05.16.04.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 16:04:19 -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 v4 09/15] media: i2c: Add pm_runtime support to ov7251 Date: Fri, 6 May 2022 00:03:56 +0100 Message-Id: <20220505230402.449643-10-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505230402.449643-1-djrscally@gmail.com> References: <20220505230402.449643-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 v4: - None 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 88875275b7b4..1713c6e22ccd 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; } @@ -1612,23 +1635,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, @@ -1636,7 +1660,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, @@ -1644,10 +1668,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) { @@ -1659,8 +1685,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: @@ -1680,9 +1709,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 */ } @@ -1700,6 +1738,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 Thu May 5 23:03:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12840307 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 ECDDBC433FE for ; Thu, 5 May 2022 23:04:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386554AbiEEXIJ (ORCPT ); Thu, 5 May 2022 19:08:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44796 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386556AbiEEXIC (ORCPT ); Thu, 5 May 2022 19:08:02 -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 840B55EDC4 for ; Thu, 5 May 2022 16:04:21 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id i5so7855977wrc.13 for ; Thu, 05 May 2022 16:04:21 -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=P/x5gHPCt1r6N6iyOGsSDffQ/m5QgUd4Lz8AY2HmEWM=; b=fSbrniFUPHoVtOU92fkTc4wz0fERRvzOfCRjxVIECtpHHSo9z+TTRoeohMV81/sgPH XeYWzPjXNNRHp+sSu7a6hOFLFygFm6mQ6Es2ONcAf4+YDuEhcWT2c3ZCaxsU9TbWGMyo sEBW241n2i76+m9c1vqvH21tmlGiOi04E1pHGqjJmcS7nlVz6FThyREc4ISKgU7JXVXK QNUnK8pnfsO/E6l+hx5qjMa7GXlka3/3/nai4F/7jEqpBvA+cAXXoqJfAbngQUFBnXwh y2mthEFoqv0Wd0tAXKWnN+YWFbvIbpi/mH7PDo8YOojx46ayzW2L+8FIY/0x3+hNuKBi sJhQ== 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=P/x5gHPCt1r6N6iyOGsSDffQ/m5QgUd4Lz8AY2HmEWM=; b=pfOn93YKDfo72VzNdUpK3l11JQ1OB1PjKKR14o1unhnN3/Ois03EErZ84/Dtw6HVA3 D/FZbwG6N/iMr1kiG10cy0YGF36fa6BbVMXtbK/I9goHbMJ+SuNHrBIQ4T6r6MEUitgC 1mHSxZnIPlrCNMutqbA3s/dbdRYrl6T63I0UZSopXQnzC/3Z26fKnLhZax8CsbGSCPPy ZGqMcGrPOgWaeKHT+bGruASsfldVUJP7rYPgOdyg15Dy7ZpLzOZhC46ATH64P2YcDoLs tq4XB5g7UvrPLC9fYoaDwoAyC8wQifdiazT1QTvIHw3rPAReDhOYp90fLcHDjP/N0mqF DNOA== X-Gm-Message-State: AOAM530aFRJD2RQtuV9ZDwm/Lx0lu6ibkGRMfThf/FwiuBOlqgM/81XN hkhw2ureQmN1E3EYfMnJSTrlg+dL85Y= X-Google-Smtp-Source: ABdhPJz+yHdAO1TIdt+C60KhfZ0eYwrm8K0Txqxhs0AA1K/1KHZG/FyAsWvtD9YPm5TbVp4xZWNnfA== X-Received: by 2002:a05:6000:156a:b0:20c:64e3:948f with SMTP id 10-20020a056000156a00b0020c64e3948fmr300296wrz.436.1651791861139; Thu, 05 May 2022 16:04:21 -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 o20-20020a05600c339400b003942a244f33sm6782130wmp.12.2022.05.05.16.04.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 16:04:20 -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 v4 10/15] media: i2c: Remove .s_power() from ov7251 Date: Fri, 6 May 2022 00:03:57 +0100 Message-Id: <20220505230402.449643-11-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505230402.449643-1-djrscally@gmail.com> References: <20220505230402.449643-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org The .s_power() callback is deprecated, and now that we have pm_runtime functionality in the driver there's no further use for it. Delete the function. Signed-off-by: Daniel Scally --- Changes in v4: - None Changes in v3: - None Changes in v2: - Set the global init registers as part of ov7251_set_power_on() (Sakari) drivers/media/i2c/ov7251.c | 53 +++++++------------------------------- 1 file changed, 10 insertions(+), 43 deletions(-) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index 1713c6e22ccd..a1326d03bcdd 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -910,7 +910,16 @@ static int ov7251_set_power_on(struct device *dev) DIV_ROUND_UP(ov7251->xclk_freq, 1000)); usleep_range(wait_us, wait_us + 1000); - return 0; + ret = ov7251_set_register_array(ov7251, + ov7251_global_init_setting, + ARRAY_SIZE(ov7251_global_init_setting)); + if (ret < 0) { + dev_err(ov7251->dev, "error during global init\n"); + ov7251_regulators_disable(ov7251); + return ret; + } + + return ret; } static int ov7251_set_power_off(struct device *dev) @@ -926,43 +935,6 @@ static int ov7251_set_power_off(struct device *dev) return 0; } -static int ov7251_s_power(struct v4l2_subdev *sd, int on) -{ - struct ov7251 *ov7251 = to_ov7251(sd); - int ret = 0; - - mutex_lock(&ov7251->lock); - - /* If the power state is not modified - no work to do. */ - if (ov7251->power_on == !!on) - goto exit; - - if (on) { - ret = ov7251_set_power_on(ov7251->dev); - if (ret < 0) - goto exit; - - ret = ov7251_set_register_array(ov7251, - ov7251_global_init_setting, - ARRAY_SIZE(ov7251_global_init_setting)); - if (ret < 0) { - dev_err(ov7251->dev, "could not set init registers\n"); - ov7251_set_power_off(ov7251->dev); - goto exit; - } - - ov7251->power_on = true; - } else { - ov7251_set_power_off(ov7251->dev); - ov7251->power_on = false; - } - -exit: - mutex_unlock(&ov7251->lock); - - return ret; -} - static int ov7251_set_hflip(struct ov7251 *ov7251, s32 value) { u8 val = ov7251->timing_format2; @@ -1387,10 +1359,6 @@ static int ov7251_set_frame_interval(struct v4l2_subdev *subdev, return ret; } -static const struct v4l2_subdev_core_ops ov7251_core_ops = { - .s_power = ov7251_s_power, -}; - static const struct v4l2_subdev_video_ops ov7251_video_ops = { .s_stream = ov7251_s_stream, .g_frame_interval = ov7251_get_frame_interval, @@ -1408,7 +1376,6 @@ static const struct v4l2_subdev_pad_ops ov7251_subdev_pad_ops = { }; static const struct v4l2_subdev_ops ov7251_subdev_ops = { - .core = &ov7251_core_ops, .video = &ov7251_video_ops, .pad = &ov7251_subdev_pad_ops, }; From patchwork Thu May 5 23:03:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12840306 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 AEBB4C4332F for ; Thu, 5 May 2022 23:04:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386565AbiEEXIJ (ORCPT ); Thu, 5 May 2022 19:08:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386551AbiEEXIF (ORCPT ); Thu, 5 May 2022 19:08:05 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 616F05F8D6 for ; Thu, 5 May 2022 16:04:23 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id x18so7906062wrc.0 for ; Thu, 05 May 2022 16:04:23 -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=OJMUrxy1YxL+MfI3BMJM4GqCEZgOTfQRNKAvaXiVyIM=; b=XWhA7V4bCFG8NiwTH5s2sJHG41CzALB8x5VlzYiPxd0IOZJ3ZqMK/x60S0SRWb2oz6 OmaIfakE5QOxgXd3QNeIvHzAWcGe7jGyWcWTPTqA9ge3bAfX2EuXfG4uyK/J2v/j7j1X +Na0Xze8bzPoPOuSJfJZIS77A5MLK9vNlcTU7EvhmN5QGR97CYuB12kmieCXDHB+1JyN XOZaNtNURpE7XM/cGbrZAKHPyGWiUyyXBQH+S/bY+91nZoAUd2yWsCh2JrTIX+HKx8Zc ZcuAHEp90K5FIe6n5gdBcQVrdSdyF4RWEHmSGC/Jwxmxe2YCypmHJsLu+wVWb4v/nkay +ucA== 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=OJMUrxy1YxL+MfI3BMJM4GqCEZgOTfQRNKAvaXiVyIM=; b=gvBkRu775cYWj96SvnmDfpMHiYN/HvIRyEfUytMV+nkJJUFP/gjnKfhXgnwsQsiUd+ OP+2DLxjnZd8DwaAF9yNnaP+n+ftVeWXLcQySkZAtgPBPqipmnSbyIe75OFpwVIhFysd COj/ElJomXkT2vFkLU/QKWQ5zs/JyXFihmsd4PKdwX9ZCuPONeIDnkqR0/UN55DOTaa7 fZ6PX3RIq5WTGEVnBuMUOQZ+X16hH9SmK/LZmPn2EYbpTY1mGKs3dr+3VwHOus50H9Vf 70OMSbbKMJ0gmyOsncYWv/7sp8mv8IFnn427BNziQ8tH0NbBtuxpJnSPM4JGmoq9cIwv pghw== X-Gm-Message-State: AOAM533pWtvqwqXATlNEQj4osQJiGBV4W1PzfTF7T2DnMWmNCo+Rze/I Pw4nIjWFo4owjBHY8+jN/5Yx+1dAfHE= X-Google-Smtp-Source: ABdhPJzAccEtlK+1CsYt+bFClc0EpxsOGgZXbA5+aBvT2ntK9n9bTfesqnMZ03VKYgGAU7BZiHzgQw== X-Received: by 2002:a05:6000:1f02:b0:20c:9be6:3e04 with SMTP id bv2-20020a0560001f0200b0020c9be63e04mr289590wrb.456.1651791862027; Thu, 05 May 2022 16:04:22 -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 o20-20020a05600c339400b003942a244f33sm6782130wmp.12.2022.05.05.16.04.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 16:04:21 -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 v4 11/15] media: ipu3-cio2: Add INT347E to cio2-bridge Date: Fri, 6 May 2022 00:03:58 +0100 Message-Id: <20220505230402.449643-12-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505230402.449643-1-djrscally@gmail.com> References: <20220505230402.449643-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 v4: - None 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 Thu May 5 23:03:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12840310 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 12340C433FE for ; Thu, 5 May 2022 23:04:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386568AbiEEXIN (ORCPT ); Thu, 5 May 2022 19:08:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386549AbiEEXIG (ORCPT ); Thu, 5 May 2022 19:08:06 -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 48F3B5EDD1 for ; Thu, 5 May 2022 16:04:24 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id q23so7884895wra.1 for ; Thu, 05 May 2022 16:04:24 -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=qwPAqsE4aOcMNMzGB8tPf83tyrfTv7ngTTp2HTofk4M=; b=qSlgtcnqM3sFqHC7qp6fblCllrBLz/shRA4Sc2JFcvERm0FPDbJSGpPVbsvwJI3lYU Mi5+8JFOBepgajDZ6qUXuDlPGsFbUJDu8K3dw7qJ3+9Tl+3ajxDWv4pcHT7uBvcg1SmG aJtuhrQJMbNt72LCJDHAeJ74hEkCztkBuo48c6DRbXR12XZWLiwFLokQgQ6Ev5v2qJeb HRo+Rgzx71l3OQyFtp19k/0k4/yz3+EbVp0TZca1cEGHwqOvd3ymcItW0q0oQfq2wB+p +oFd+u+S73754ScsiOrtzCS2VB6VDHu7frl6Z9HOuokyqaclqvMZxT/3FtqcYb4m/Fxj CfGA== 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=qwPAqsE4aOcMNMzGB8tPf83tyrfTv7ngTTp2HTofk4M=; b=T3Ay5BLj5uFfrgUKNoLqLxIWtjlgpRszv3/JDAqn3MQ8Y42yQ3wmGor8EuesOEy1S8 0AHTZIjjnO9kr9wlZmpiNuhng3rtI75Tyr1p5uWDY9QyZWMcefZ4P2NVs3PBYDe1Mu+M Mo9067B6vjrjaigKEsuhTbsJ9SvGOVIPGAOdFUEoxO8N/PT6uzgtu3agi8/uSnbpAMJg ABZHa8J35uirhf33K8LQXgSis/HCQ7VIttQLxnQS05nHP0YCklKr1FYkIS180IxGgj2g 1SGrepQZesVD+PHqdVqXKME8GzL66XBvLilaiKFFMWpbiJh4pSFDaFcLBa0FkkHnovfS 1yKQ== X-Gm-Message-State: AOAM53178D7SYS/0rqvIm2C2NM2Ein/pAtxCvkYHefxC5lDjiqBBipHO vaxlGpluGs/agFH64J4AD6gs7IuJtsc= X-Google-Smtp-Source: ABdhPJxNTuFoO5z8EivN9F++u+t6zc0G48aFcipSITSc2n01p3KRCWEwUW6t4QYE21LFfq3PxaPAiA== X-Received: by 2002:a5d:588e:0:b0:20c:7ec0:b804 with SMTP id n14-20020a5d588e000000b0020c7ec0b804mr294449wrf.128.1651791862858; Thu, 05 May 2022 16:04:22 -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 o20-20020a05600c339400b003942a244f33sm6782130wmp.12.2022.05.05.16.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 16:04:22 -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 v4 12/15] media: i2c: Extend .get_selection() for ov7251 Date: Fri, 6 May 2022 00:03:59 +0100 Message-Id: <20220505230402.449643-13-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505230402.449643-1-djrscally@gmail.com> References: <20220505230402.449643-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Extend the .get_selection() callback to support other values for sel->target, primarily to satisfy libcamera's requirements. Signed-off-by: Daniel Scally --- Changes in v4: - None Changes in v3: - New patch drivers/media/i2c/ov7251.c | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index a1326d03bcdd..54c883753207 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -54,6 +54,13 @@ #define OV7251_PLL2_SYS_DIV_REG 0x309a #define OV7251_PLL2_ADC_DIV_REG 0x309b +#define OV7251_NATIVE_WIDTH 656 +#define OV7251_NATIVE_HEIGHT 496 +#define OV7251_ACTIVE_START_LEFT 4 +#define OV7251_ACTIVE_START_TOP 4 +#define OV7251_ACTIVE_WIDTH 648 +#define OV7251_ACTIVE_HEIGHT 488 + struct reg_value { u16 reg; u8 val; @@ -1248,13 +1255,29 @@ static int ov7251_get_selection(struct v4l2_subdev *sd, { struct ov7251 *ov7251 = to_ov7251(sd); - if (sel->target != V4L2_SEL_TGT_CROP) - return -EINVAL; - + switch (sel->target) { + case V4L2_SEL_TGT_CROP_DEFAULT: + case V4L2_SEL_TGT_CROP: mutex_lock(&ov7251->lock); - sel->r = *__ov7251_get_pad_crop(ov7251, sd_state, sel->pad, - sel->which); - mutex_unlock(&ov7251->lock); + sel->r = *__ov7251_get_pad_crop(ov7251, sd_state, sel->pad, + sel->which); + mutex_unlock(&ov7251->lock); + break; + case V4L2_SEL_TGT_NATIVE_SIZE: + sel->r.top = 0; + sel->r.left = 0; + sel->r.width = OV7251_NATIVE_WIDTH; + sel->r.height = OV7251_NATIVE_HEIGHT; + break; + case V4L2_SEL_TGT_CROP_BOUNDS: + sel->r.top = OV7251_ACTIVE_START_TOP; + sel->r.left = OV7251_ACTIVE_START_LEFT; + sel->r.width = OV7251_ACTIVE_WIDTH; + sel->r.height = OV7251_ACTIVE_HEIGHT; + break; + default: + return -EINVAL; + } return 0; } From patchwork Thu May 5 23:04:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12840309 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 DEE8CC433EF for ; Thu, 5 May 2022 23:04:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386567AbiEEXIM (ORCPT ); Thu, 5 May 2022 19:08:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386560AbiEEXIG (ORCPT ); Thu, 5 May 2022 19:08:06 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 17DF860064 for ; Thu, 5 May 2022 16:04:25 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id 125-20020a1c1983000000b003941f354c62so3451526wmz.0 for ; Thu, 05 May 2022 16:04:25 -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=EIQSEG3+wGcsjDuomAoboBMgPUdN7Q2cDoJ9+phCwvA=; b=BSD0oQVLj1lqwXQ5ETdpZSOpIvWFeMreNECmj75npOEsZvg1rQeR/ar6895XKM2Ey6 IN9WNS4PkWfn8Ov+VVyjUFTlaVdqZzoRQn1JwNq9qH0xXK8n6Rzguc8hoer6I+GG4oeP 3Vkliieaxh6ImxN4WS78yEqr3pKsXP9WLKh7aML4u7xH+jQmQMA/6djLebxrD/kCsWhL h8OBuFHPDKIpIXUeXlFtSyaT3Rex7M38dKPISdyOUBng/1P0vaYMgBb8nea+IIezZgFX GkG2OGtjx3qtUsE0gAtzAHl8IeZ97iigsohwoQWR381fqRO6yKof8Rk21GFLNcKkrNz0 BqnQ== 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=EIQSEG3+wGcsjDuomAoboBMgPUdN7Q2cDoJ9+phCwvA=; b=tAe5yPFMGXYvSRy+HNuR0N+vgSODnqweUbAeJJOy3b0zI4hYsgoy7geJcB00fJAE9T 5Ljt/zNYe5xM5KmTs4ZWDwC/oXbN3SKEAHcixSaKp1ml9oRRyDNOVaqxr+FEj7YqG0Do UEB7FohIE2MKbmu010vgm1id9cJkNmuxA+DJt4SkNY2+5EhWUbm1KmIvn7AHvcsqHmL4 /eSjh4SWWnqvvsbqf/LB79xA+bld789sllDuz6HQ+7HMIA8wsrcGpHA0EJIK7iCE1cXw 5nHeIqDxB5+lcVF5J1cVcKoTpCVNshiCOmeoK79TK4/dMD55hUflODLSrAv7yb8UjgBe KWmg== X-Gm-Message-State: AOAM532JPTRM0Y0w9DE5B1MqABnJ5mR5td0gtWZSpf8Qe2JWYLNYc6yK 8Fu2fdwA4pdOcRI74VhIKOu6gDWFfaw= X-Google-Smtp-Source: ABdhPJwCfhaUXumGDhZnx93eCKpucl1oRRR9YZku5YD5evt/KSbj13UyhKtc7SZMU3XpVfHNmoNdXg== X-Received: by 2002:a1c:e916:0:b0:37c:f44f:573 with SMTP id q22-20020a1ce916000000b0037cf44f0573mr7011354wmc.179.1651791863698; Thu, 05 May 2022 16:04:23 -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 o20-20020a05600c339400b003942a244f33sm6782130wmp.12.2022.05.05.16.04.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 16:04:23 -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 v4 13/15] media: i2c: add ov7251_init_ctrls() Date: Fri, 6 May 2022 00:04:00 +0100 Message-Id: <20220505230402.449643-14-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505230402.449643-1-djrscally@gmail.com> References: <20220505230402.449643-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org V4L2 controls initialisation takes up a sizeable portion of the driver's .probe() function. To keep things neat, move it to a dedicated function. Signed-off-by: Daniel Scally --- Changes in v4: - None Changes in v3: - New patch drivers/media/i2c/ov7251.c | 93 +++++++++++++++++++++----------------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index 54c883753207..e50514bbb345 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -1485,12 +1485,58 @@ static int ov7251_detect_chip(struct ov7251 *ov7251) return 0; } +static int ov7251_init_ctrls(struct ov7251 *ov7251) +{ + s64 pixel_rate; + + v4l2_ctrl_handler_init(&ov7251->ctrls, 7); + ov7251->ctrls.lock = &ov7251->lock; + + v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops, + V4L2_CID_HFLIP, 0, 1, 1, 0); + v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops, + V4L2_CID_VFLIP, 0, 1, 1, 0); + ov7251->exposure = v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops, + V4L2_CID_EXPOSURE, 1, 32, 1, 32); + ov7251->gain = v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops, + V4L2_CID_GAIN, 16, 1023, 1, 16); + v4l2_ctrl_new_std_menu_items(&ov7251->ctrls, &ov7251_ctrl_ops, + 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, + 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, + 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; + + if (ov7251->ctrls.error) { + v4l2_ctrl_handler_free(&ov7251->ctrls); + return ov7251->ctrls.error; + } + + return 0; +} + static int ov7251_probe(struct i2c_client *client) { struct device *dev = &client->dev; struct ov7251 *ov7251; unsigned int rate = 0, clk_rate = 0; - s64 pixel_rate; int ret; int i; @@ -1571,46 +1617,10 @@ static int ov7251_probe(struct i2c_client *client) mutex_init(&ov7251->lock); - v4l2_ctrl_handler_init(&ov7251->ctrls, 7); - ov7251->ctrls.lock = &ov7251->lock; - - v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops, - V4L2_CID_HFLIP, 0, 1, 1, 0); - v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops, - V4L2_CID_VFLIP, 0, 1, 1, 0); - ov7251->exposure = v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops, - V4L2_CID_EXPOSURE, 1, 32, 1, 32); - ov7251->gain = v4l2_ctrl_new_std(&ov7251->ctrls, &ov7251_ctrl_ops, - V4L2_CID_GAIN, 16, 1023, 1, 16); - v4l2_ctrl_new_std_menu_items(&ov7251->ctrls, &ov7251_ctrl_ops, - 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, - 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, - 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; - - if (ov7251->ctrls.error) { - dev_err(dev, "%s: control initialization error %d\n", - __func__, ov7251->ctrls.error); - ret = ov7251->ctrls.error; - goto free_ctrl; + ret = ov7251_init_ctrls(ov7251); + if (ret) { + dev_err_probe(dev, ret, "error during v4l2 ctrl init\n"); + goto destroy_mutex; } v4l2_i2c_subdev_init(&ov7251->sd, client, &ov7251_subdev_ops); @@ -1684,6 +1694,7 @@ static int ov7251_probe(struct i2c_client *client) media_entity_cleanup(&ov7251->sd.entity); free_ctrl: v4l2_ctrl_handler_free(&ov7251->ctrls); +destroy_mutex: mutex_destroy(&ov7251->lock); return ret; From patchwork Thu May 5 23:04:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12840308 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 035C9C433EF for ; Thu, 5 May 2022 23:04:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386566AbiEEXIK (ORCPT ); Thu, 5 May 2022 19:08:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44842 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386561AbiEEXIG (ORCPT ); Thu, 5 May 2022 19:08:06 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 055CB60070 for ; Thu, 5 May 2022 16:04:25 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id t6so7879670wra.4 for ; Thu, 05 May 2022 16:04:25 -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=1ODFWTPgqE1W4ZeXLlzmSDrqxPKsWiY7mz/SYbLjvDI=; b=otOvwaiP0QaJLgJ7jOvwhlFrjV38w9IC8bMt/LIKjdeXOctCrWH7GHpuKKkl+qE5c8 8zQi+PJ/MVwXirMubdj2EKzLu0ynWWZheOME6irrrOMVotd9rXomyhGdrWPexuJupNQl rI8kR7W0hLfmE/yz/jvn8veM+iFGTnkRXbSdcJbDX3fbHdlC3NWd9rs/NqgL4shXE/30 IxXawZaujOe1zYB7NTrD2mgbBZts/cGjWZFd+pDxm4mhG+sJkQwOYOoXJY5dgCaDfRk6 NMx/VZ4F60MTPhmljXz8U5NcUEonXz4b14En2OKGMLCyo+CNyHCeMtRs8oJPiyIokv9B U39A== 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=1ODFWTPgqE1W4ZeXLlzmSDrqxPKsWiY7mz/SYbLjvDI=; b=EP5Y7kz49/2hYJGWWGjkA9d8m1EqeCsdS7GRAonJqixBh0ErLwB9Wes9chM9N/6Q8U wpbngxDOBAhPNyIgIKcnqV65gj5VVeHX+BS9XVI5mlQ/3VSlNwuNnxlAf/5DOlV9uT2/ NQIF1EmsZG0uufaDo6DbOavBgj2kRyXBMGiUuHFkIoxmlBGe8hPSjQ0RuC5JsJuYyN9k 3lrrS2rFUy+XA4orAVYwGrkVwbLXvw0PfPd8i6QBlpbc/dvnqJngcm64XwG9WbnGiCLN FNMcLyU+o3tZhs+nmMyuZKh8ApP8V3SZ/P9KSnIbUzBrwY41twhKqbwpYwKqUyQbNDj0 byrg== X-Gm-Message-State: AOAM530Age4+ipxeKyai/wGlHYTztxgDHbOHqACLqKCupZuF6MtEmJbX d/XvM0XKVjIkSt1FXRnsEsO7bnR/qbA= X-Google-Smtp-Source: ABdhPJyrBg3CYhGteniO5KfTlLg6IaHhIJb0/JjFVC59n1XZfpM4zZJtViZonUzFTSdKnl0TG/9HlQ== X-Received: by 2002:a5d:6d8b:0:b0:20c:7022:7504 with SMTP id l11-20020a5d6d8b000000b0020c70227504mr288237wrs.183.1651791864573; Thu, 05 May 2022 16:04:24 -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 o20-20020a05600c339400b003942a244f33sm6782130wmp.12.2022.05.05.16.04.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 16:04:24 -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 v4 14/15] media: i2c: Add hblank control to ov7251 Date: Fri, 6 May 2022 00:04:01 +0100 Message-Id: <20220505230402.449643-15-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505230402.449643-1-djrscally@gmail.com> References: <20220505230402.449643-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 v4: - None 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 e50514bbb345..20591d8227c9 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; @@ -1488,6 +1491,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; @@ -1522,6 +1526,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) { @@ -1617,6 +1628,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 Thu May 5 23:04:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12840312 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 17C71C433F5 for ; Thu, 5 May 2022 23:04:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386577AbiEEXIQ (ORCPT ); Thu, 5 May 2022 19:08:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386553AbiEEXII (ORCPT ); Thu, 5 May 2022 19:08:08 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E20825EDC5 for ; Thu, 5 May 2022 16:04:26 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id e24so7862296wrc.9 for ; Thu, 05 May 2022 16:04:26 -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=10bGTJ2+BtTAQLbHFAjuYKXTSrjADGSIg0sJUSuRJsQ=; b=mxAbNuJxH7AAdMXMHp04WEE5azL9YZTm+xODh5DnZ7861boAO7DSrqeqvyrUcJ5nHK LwHdSgu+SdGYA154rvyShp66UdrKErBLCc0/8IxDjDVsA/lNeaT2zXEf5qH7zbzRXzVi 9oANt9bZDqV7h0YrnNB9yfAL5UlV/Vbd6WRxSRXF6/hzGDY/zGRcmmfF/EIjZQ+IkwOs McejOPftXVarfJPVEv7QqaGllq87ySJs0AZOrt3BrfMTE/yLsznuU6+puZbrEA12Ooss lAg2il5UtXn9Ams8R13F2TBXYYu3PnyG2HDt6wqKob7kx7SIiIa/ySF4rI320gwWj8rO PhQw== 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=10bGTJ2+BtTAQLbHFAjuYKXTSrjADGSIg0sJUSuRJsQ=; b=g6IX8VaQT85UjATDMTwLnWKwZ9Dqz3UAWizE+/bSqG3ObDaqBZdQhPrhEA/mC0R0S3 wEUu/P3M1xRdV7/hzAMm7j0JBBVp7R6GJax8H3T8B55PzBQ+FSBxJ8t0CGcuChgeXF3O rLL+Vrt2Zms1m5pNRGse8mAyeiz5M0ayH/GKzfQEplIVZ7mJTWiM235Ksmvg9d9k5X9q yyGlBj3x6X+RVHaNcr/p+rKxmeIGlN74fkUYMUzOH22GraSzeera4uyG9pmJ2ZOvoD6o EPmH9zdmyTqEJiDUuiv+NEwqr55dx7LiSKRjjPjFMjtE9yRgvqjqSp7KkOLlBP/CrCBv Tt2A== X-Gm-Message-State: AOAM532laVB1U4shy+FaucM6JtqPYiPotqWg3FulZ+SKlICP26dsRdmb VRwRt8awQA3MJBZDmwtguVWmnxtqT9Q= X-Google-Smtp-Source: ABdhPJyCchQvoD7jaDxxG+pbhhgwGvC32935fGnGK+L2Qrv1QfjRkFVV7/E+cacXP9BMH97/22X1FQ== X-Received: by 2002:a5d:6d8c:0:b0:20c:599a:4f7e with SMTP id l12-20020a5d6d8c000000b0020c599a4f7emr296936wrs.324.1651791865396; Thu, 05 May 2022 16:04:25 -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 o20-20020a05600c339400b003942a244f33sm6782130wmp.12.2022.05.05.16.04.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 May 2022 16:04:25 -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 v4 15/15] media: i2c: Add vblank control to ov7251 driver Date: Fri, 6 May 2022 00:04:02 +0100 Message-Id: <20220505230402.449643-16-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220505230402.449643-1-djrscally@gmail.com> References: <20220505230402.449643-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 v4: - Used vblank_def in ov7251_set_format() Suggestions not applied: - Didn't use __be16 / cpu_to_be16() - Andy I kinda thought the better way to do that would be as another patch changing the i2c read/write functions. I'll be working on this driver a bit more in the near future 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 20591d8227c9..4867dc86cd2e 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_def); + if (ret < 0) + goto exit; + ov7251->current_mode = new_mode; } @@ -1490,6 +1535,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; @@ -1533,6 +1579,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) {