From patchwork Tue Feb 15 23:07:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12747697 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 B6138C433F5 for ; Tue, 15 Feb 2022 23:07:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240786AbiBOXID (ORCPT ); Tue, 15 Feb 2022 18:08:03 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240552AbiBOXIC (ORCPT ); Tue, 15 Feb 2022 18:08:02 -0500 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 095C063A6 for ; Tue, 15 Feb 2022 15:07:51 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id w11so522700wra.4 for ; Tue, 15 Feb 2022 15:07:50 -0800 (PST) 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=SMY5mZRDZ5zSeVhczFX3GzI0HUddpNaRbL4SPzwPbzs=; b=P65b+cGa5QtW+XotpjFNzSYoINLupFXuF5daKH9OVJr29xdmItyabRxnPMAkQ1mK7/ YqCFkMxmkp/bTjXvwY6fJbkb1Utz6tYMrCl/KeDIbmVq4iS5NqG1DggQtHDZbHI5Kk9j GUwTUicAbgCPFqDXLgysHZNWmrJAu7u22iEeRcsOilBCs1fo26ymNPfa0gtF2TNiNvM2 MvasjZYR4/H1SrR49/WOBh6/A96lHLTYlkX6TMXQySRiC47XguV9fZsfoGD9iW7NcQAz dIboPE5QC2oPwRA/pTFxw9eRd3ZMkWWFkd6dTkTJvc1clHH3hUhh9nRZi2gOsKuHiQMg qlBw== 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=SMY5mZRDZ5zSeVhczFX3GzI0HUddpNaRbL4SPzwPbzs=; b=gRGq7N3ArBZDQjt2eV6G8minRml2B6szJGk/RkvFTLvXE68ZVU0ipvTQ6gNhAbF6MF nZBsBMtFOrRChksOq0m9t/t0dbL0t04oEe/Oc6iVhPEXp3cT/sbl7nM2OnJAZirvezhb CAg7FlCilb1IkwuFE6xY2qpJibfct7fynHmD0YmWwSfSxbw9HrcDTeAatuIW9IxPzNJ2 mhLTm4IpGd2WJQxgGStcVERWlFxJDFDbnDz4Mb0OyU6HwetaEljPV/hO0iavHcNRdsQx SAD00sedH4HYn6JAthG/GJQ1wycm3l/DAAhcf/ZXFeVentSo+cY6vbakoqGhZikNig25 VbbQ== X-Gm-Message-State: AOAM530DSC6PM4eEgFQ/s6hfzq3xvlAwJCrDAB6WLjGtVKZyGpZLaA+s 7KiPYYJ2mAbPiQ0VCKX3VeToVaa+qNY1bA== X-Google-Smtp-Source: ABdhPJxf4SxJE4nJsLRuPwdOiUCfv+xQRh8N2igutokd9L0OUiToKzn6frlSWKDsNItIwiPcnzA4yQ== X-Received: by 2002:a5d:6244:0:b0:1e7:686d:41e7 with SMTP id m4-20020a5d6244000000b001e7686d41e7mr103495wrv.491.1644966469669; Tue, 15 Feb 2022 15:07:49 -0800 (PST) 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 w18sm16956590wrl.62.2022.02.15.15.07.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 15:07:49 -0800 (PST) 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 01/10] media: uapi: Add IPU3 packed Y10 format Date: Tue, 15 Feb 2022 23:07:28 +0000 Message-Id: <20220215230737.1870630-2-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220215230737.1870630-1-djrscally@gmail.com> References: <20220215230737.1870630-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. Detail that format. Signed-off-by: Daniel Scally Reviewed-by: Nicolas Dufresne --- .../userspace-api/media/v4l/pixfmt-yuv-luma.rst | 14 +++++++++++++- drivers/media/v4l2-core/v4l2-ioctl.c | 1 + include/uapi/linux/videodev2.h | 1 + 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Documentation/userspace-api/media/v4l/pixfmt-yuv-luma.rst b/Documentation/userspace-api/media/v4l/pixfmt-yuv-luma.rst index 8ebd58c3588f..5465ce3bb533 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 ip3y 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..b378c7e37eac 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 */ From patchwork Tue Feb 15 23:07:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12747698 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 030A9C433F5 for ; Tue, 15 Feb 2022 23:07:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241437AbiBOXIF (ORCPT ); Tue, 15 Feb 2022 18:08:05 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240552AbiBOXIE (ORCPT ); Tue, 15 Feb 2022 18:08:04 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A2A8654F for ; Tue, 15 Feb 2022 15:07:53 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id d27so518706wrb.5 for ; Tue, 15 Feb 2022 15:07:53 -0800 (PST) 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=Ihc3y3MKZexrKZJkAwHz5nfKWryLTjQ76jG7vqQNZLc=; b=JUShL6Q5Qg4Hwyuli0ivgr+NJ5YVa4GNro4TPm1yK1kdqWf4dMUkEggeI12ZTdTyXf 4qcHU9286mka5IQdy9t/Sgssua9shGlIAy5taodoTsBrCBkU/U2VnGZUw+mHaDam6ElW a4HMTS1AKO4+WFfBWptiu1t9ZWwNwBXwVfnXie468Y/afXYrvWijvhSwTwqwJ1NZkENe 3vaKn2Ej2vDIJhi1w863vjj/jEoBpvM3HYLb5yuN/imtlttUxrtUcSfrxLMKX1kadLK8 vRbNflMVeIkjl6vkQ64GJrVQ0rS6BL3HX1nJcRC2c8IxyECIpDlLKCHwMnkX2bq947h2 993A== 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=Ihc3y3MKZexrKZJkAwHz5nfKWryLTjQ76jG7vqQNZLc=; b=wuEOAv3EZ3fZxoT3uwv8qimTaCr/VYw/5ZAPDaC6KNa47fSpdIAHH98K7c5DNHKGVp /6PgmWGrzMaNpbeXd76HEORmUEpD3+kEiUfoM4o2y2it372qmilhoCRxuU68+su1cqwE sL57iKkNQbYH/pIIOcm5RoI+LOyROCvDo3JgDw6LNQQO2GWMERc1WKi/vycPxItu66O8 L0b0Gkc+FnxGM+C0IQQGoEl6wqxTYdWXK0aqMaQBy4uWjZjwpVubUFqLAZH1vIgcUdTO /oPox71OEZstkc3OoLt33WMN8SK+gh9+OBdqLrKow0dbJXuZDpdExDNZUnEg+pEcONYT 96Ng== X-Gm-Message-State: AOAM533hjzrs2leBh85DOspHCG6Dg5RRg6RSwQl6Qd59rJld5dojEOAS cwMqLgkIqRw7tmlmTtQNWe2nGhFXTbSvCA== X-Google-Smtp-Source: ABdhPJwYSlwBoE7BfQdb3hbX90uwdBy4HgxYCYq7NtIgX8VaoJnoFtrvMdI0dwOHkTyB0y919YFVWA== X-Received: by 2002:a5d:40c8:0:b0:1e3:e76:129b with SMTP id b8-20020a5d40c8000000b001e30e76129bmr129927wrq.295.1644966471915; Tue, 15 Feb 2022 15:07:51 -0800 (PST) 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 w18sm16956590wrl.62.2022.02.15.15.07.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 15:07:51 -0800 (PST) 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 02/10] media: ipu3-cio2: Add support for V4L2_PIX_FMT_IPU3_Y10 Date: Tue, 15 Feb 2022 23:07:29 +0000 Message-Id: <20220215230737.1870630-3-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220215230737.1870630-1-djrscally@gmail.com> References: <20220215230737.1870630-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 --- drivers/media/pci/intel/ipu3/ipu3-cio2-main.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c index 0e9b0503b62a..ea2f9f70a64e 100644 --- a/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c +++ b/drivers/media/pci/intel/ipu3/ipu3-cio2-main.c @@ -65,7 +65,12 @@ 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 Tue Feb 15 23:07:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12747699 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 057F7C433EF for ; Tue, 15 Feb 2022 23:07:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242541AbiBOXIF (ORCPT ); Tue, 15 Feb 2022 18:08:05 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241021AbiBOXIF (ORCPT ); Tue, 15 Feb 2022 18:08:05 -0500 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 236C565E0 for ; Tue, 15 Feb 2022 15:07:54 -0800 (PST) Received: by mail-wm1-x334.google.com with SMTP id m126-20020a1ca384000000b0037bb8e379feso2497447wme.5 for ; Tue, 15 Feb 2022 15:07:54 -0800 (PST) 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=44CmJ4QtyEm7oBo0dApTxf2TlNPg1exYdSOKt0txzwU=; b=jkF7jdZpnPrMlilVWbpTbDKOI/ny/TP1HBWftbaIttn3qOEkWdzAHJLzPH/vcWrBVq i1PZBxVxM3Gwr/lG05MQf2pWVM5trbw4VA7J709Z/qAeHWEzsTpkDAEjT6g8R5BO5E/W CYxyQm0CUzi4sbQbQEKBZTh+U9inwSZ4o8mz0Q6bz2ZDF2qOqfThlNJNFnEiG0xjPFnV weC3PKz2gznTAdWHohAVvMBK1JlTF/UxG+zqctcCVcJNxRSk/RRRCfgOnLBKheB26gkt CjTXm0np4SXsOpjKvJNrIkU2Jj46UXfZUarrS0BH5OXmm5vipcMicDB7eyXJBbimx4li s+2Q== 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=44CmJ4QtyEm7oBo0dApTxf2TlNPg1exYdSOKt0txzwU=; b=3SLU7UI/WlC3s4lwEdu+pcvqZnuWhMF6HsUzXgHYKwFqptWgSYvLvdAb9q+JrPuKX1 OEwVUuE/0JdM9RCm0VgJbtjHpQN5hUhe9fJKHSKJJmLb72oBmM1e3rGcUwOax6pq5HWb Yq8bAq38pGrCF3w3Zq06lOlK+/7qR9V2/VAkLgcMhmQgJ2CZmwaG4UiR3pbxxodl7AVV XSH5/7epzRDjz+pTEpuC45ybFFHgU/KHNxwLvJKuV20WbKOLKwRaLDVefvMVuTjxvEoZ FTriffZZB/4jdugad5VzXpDt4H0fehvB01ADUB3FLToGiSe8F05ZlV81uI3ixN4r12ny wZDA== X-Gm-Message-State: AOAM532bTJZuquc2X8sC1Kr3prpNoJst02sEwl6C0uUr8sTz2g3Ou7K2 GF5QhgF/bmngBycBEwAcrmQQsVd/MRo4LA== X-Google-Smtp-Source: ABdhPJyfZwzzti6+BF0O0YZbr+2Y0iEhLXz3Ha1j8fU7VNnTXgnBrYDeWD44iL7284z7C/8DuiMcNw== X-Received: by 2002:a05:600c:1583:b0:346:3f83:6b8 with SMTP id r3-20020a05600c158300b003463f8306b8mr113497wmf.75.1644966472805; Tue, 15 Feb 2022 15:07:52 -0800 (PST) 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 w18sm16956590wrl.62.2022.02.15.15.07.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 15:07:52 -0800 (PST) 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 03/10] media: i2c: Add acpi support to ov7251 Date: Tue, 15 Feb 2022 23:07:30 +0000 Message-Id: <20220215230737.1870630-4-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220215230737.1870630-1-djrscally@gmail.com> References: <20220215230737.1870630-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 --- 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 Tue Feb 15 23:07:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12747700 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 23142C433F5 for ; Tue, 15 Feb 2022 23:07:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243039AbiBOXIH (ORCPT ); Tue, 15 Feb 2022 18:08:07 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242827AbiBOXIG (ORCPT ); Tue, 15 Feb 2022 18:08:06 -0500 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 3C31E7673 for ; Tue, 15 Feb 2022 15:07:55 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id k1so496572wrd.8 for ; Tue, 15 Feb 2022 15:07:55 -0800 (PST) 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=P434KImp5liNoIFLNLhSQYwe4ebiOCGmzd94xVyT5uY=; b=oeN8qhkqjrAya6/RJNBj3N2mCi01Xsj7V32wf77jzxkV58g9Zwb3mL2LV1HjN28ywh 3spiohF85EiOeqfOKUOM1jJQhLzGxPVqsbAIPATC4QFR8NDRoZnCsWrJygxmdZyJENJE Cikc+BRK2zpEkeyApPxHLGc05lSdi85vx1VQytgwICXJuEPCEOOKt76NdhLMhQOJHO0F YBGnnMWrpY5vrx5ORtjzuLWE1igsqRP3prbOIEF8CTmK02NcazVpFNg9gIs19eSjCKZL DwYuVEDCV5J1p4/TVNuQ/UzypywvmcvAfHG7iPTcYCX31OjfqKxR358aCHWeY08rEDnL /dDA== 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=P434KImp5liNoIFLNLhSQYwe4ebiOCGmzd94xVyT5uY=; b=qfeS8t35PFKkohCaO749OpEbYpNUw0hVo5q66TzJ8jibFMYLujRW8ICuT2qhZSZfhD Mv32t+CyQ1+c1TbE1KNr+9kBs2lJSCnYfnAuSz0I0hJdCAYhLJpCJ1S3BhiO7yNuKCIz geJzfrmhTcOfFgkcKERZx9rdMHNDGXtj3wNZIFb+nrbbDViRvqTLwGhvLMviWERThcAv +b/VkH0pVNKMA/zA2FN/wZBtBSJbU1gVB4QXzWXoDhubTqPpefTVse3OIGyAiCb3vktM BZ4FwOjgELo1Nab60tqqZSJhTOcRDdPDVHwzBgC3CyJ+cFh4N83HxsvcvcCBuwxdJ7Ld g4xQ== X-Gm-Message-State: AOAM530vg6g05672SSMHnWQDODKGVsRgaz71NsHugEgXCbI4OhkTj7qS 7BCJ6ssoIfQ0b9HS/3aRB41CtA3ZzdGexw== X-Google-Smtp-Source: ABdhPJyrD9RKCgOQx/G+DUKMVqSdPm4YDzFF/ntUo/SEL0qk9BBCw2zE0ogfyVx2XAO9WBv3M10s0A== X-Received: by 2002:adf:9f4a:0:b0:1e3:1c28:c298 with SMTP id f10-20020adf9f4a000000b001e31c28c298mr138686wrg.233.1644966473739; Tue, 15 Feb 2022 15:07:53 -0800 (PST) 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 w18sm16956590wrl.62.2022.02.15.15.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 15:07:53 -0800 (PST) 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 04/10] media: i2c: Provide ov7251_check_hwcfg() Date: Tue, 15 Feb 2022 23:07:31 +0000 Message-Id: <20220215230737.1870630-5-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220215230737.1870630-1-djrscally@gmail.com> References: <20220215230737.1870630-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. Finally, return -EPROBE_DEFER if the endpoint is not available, as it could be built by the ipu3-cio2 driver if that probes later. Signed-off-by: Daniel Scally --- drivers/media/i2c/ov7251.c | 84 ++++++++++++++++++++++++++++++-------- 1 file changed, 66 insertions(+), 18 deletions(-) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index d6fe574cb9e0..5c5f7a15a640 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -1255,10 +1255,73 @@ 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; + bool freq_found; + 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.bus_type != V4L2_MBUS_CSI2_DPHY) { + ret = -EINVAL; + dev_err(ov7251->dev, "invalid bus type (%u), must be (%u)\n", + bus_cfg.bus_type, V4L2_MBUS_CSI2_DPHY); + goto out_free_bus_cfg; + } + + if (bus_cfg.bus.mipi_csi2.num_data_lanes != 1) { + dev_err(ov7251->dev, "only a 1-lane CSI2 config is supported"); + ret = -EINVAL; + goto out_free_bus_cfg; + } + + if (!bus_cfg.nr_of_link_frequencies) { + dev_err(ov7251->dev, "no link frequencies defined\n"); + ret = -EINVAL; + goto out_free_bus_cfg; + } + + freq_found = false; + for (i = 0; i < bus_cfg.nr_of_link_frequencies; i++) { + if (freq_found) + break; + + for (j = 0; j < ARRAY_SIZE(link_freq); j++) + if (bus_cfg.link_frequencies[i] == link_freq[j]) { + freq_found = true; + break; + } + } + + if (i == bus_cfg.nr_of_link_frequencies) { + dev_err(ov7251->dev, "no supported link freq found\n"); + ret = -EINVAL; + goto out_free_bus_cfg; + } + +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 +1333,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 Tue Feb 15 23:07:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12747701 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 9B5D5C4332F for ; Tue, 15 Feb 2022 23:07:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243245AbiBOXII (ORCPT ); Tue, 15 Feb 2022 18:08:08 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241021AbiBOXIH (ORCPT ); Tue, 15 Feb 2022 18:08:07 -0500 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 1197365E0 for ; Tue, 15 Feb 2022 15:07:56 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id d27so518806wrb.5 for ; Tue, 15 Feb 2022 15:07:55 -0800 (PST) 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=7YNBUO8XgUFmBpbbAekPgNEEx1eoBe6SU8q8/QoD89s=; b=NAwNs5H/3Z5UlLXwzs59eJ1V/KqfMhnYE+x/l8H5D4vIMMPbsEa2YrapZ33hSRNRG5 Xql6SPV5m/mSbtQM/OIJWvOGxMqKsDuvp8Nmo/LZF9nkNlIT3TTv/rTy00R/Ra2WgTqN OUN4US97weIWPgwOlQWI9831Lt4dGxCzQt5ffX11th/rY4SzL/BryXtYGaVRC0n7C4uD 8aguPXF4va+J7BIkC9jcHvgx+i9Q1bYO4o9DFo6YVIEV9i57X6gAprOL3XveJv9m32nG 2bMv0zBM/ftMcgPSGS1t+84x6Xh14ZeKHXVfrNUpnMJXBwN1JDkJPRFFm3oKXr8C0+/p czLA== 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=7YNBUO8XgUFmBpbbAekPgNEEx1eoBe6SU8q8/QoD89s=; b=jRS5Qus1w5AAtRcGiw1pffuIb5RtAyR+iNMs/ZRcnLQZbep5iBuiKmbbiBoDnYHWMG rabQZEKPoK08JzdX8erH9kt8fG/L9B4RigudJPbv22WN2dMtfjJas19tW7PMXRFpNdnp MBaw51sYyoDUku00Wk57zTwIMVz4tXZRR2O7GSM9TcNl8UtMKk99zvti1hevTJPZvH67 Rf5mckhjqPLZB9Oythviz3gyxRoaOyJzBuaUPS1pLS330VhmqPWZycCm9G1VVORki33f ZU9E5o9tKZy5l8UTBv+3jaCTzowzxycljm+MSlPZCSTlv+sSnNAl/VJcByk+KKWElWqS +zsg== X-Gm-Message-State: AOAM5307tnKal99i1WihNj9eXJNFa9hngnrQEhZy4ZaVELz4AWNWZ1ay U8kUcOUqCqPUMAq2qs5GAdj8uIB6Tnt3cQ== X-Google-Smtp-Source: ABdhPJwXJaqq0Wgr6KOLL3xpxOqHaFW9lQqXbO+HuPGcQKB1g5hW+QTHsOC9OZPzkXg/lu2o8NYqyw== X-Received: by 2002:adf:dec8:0:b0:1e4:9a2f:e3d1 with SMTP id i8-20020adfdec8000000b001e49a2fe3d1mr170878wrn.374.1644966474679; Tue, 15 Feb 2022 15:07:54 -0800 (PST) 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 w18sm16956590wrl.62.2022.02.15.15.07.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 15:07:54 -0800 (PST) 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 05/10] media: i2c: Add ov7251_pll_configure() Date: Tue, 15 Feb 2022 23:07:32 +0000 Message-Id: <20220215230737.1870630-6-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220215230737.1870630-1-djrscally@gmail.com> References: <20220215230737.1870630-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 external clock frequencies. Signed-off-by: Daniel Scally --- drivers/media/i2c/ov7251.c | 165 ++++++++++++++++++++++++++++++------- 1 file changed, 135 insertions(+), 30 deletions(-) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index 5c5f7a15a640..809450b5a99a 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,27 @@ struct ov7251_mode_info { struct v4l2_fract timeperframe; }; +struct ov7251_pll1_config { + unsigned int pre_div; + unsigned int mult; + unsigned int div; + unsigned int pix_div; + unsigned int mipi_div; +}; + +struct ov7251_pll2_config { + unsigned int pre_div; + unsigned int mult; + unsigned int div; + unsigned int sys_div; + unsigned int adc_div; +}; + +struct ov7251_pll_configs { + const struct ov7251_pll1_config *pll1; + const struct ov7251_pll2_config *pll2; +}; + struct ov7251 { struct i2c_client *i2c_client; struct device *dev; @@ -71,6 +102,8 @@ struct ov7251 { struct clk *xclk; u32 xclk_freq; + const struct ov7251_pll_configs *pll_configs; + struct regulator *io_regulator; struct regulator *core_regulator; struct regulator *analog_regulator; @@ -100,6 +133,36 @@ static inline struct ov7251 *to_ov7251(struct v4l2_subdev *sd) return container_of(sd, struct ov7251, sd); } +enum xclk_rate { + OV7251_24_MHZ, + OV7251_NUM_SUPPORTED_RATES +}; + +static const struct ov7251_pll1_config ov7251_pll1_config_24_mhz = { + .pre_div = 0x03, + .mult = 0x64, + .div = 0x01, + .pix_div = 0x0a, + .mipi_div = 0x05 +}; + +static const struct ov7251_pll2_config ov7251_pll2_config_24_mhz = { + .pre_div = 0x04, + .mult = 0x28, + .div = 0x00, + .sys_div = 0x05, + .adc_div = 0x04 +}; + +static const struct ov7251_pll_configs ov7251_pll_configs_24_mhz = { + .pll1 = &ov7251_pll1_config_24_mhz, + .pll2 = &ov7251_pll2_config_24_mhz +}; + +static const struct ov7251_pll_configs *ov7251_pll_configs[] = { + [OV7251_24_MHZ] = &ov7251_pll_configs_24_mhz +}; + static const struct reg_value ov7251_global_init_setting[] = { { 0x0103, 0x01 }, { 0x303b, 0x02 }, @@ -118,16 +181,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 }, @@ -256,16 +309,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 }, @@ -394,16 +437,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 }, @@ -519,6 +552,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[] = { 240000000, }; @@ -692,6 +729,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_configs *configs; + int ret; + + configs = ov7251->pll_configs; + + ret = ov7251_write_reg(ov7251, OV7251_PLL1_PRE_DIV_REG, + configs->pll1->pre_div); + if (ret < 0) + return ret; + + ret = ov7251_write_reg(ov7251, OV7251_PLL1_MULT_REG, + configs->pll1->mult); + if (ret < 0) + return ret; + ret = ov7251_write_reg(ov7251, OV7251_PLL1_DIVIDER_REG, + configs->pll1->div); + if (ret < 0) + return ret; + + ret = ov7251_write_reg(ov7251, OV7251_PLL1_PIX_DIV_REG, + configs->pll1->pix_div); + if (ret < 0) + return ret; + + ret = ov7251_write_reg(ov7251, OV7251_PLL1_MIPI_DIV_REG, + configs->pll1->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; @@ -1143,6 +1237,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); @@ -1325,6 +1424,7 @@ static int ov7251_probe(struct i2c_client *client) struct ov7251 *ov7251; u8 chip_id_high, chip_id_low, chip_rev; int ret; + int i; ov7251 = devm_kzalloc(dev, sizeof(struct ov7251), GFP_KERNEL); if (!ov7251) @@ -1363,6 +1463,11 @@ 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; + + ov7251->pll_configs = ov7251_pll_configs[i]; ov7251->io_regulator = devm_regulator_get(dev, "vdddo"); if (IS_ERR(ov7251->io_regulator)) { From patchwork Tue Feb 15 23:07:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12747702 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 312A5C433EF for ; Tue, 15 Feb 2022 23:08:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S243391AbiBOXIJ (ORCPT ); Tue, 15 Feb 2022 18:08:09 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43976 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241021AbiBOXII (ORCPT ); Tue, 15 Feb 2022 18:08:08 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 777447673 for ; Tue, 15 Feb 2022 15:07:57 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id k1so496691wrd.8 for ; Tue, 15 Feb 2022 15:07:57 -0800 (PST) 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=MxqhPZOXPwbXKo4y5/HVVtSgWtZWBVp/Awnv44fZ+28=; b=PFjGE5cUjTAsyq8sEP1qsdQ4fQXio8XK8/mFZDCcSUPrnh+yjxkLr22NjqN1HGZtQx BRwHCYUYBK76JebNMUrpebFy16orqK083VypJC2cWUSeoqlC3aFnInKtpJctWmuVnNIz jdTuUqQfLoOHcdNVh47JQjGXsE3mMq79kXV4i2WH9NyrhLwPC+sXxTRiqFCMCA/5y7GY BFtgPJ7wOeizdfrbYfnOdm6zbRhYdZ1mUB5nCi5KDPuSTMVSoP8ps8LHvSOf+IzZbmrI /ZIzRR4W7wYqjNvIYicg5CwpOxKuNi3Lb+PUjrSXwBojEUqFNmsl0Xnlgyu7pEMU9LAw xdSQ== 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=MxqhPZOXPwbXKo4y5/HVVtSgWtZWBVp/Awnv44fZ+28=; b=aO82fUaPPTasMVLnWterL+S8Z5LP3GuJ/1n97M0fh8TaV+bIbBKZtsKDq+mKquzf+Q Pzca+wot7XFHa/BaVF4R+qAxWXDRzI2MlqxUy97/UXzNqinYhqEk+f90eMDePQ4LDUV9 06L1auhstGl50HeAcPnJaiF4Qin4+Y4ogxgy50AjHD5dG1VT4TIBYLaB8OHxHpjP+sHT /yS0b3heJwEqNY1vOYpvfe6/gl/4DcUBeK/fZmUGrzmdL4gm7/rtxnNNsx8vPqI8D6Xt ib0D111mALtrJK+Wo2Rd3+rUE028k3SqwEAWVdTRw7xPLWENJJCyBj4LpeZUd2MaAevF 9r8A== X-Gm-Message-State: AOAM533fpoR/DDUPqF7+fHcgSOyzjdPxiisX3mjDcEc5RLuZsqkZ6TEC ynFJpztfMZ0N9ygukCWPnxcFTiJCvBYmqg== X-Google-Smtp-Source: ABdhPJy4KpPSuRhrlepnXjBl5FtwQ5s8pBBO9n2tpCCUtD/xzSlYmazEGmHMmUFsb8XEV6aFol9eRg== X-Received: by 2002:adf:cf12:0:b0:1e3:25ac:7b25 with SMTP id o18-20020adfcf12000000b001e325ac7b25mr201603wrj.196.1644966476082; Tue, 15 Feb 2022 15:07:56 -0800 (PST) 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 w18sm16956590wrl.62.2022.02.15.15.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 15:07:55 -0800 (PST) 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 06/10] media: i2c: Add support for 19.2MHz clock to ov7251 Date: Tue, 15 Feb 2022 23:07:33 +0000 Message-Id: <20220215230737.1870630-7-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220215230737.1870630-1-djrscally@gmail.com> References: <20220215230737.1870630-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. Add the ability to support that rate to the driver by defining a new set of PLL configs. Extend the clock handling in .probe() to check for either supported frequency. Signed-off-by: Daniel Scally --- drivers/media/i2c/ov7251.c | 61 ++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 16 deletions(-) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index 809450b5a99a..92605ecdfaa4 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -134,10 +134,19 @@ static inline struct ov7251 *to_ov7251(struct v4l2_subdev *sd) } enum xclk_rate { + OV7251_19_2_MHZ, OV7251_24_MHZ, OV7251_NUM_SUPPORTED_RATES }; +static const struct ov7251_pll1_config ov7251_pll1_config_19_2_mhz = { + .pre_div = 0x03, + .mult = 0x4b, + .div = 0x01, + .pix_div = 0x0a, + .mipi_div = 0x05 +}; + static const struct ov7251_pll1_config ov7251_pll1_config_24_mhz = { .pre_div = 0x03, .mult = 0x64, @@ -146,6 +155,14 @@ static const struct ov7251_pll1_config ov7251_pll1_config_24_mhz = { .mipi_div = 0x05 }; +static const struct ov7251_pll2_config ov7251_pll2_config_19_2_mhz = { + .pre_div = 0x04, + .mult = 0x32, + .div = 0x00, + .sys_div = 0x05, + .adc_div = 0x04 +}; + static const struct ov7251_pll2_config ov7251_pll2_config_24_mhz = { .pre_div = 0x04, .mult = 0x28, @@ -154,12 +171,18 @@ static const struct ov7251_pll2_config ov7251_pll2_config_24_mhz = { .adc_div = 0x04 }; +static const struct ov7251_pll_configs ov7251_pll_configs_19_2_mhz = { + .pll1 = &ov7251_pll1_config_19_2_mhz, + .pll2 = &ov7251_pll2_config_19_2_mhz +}; + static const struct ov7251_pll_configs ov7251_pll_configs_24_mhz = { .pll1 = &ov7251_pll1_config_24_mhz, .pll2 = &ov7251_pll2_config_24_mhz }; static const struct ov7251_pll_configs *ov7251_pll_configs[] = { + [OV7251_19_2_MHZ] = &ov7251_pll_configs_19_2_mhz, [OV7251_24_MHZ] = &ov7251_pll_configs_24_mhz }; @@ -553,6 +576,7 @@ 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, }; @@ -1423,6 +1447,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; int ret; int i; @@ -1438,35 +1463,39 @@ static int ov7251_probe(struct i2c_client *client) return ret; /* get system clock (xclk) */ - ov7251->xclk = devm_clk_get(dev, "xclk"); + ov7251->xclk = devm_clk_get(dev, NULL); if (IS_ERR(ov7251->xclk)) { dev_err(dev, "could not get xclk"); return PTR_ERR(ov7251->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) { + ret = clk_set_rate(ov7251->xclk, rate); + if (ret) + return dev_err_probe(dev, ret, + "failed to set clock rate\n"); + } else 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; - } + ov7251->xclk_freq = rate ? rate : clk_get_rate(ov7251->xclk); - ret = clk_set_rate(ov7251->xclk, ov7251->xclk_freq); - if (ret) { - 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_configs = ov7251_pll_configs[i]; ov7251->io_regulator = devm_regulator_get(dev, "vdddo"); From patchwork Tue Feb 15 23:07:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12747703 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 54420C433F5 for ; Tue, 15 Feb 2022 23:08:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236611AbiBOXIL (ORCPT ); Tue, 15 Feb 2022 18:08:11 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243412AbiBOXIJ (ORCPT ); Tue, 15 Feb 2022 18:08:09 -0500 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 7BA2F65E0 for ; Tue, 15 Feb 2022 15:07:58 -0800 (PST) Received: by mail-wr1-x432.google.com with SMTP id e3so590803wra.0 for ; Tue, 15 Feb 2022 15:07:58 -0800 (PST) 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=yIAKZBtnJQwKXWI1ucGmm1tOZicYz+1srhpP8quz3OY=; b=IYgHE7mLYLnJgTvwkQGc7edqQKDxjVmpv2tKZHfD8bEb4cv5FRfJ6lPmVuDGGis4pH Yt224WdmekPb5OspNO3C2hNIsBf4ysXCKL2+xHLDty7CulBfNS+FqOTaNnQgXzGq2mYV pAJ65MSlUsf34vT8IhGPnEtDufNjijZEFUiFgKKcwN1vrvSc6CJDFkyueQrr4XdgBvop b9TNtwsDAUVGWXcGxQf1/Y8vSjCH53jCPfSVYf0fbfeImbem38TonmeffSpAOGNl2rgb cyEP7USWEWpXDlxGuGbaxulD+4JVt6F7dNb9gn4BtIYIu4w5S2sNF9+ff8ZfpGllEpAH yH/w== 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=yIAKZBtnJQwKXWI1ucGmm1tOZicYz+1srhpP8quz3OY=; b=fBOBdjN7XEnMXJwkF69868PNRpnUmppF9Hupu+27uMnUYIZbCiBE6w4khlzcOJMWQo DEmYhIxO/Rm2v2nkFAnE3NKUbDoLAwW53Oe0cV5jTbGAF9YGoxJkKhGeWSabUrBFBpVP 5/SebCk52+oUeILHoIVjyRcAeyw747DzHBPHfEkpxT1tAozuhkBtTqvvtj9+CjXDu2hz GzHA9RH8CkaJ1eGamWRTynETC1HbeRfKMAS2luxSsjlodAKLNOlAVHFE6wRisZ7J/2qB d5as54Fg6RnoZ/Lpdtdwmfj7KehkM2o8dWfGc3PXykgfmRQm8wkufRCBDQ6BYE5xxJW/ TxkQ== X-Gm-Message-State: AOAM531IPFCytZINBpEBSFfkvj4ckgBXJEVAyMC73cYDZbnLUAdfQ3yY nKpov3z/ycFIwgHavGpY84XVSzYqTLZtwQ== X-Google-Smtp-Source: ABdhPJxf7vfHdFxvVdhqLPG4HgXOs2Xj0GO19sRCIYz6rYek5e7wCnSx9c1X0xVWRDkL/ZtX18DQKg== X-Received: by 2002:adf:e607:0:b0:1e4:b899:212f with SMTP id p7-20020adfe607000000b001e4b899212fmr146237wrm.173.1644966477110; Tue, 15 Feb 2022 15:07:57 -0800 (PST) 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 w18sm16956590wrl.62.2022.02.15.15.07.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 15:07:56 -0800 (PST) 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 07/10] media: i2c: Add ov7251_detect_chip() Date: Tue, 15 Feb 2022 23:07:34 +0000 Message-Id: <20220215230737.1870630-8-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220215230737.1870630-1-djrscally@gmail.com> References: <20220215230737.1870630-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 --- 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 92605ecdfaa4..f137a1e87537 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -1442,11 +1442,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; int ret; int i; @@ -1578,34 +1610,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 Tue Feb 15 23:07:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12747704 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 D052AC433FE for ; Tue, 15 Feb 2022 23:08:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244336AbiBOXIM (ORCPT ); Tue, 15 Feb 2022 18:08:12 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:43998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243426AbiBOXIL (ORCPT ); Tue, 15 Feb 2022 18:08:11 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 935017673 for ; Tue, 15 Feb 2022 15:07:59 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id v129so182815wme.2 for ; Tue, 15 Feb 2022 15:07:59 -0800 (PST) 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=Iv+bUBoKf/lNxici8br7gTJshq/us8jPfldYaC2Vdfc=; b=nNGh1YophE67cY2vO2LDTrPg06FEJ/gW4QFNX7Y42Rlzlmn0ft47oal6Hd1AcGLCgf NwOn5JS3cbzAGAfTyvnJ587EGG/KW8gcULBUdlKgLc6VZac+zCJKqal1Ddmn3G2pEm1N EcIz70uigBZzOP3xPI18OxOeBrbzIDMzybaMOU9jPgXK9BjCOzTjOvi6zEAT0D5go7nI gP77sh03EEfdaJi5UJ8ZS82UqSjJjj7mjJ0vesh/Mx3jNd7tPHoFmlPjrlGEeL124Ais 7bQj2JxCt9ye5/aAeD77zbfH08NL65IlfVMTgsYuSU6jD3N2+/KcZmooXmTfCQGAZUsO 4OMA== 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=Iv+bUBoKf/lNxici8br7gTJshq/us8jPfldYaC2Vdfc=; b=Tx8n/rKwJ4VLqnQaW2VwgLQLFNH/I84NAskIzHhHpqaSI/i2N7mNiOBSUfSSlp+qwu hti0ML8LfypFw1UvyXcSbRUvOastC2MVRhk3XSa+OF8Su/NK7uvmHRYy2oA6NE6OG/C8 byaxhawcYoazYiIg4KcA2/IkFr1yz8Q/p45Y2hf869+jc/EYnFV7i31DkqbtOZi4QmLO jMKyhZzpqmJnx9zdpGtxbQhuciwYXrKognT9V6sAlxlWAogOZZlGhDdBcWSCCEe2LyoV efit+v7og/TPiuGsGfZvX0dWeTQ9pSPMc7wP6KoONc1JbZD9P+KpUjspddB4NHLSqdy/ ehuQ== X-Gm-Message-State: AOAM530GmWMuJ7kfq85ruln/EqvcHUYcuXrmbYXOVzI/B83U3XyDadve 4ofI8Bl/iEnv0g8TsESTiki/4UVMJshqmA== X-Google-Smtp-Source: ABdhPJzL01EsitoQnTF7QU5CyqHgx3RmUYtrWjlUD99f0CjwRe9eOO+8OOdz4yiykvCMdUI+3pu7rA== X-Received: by 2002:a1c:4443:0:b0:34d:a9d6:884 with SMTP id r64-20020a1c4443000000b0034da9d60884mr5044885wma.50.1644966478238; Tue, 15 Feb 2022 15:07:58 -0800 (PST) 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 w18sm16956590wrl.62.2022.02.15.15.07.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 15:07:57 -0800 (PST) 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 08/10] media: i2c: Add pm_runtime support to ov7251 Date: Tue, 15 Feb 2022 23:07:35 +0000 Message-Id: <20220215230737.1870630-9-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220215230737.1870630-1-djrscally@gmail.com> References: <20220215230737.1870630-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 --- drivers/media/i2c/ov7251.c | 78 ++++++++++++++++++++++++++++++-------- 1 file changed, 63 insertions(+), 15 deletions(-) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index f137a1e87537..d620ed6a4e42 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -884,6 +885,24 @@ static void ov7251_set_power_off(struct ov7251 *ov7251) ov7251_regulators_disable(ov7251); } +static int __maybe_unused ov7251_sensor_suspend(struct device *dev) +{ + struct v4l2_subdev *sd = dev_get_drvdata(dev); + struct ov7251 *ov7251 = to_ov7251(sd); + + ov7251_set_power_off(ov7251); + + return 0; +} + +static int __maybe_unused ov7251_sensor_resume(struct device *dev) +{ + struct v4l2_subdev *sd = dev_get_drvdata(dev); + struct ov7251 *ov7251 = to_ov7251(sd); + + return ov7251_set_power_on(ov7251); +} + static int ov7251_s_power(struct v4l2_subdev *sd, int on) { struct ov7251 *ov7251 = to_ov7251(sd); @@ -985,7 +1004,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) { @@ -1009,6 +1028,8 @@ static int ov7251_s_ctrl(struct v4l2_ctrl *ctrl) break; } + pm_runtime_put(ov7251->dev); + return ret; } @@ -1261,10 +1282,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) + return ret; + 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, @@ -1273,23 +1299,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: mutex_unlock(&ov7251->lock); + return ret; +err_power_down: + pm_runtime_put_noidle(ov7251->dev); + mutex_unlock(&ov7251->lock); return ret; } @@ -1604,23 +1636,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); + 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, @@ -1628,7 +1661,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, @@ -1636,10 +1669,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) { @@ -1651,6 +1686,9 @@ 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); free_entity: @@ -1672,9 +1710,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); + pm_runtime_set_suspended(ov7251->dev); + return 0; } +static const struct dev_pm_ops ov7251_pm_ops = { + SET_RUNTIME_PM_OPS(ov7251_sensor_suspend, ov7251_sensor_resume, NULL) +}; + static const struct of_device_id ov7251_of_match[] = { { .compatible = "ovti,ov7251" }, { /* sentinel */ } @@ -1692,6 +1739,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 Tue Feb 15 23:07:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12747705 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 A40EBC4332F for ; Tue, 15 Feb 2022 23:08:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244348AbiBOXIM (ORCPT ); Tue, 15 Feb 2022 18:08:12 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:44000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243451AbiBOXIL (ORCPT ); Tue, 15 Feb 2022 18:08:11 -0500 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 8D88665E0 for ; Tue, 15 Feb 2022 15:08:00 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id h6so494185wrb.9 for ; Tue, 15 Feb 2022 15:08:00 -0800 (PST) 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=l2tRfNrOIKSoY0VV6Ty+DAIfmKgy5ueutRp2dWCh5N8=; b=PD3lJUsN8qPv5UHjhZchPZvcRsBUS1Xn9Y86GpZxWDrbgStg3LXVP/tfnM4P7TSpYI N2MY9cfjvK0YOGBaDA0e77geHyZiBl9oBxLc2KFyScYVONOV4VLB6ZxPmcQ3Cn7QuFyh IgkEw+NVsw+Fzr9rCGBsouh9C2mVNgGfXXRD6D5hNSBG4+pcIPs82UpJKSrrMDsnXZmz 9vXB3eLbVJMhwdBmZeDvDNEDaLIn1KOhnmuaEq4p/2eXijJhvbtypwvB6ZOC40eEpvPg rxeGeyeO8NnIHIWRQBRVwIMl2HVxaRVTrxhG3C1p+dHm+7Qznks2lPp2emPQXCMq7aKR 9pxQ== 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=l2tRfNrOIKSoY0VV6Ty+DAIfmKgy5ueutRp2dWCh5N8=; b=hcZ9m3qSo/0mLj+fMs8YhvOsi9Z/Vd72xeEv/yyPZg0gP1MB7ESb98jvXImgJm7sUm TD0gm4EjEu9h1x+sdg2hjyNrezmUgyRkXQxqSPojxf2qp5bghfHjt0pxjhjDELpwYET3 7DSr8sKXHF3z3pCdGSQOUVuWZC4qrYno6ziklXigr7Jpliz3vnyqTBv+O+DB1U7oSB5e Ppp+DbqOdxazvEZEQWzsIzkTHMGThOfo7ydbZj6WKgjIRpWg7A/nqTV9gAXSt8yQhQYF S8hUKzYraLZhfPcIWyiR+36Eyoc0lEh/KAH60A/TCfWF2GmnDaGps5UyajLkCNq/IFko +eHQ== X-Gm-Message-State: AOAM531ZCCPRqOixeqSnmxr2OwzlZPvrMpGZC/TqQy03cPcfxzWtlEjE pdUR0uVDdOzEgsI1d0mI2hKQO9J30K8pjg== X-Google-Smtp-Source: ABdhPJwyjDUeKKWmw2gNSF/NQP1ARSi9LWPJGNMG4fNyQdBATH4e+kZQ0jiHVL86cgYeYPeGsiP+qA== X-Received: by 2002:adf:d082:0:b0:1e3:16e2:d611 with SMTP id y2-20020adfd082000000b001e316e2d611mr165280wrh.716.1644966479230; Tue, 15 Feb 2022 15:07:59 -0800 (PST) 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 w18sm16956590wrl.62.2022.02.15.15.07.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 15:07:58 -0800 (PST) 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 09/10] media: i2c: Remove .s_power() from ov7251 Date: Tue, 15 Feb 2022 23:07:36 +0000 Message-Id: <20220215230737.1870630-10-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220215230737.1870630-1-djrscally@gmail.com> References: <20220215230737.1870630-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 Reported-by: kernel test robot --- drivers/media/i2c/ov7251.c | 44 +------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/drivers/media/i2c/ov7251.c b/drivers/media/i2c/ov7251.c index d620ed6a4e42..5e7422ca4ab9 100644 --- a/drivers/media/i2c/ov7251.c +++ b/drivers/media/i2c/ov7251.c @@ -903,43 +903,6 @@ static int __maybe_unused ov7251_sensor_resume(struct device *dev) return ov7251_set_power_on(ov7251); } -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); - 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); - goto exit; - } - - ov7251->power_on = true; - } else { - ov7251_set_power_off(ov7251); - 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; @@ -1384,10 +1347,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, @@ -1405,7 +1364,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, }; @@ -1690,7 +1648,7 @@ static int ov7251_probe(struct i2c_client *client) pm_runtime_disable(ov7251->dev); pm_runtime_put_noidle(ov7251->dev); power_down: - ov7251_s_power(&ov7251->sd, false); + ov7251_set_power_off(ov7251); free_entity: media_entity_cleanup(&ov7251->sd.entity); free_ctrl: From patchwork Tue Feb 15 23:07:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Scally X-Patchwork-Id: 12747706 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 277A8C433EF for ; Tue, 15 Feb 2022 23:08:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244358AbiBOXIN (ORCPT ); Tue, 15 Feb 2022 18:08:13 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:44014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244343AbiBOXIM (ORCPT ); Tue, 15 Feb 2022 18:08:12 -0500 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 839987674 for ; Tue, 15 Feb 2022 15:08:01 -0800 (PST) Received: by mail-wm1-x335.google.com with SMTP id x3-20020a05600c21c300b0037c01ad715bso388023wmj.2 for ; Tue, 15 Feb 2022 15:08:01 -0800 (PST) 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=3iUKXpsWvnYENTSa7D2kghfQRHXp3gOSZNEj5S0Nu0A=; b=Vytv+VH+8Xu9JpX537GKIqhwBr+oI95WiBwq40kqoESolCyaiJUoRYlqc9nc8qiNRp 44P+scSfeexEZWHklQ6PAAR0/nWNl+HBnNFMw/OanVJ3eQCgNA/zzjCirgcmgxelzmQo +KQjkXh580sgV0JG4yS+O3G0Z7NFUdcwzfha19pw0AOU3c8MlooiPZllvO1guSY+/Se/ 3/i9EA3cyvZoFEZWstsuk/3xpNBkQlq2gWZlG+7OB4p+hsm2vNy7ZQT0OobE+eyuzial DbuTOyHzFWNOAMgysUrZ3yC2l6VXyE+loGmjltYk0DDidOHkVqrPAt3lhTEu63D3+Aur 2XTg== 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=3iUKXpsWvnYENTSa7D2kghfQRHXp3gOSZNEj5S0Nu0A=; b=VXdzvrByynpidxR0S6ibeiooR369/c69ImqsYsuJcOPUIaqbIK0Ftgfu2cULn7/5pV j6gIUbpItwNYgsLrtq1G26ZDM6EeeoHRcCHXUOtRRmmwN38hqHBmv7mAiMUvR9qikea6 2145LYakKpHJwovXjzu8TS89fvbP29KW7S8yhuPFkxA/GuHsr04iRTqja43yqadKJ74a daqvCitWODMiSdou0L0IqAZBG2gozOiYy3Noy3lreTyNGvijyArN4U9Z0j1/E5Yf8T6V lmCYLhYHD/8/xP8ExSQb1HW+EcuNMRCy7lDb0PRm727dRUNfLqFqzSu8sWJJjuUcAZTk M+ww== X-Gm-Message-State: AOAM532egu4uG6vAHIyYpCX499pP47t+ZwkrmgItEmq1jiH5d3qBOJfV G88hCo4S+5Tr6UpSSoY9t8pyPgWohAtI3g== X-Google-Smtp-Source: ABdhPJx04N05ZsAMUTfSc1foZNTar/e3QqN7QNB0R+I++9Z6u1QjE7TXLG95S/B5ARjmTmJbVwDePA== X-Received: by 2002:a05:600c:22d3:b0:37b:f1a7:ceb5 with SMTP id 19-20020a05600c22d300b0037bf1a7ceb5mr124707wmg.164.1644966480205; Tue, 15 Feb 2022 15:08:00 -0800 (PST) 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 w18sm16956590wrl.62.2022.02.15.15.07.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Feb 2022 15:07:59 -0800 (PST) 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 10/10] media: ipu3-cio2: Add INT347E to cio2-bridge Date: Tue, 15 Feb 2022 23:07:37 +0000 Message-Id: <20220215230737.1870630-11-djrscally@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220215230737.1870630-1-djrscally@gmail.com> References: <20220215230737.1870630-1-djrscally@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org ACPI _HID INT347E represents the ov7251 sensor, which can be supported by the cio2-bridge. Add it to the list of supported devices so the bridge builts the software nodes. Signed-off-by: Daniel Scally --- 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..a27b4948b4f6 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, 240000000), /* Omnivision OV2680 */ CIO2_SENSOR_CONFIG("OVTI2680", 0), };