From patchwork Tue Mar 14 11:55:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaishnav Achath X-Patchwork-Id: 69538 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1719275wrd; Tue, 14 Mar 2023 05:13:09 -0700 (PDT) X-Google-Smtp-Source: AK7set/B6tCTQ2Os2lyDA9D7HIgAfwtd6awxvjKlooOZZeBoWJn1d5K+9H/sNKPAYpfVBNhrf5dB X-Received: by 2002:a05:6a21:32a2:b0:cb:8d74:112e with SMTP id yt34-20020a056a2132a200b000cb8d74112emr41029636pzb.45.1678795989554; Tue, 14 Mar 2023 05:13:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678795989; cv=none; d=google.com; s=arc-20160816; b=nWlEIHiDm7TY8x2lnFXTs9+K9q4obFumQ/Cc92WPIDKrZbOu8mgX1obLB0X+5Lb1u2 CWr4ACsDJNXgI7+UY7rFuMYjV8e6//5CWFWrAY5n/bdY142NFqUt0jh6zAl7HpqURtNr KtdfWXDLn/9HxxSg2wdhkVIxJqrjbj1OinDX3J9yC3j2bW3T7kpD5ZGWjfUNXfxv7P9a T/qUs8V8By9suXgNN90Eun91awVTYDcRyGZpV7QzcxCszeREPSATSow6ASyI7oDwme8i X+IgTZekz9DgSZGKPaGL0Zq+5P4A6oT/NzcNSA4qb0U5YM1sIsUqvxgdBw/Af5HdmQmM RidA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=hoH8JvDJMF9kb6jtv86aNPb3gPGJn4rtX1ltZYZwBtA=; b=GayQmkbgZvxRB/YifC5ojGNe/qaaReREIB/QXGDvuzuKvy1YtPzgUTStlSYEOaFN20 ZN5us/Y6gyR4BuvgVK6bUxS+3VPlgMUgxW9VmBGlrEj2cDuo/PqFT+XoZcN4zy9Rs7Rg uXxg2FRB92nS+VrXhZZWt4+9fUDvPqBRCru59m4tD88zb67eljJSxXcQDS8vyNA4fud6 JPa7cY38idAzj8VkIHEQON9/MoUZOgYNxbDF6NCBNrF5Em3rFR250huqL77xW7E3D8D1 x07OBi1elXozWPSnN9o5Y7OIGTWIhHe3Lt6DMc9fJVBagajleXEPAaT9uQ0vBCvrXEEw EUOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=BTzJFcM5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e14-20020a631e0e000000b004ffc2ec1b51si2043459pge.271.2023.03.14.05.12.53; Tue, 14 Mar 2023 05:13:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=BTzJFcM5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231675AbjCNL43 (ORCPT + 99 others); Tue, 14 Mar 2023 07:56:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231630AbjCNL4Q (ORCPT ); Tue, 14 Mar 2023 07:56:16 -0400 Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 14CDF9FBF8; Tue, 14 Mar 2023 04:55:59 -0700 (PDT) Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtLjc118609; Tue, 14 Mar 2023 06:55:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1678794921; bh=hoH8JvDJMF9kb6jtv86aNPb3gPGJn4rtX1ltZYZwBtA=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=BTzJFcM5QVeEDKZeJuZm66vU2YfiyRbTZ4jFP0aMW3/GA1RmUYuLgt77I4GJtcMIP qIOjj2RRNJnjJQb87r9Bfq6YQ72V21409rMB0J0TQbqG09yuHsUxtKqIrxsmgJuqlN VCGxiCKnr0XbOvGxDfjSaJcayA8747fC9uOMDEDg= Received: from DFLE110.ent.ti.com (dfle110.ent.ti.com [10.64.6.31]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 32EBtLTV112465 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 14 Mar 2023 06:55:21 -0500 Received: from DFLE108.ent.ti.com (10.64.6.29) by DFLE110.ent.ti.com (10.64.6.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Tue, 14 Mar 2023 06:55:20 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE108.ent.ti.com (10.64.6.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Tue, 14 Mar 2023 06:55:20 -0500 Received: from localhost (ileaxei01-snat.itg.ti.com [10.180.69.5]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtJ31002271; Tue, 14 Mar 2023 06:55:20 -0500 From: Vaishnav Achath To: , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v7 01/13] media: cadence: csi2rx: Unregister v4l2 async notifier Date: Tue, 14 Mar 2023 17:25:04 +0530 Message-ID: <20230314115516.667-2-vaishnav.a@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314115516.667-1-vaishnav.a@ti.com> References: <20230314115516.667-1-vaishnav.a@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760345183770531107?= X-GMAIL-MSGID: =?utf-8?q?1760345183770531107?= From: Pratyush Yadav The notifier is added to the global notifier list when registered. When the module is removed, the struct csi2rx_priv in which the notifier is embedded, is destroyed. As a result the notifier list has a reference to a notifier that no longer exists. This causes invalid memory accesses when the list is iterated over. Similar for when the probe fails. Unregister and clean up the notifier to avoid this. Fixes: 1fc3b37f34f6 ("media: v4l: cadence: Add Cadence MIPI-CSI2 RX driver") Signed-off-by: Pratyush Yadav Signed-off-by: Vaishnav Achath Reviewed-by: Laurent Pinchart --- (no changes since v5) Changes in v5: - Cleanup notifier in csi2rx_parse_dt() after the call to v4l2_async_nf_add_fwnode_remote(). Changes in v3: - New in v3. drivers/media/platform/cadence/cdns-csi2rx.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c index cc3ebb0d96f6..2a23da6a0b8e 100644 --- a/drivers/media/platform/cadence/cdns-csi2rx.c +++ b/drivers/media/platform/cadence/cdns-csi2rx.c @@ -404,8 +404,10 @@ static int csi2rx_parse_dt(struct csi2rx_priv *csi2rx) asd = v4l2_async_nf_add_fwnode_remote(&csi2rx->notifier, fwh, struct v4l2_async_subdev); of_node_put(ep); - if (IS_ERR(asd)) + if (IS_ERR(asd)) { + v4l2_async_nf_cleanup(&csi2rx->notifier); return PTR_ERR(asd); + } csi2rx->notifier.ops = &csi2rx_notifier_ops; @@ -467,6 +469,7 @@ static int csi2rx_probe(struct platform_device *pdev) return 0; err_cleanup: + v4l2_async_nf_unregister(&csi2rx->notifier); v4l2_async_nf_cleanup(&csi2rx->notifier); err_free_priv: kfree(csi2rx); @@ -477,6 +480,8 @@ static int csi2rx_remove(struct platform_device *pdev) { struct csi2rx_priv *csi2rx = platform_get_drvdata(pdev); + v4l2_async_nf_unregister(&csi2rx->notifier); + v4l2_async_nf_cleanup(&csi2rx->notifier); v4l2_async_unregister_subdev(&csi2rx->subdev); kfree(csi2rx); From patchwork Tue Mar 14 11:55:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaishnav Achath X-Patchwork-Id: 69536 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1719143wrd; Tue, 14 Mar 2023 05:12:54 -0700 (PDT) X-Google-Smtp-Source: AK7set9pVyUBQiPDrnueziPrA7tB7mcUGFyqfpaiQou+iMXlDsO2LIy8uVpS3//OHqiTlQofQieP X-Received: by 2002:a17:903:481:b0:1a0:5bb1:3f15 with SMTP id jj1-20020a170903048100b001a05bb13f15mr3408934plb.69.1678795974414; Tue, 14 Mar 2023 05:12:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678795974; cv=none; d=google.com; s=arc-20160816; b=c0EGOEMuI+eWZXX0x/Z+0bSlyFzRe3kV0yhFUuK7CX4TWBJx8nzvs5KXVOhaoDE4Bn 5AQF4F4rG3U7nUPPsW8Zs25mWMXVHzHK6tAl58WWPkuWf9qGalrR7UVLRo+y5ywUE3Dd kaqJH3W020NsMsGSQ1/fHbkOqmxEB36+Hipxxmrv1K805wGbn1PwZAk7BlQAefFpj22V BShKO1+565COjFLJsPEYZwFq2Za+nZloi6tkzW7TbEBUYCTfPFfdPVq9HqqzzZsEjn/g G+UtBq+vnWPhtFhmWdxpfQTc3CXTzDTW8OE+SH0FjhDgSbHbsqRmCoLuSKzhBASxJXV2 841A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=WlYyHV2rscE3JvYAKhJpMK+zPp8qksypOpo3lqWNjEM=; b=q7IPM8A1031RVa1tiVM1Cv2qtrqBS62jiAcp1LReHI8Gd1bNHhwPsEw2pccYFFBYWb muyNQhLLHoF6WRTp0jmyMwHlELGrwPeNKdX8nEmT9tsOn4/UmkrY0iAUtFsxyVZkSDuC VVZsOXFL2pHvuRQBN7Q51xuYtP2855geQKUZ5n+bzLdwimjJolMZmxF3z+u0jllzLMRf 6XrlJrgSk8XEpiKxFWyOQsSoxltqj96MVorQmhpvL1/+tTL3XP5fSEGfi+5vX0NHc+8p 2/yQPEBpa2qI8NmJda5TMi7SUdZIMOH6ziMTCF64R8Q4m4ladH+UAIRC6p2k/X7ZD/Zo xcZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=u1AGv+iq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n14-20020a63590e000000b004df43225600si1984352pgb.709.2023.03.14.05.12.39; Tue, 14 Mar 2023 05:12:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=u1AGv+iq; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231582AbjCNLzz (ORCPT + 99 others); Tue, 14 Mar 2023 07:55:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231536AbjCNLzs (ORCPT ); Tue, 14 Mar 2023 07:55:48 -0400 Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07CDA89F27; Tue, 14 Mar 2023 04:55:45 -0700 (PDT) Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtNLR105613; Tue, 14 Mar 2023 06:55:23 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1678794923; bh=WlYyHV2rscE3JvYAKhJpMK+zPp8qksypOpo3lqWNjEM=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=u1AGv+iq/1lehFNWh1VRk0FsEejdUXrvBaljru6KlqEkJb9hwryOeWZPgArm0zPdh DlaPa64UtMxhn6JhXDdU9VNEe713/XXkYd+KHBz14v3MlRNUZ7XPDFS9RL4Rayin8E TI7QfUfF2xhsGiAARTbEgJ5W04z93kNsuLmtGGKk= Received: from DFLE103.ent.ti.com (dfle103.ent.ti.com [10.64.6.24]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 32EBtN5R002951 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 14 Mar 2023 06:55:23 -0500 Received: from DFLE104.ent.ti.com (10.64.6.25) by DFLE103.ent.ti.com (10.64.6.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Tue, 14 Mar 2023 06:55:22 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Tue, 14 Mar 2023 06:55:22 -0500 Received: from localhost (ileaxei01-snat.itg.ti.com [10.180.69.5]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtLh0057098; Tue, 14 Mar 2023 06:55:22 -0500 From: Vaishnav Achath To: , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v7 02/13] media: cadence: csi2rx: Cleanup media entity properly Date: Tue, 14 Mar 2023 17:25:05 +0530 Message-ID: <20230314115516.667-3-vaishnav.a@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314115516.667-1-vaishnav.a@ti.com> References: <20230314115516.667-1-vaishnav.a@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760345167516331140?= X-GMAIL-MSGID: =?utf-8?q?1760345167516331140?= From: Pratyush Yadav Call media_entity_cleanup() in probe error path and remove to make sure the media entity is cleaned up properly. Suggested-by: Laurent Pinchart Signed-off-by: Pratyush Yadav Signed-off-by: Vaishnav Achath Reviewed-by: Laurent Pinchart --- (no changes since v6) Changes in v6: - Add Laurent's R-by. Changes in v5: - New in v5. drivers/media/platform/cadence/cdns-csi2rx.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c index 2a23da6a0b8e..2547903f2e8e 100644 --- a/drivers/media/platform/cadence/cdns-csi2rx.c +++ b/drivers/media/platform/cadence/cdns-csi2rx.c @@ -471,6 +471,7 @@ static int csi2rx_probe(struct platform_device *pdev) err_cleanup: v4l2_async_nf_unregister(&csi2rx->notifier); v4l2_async_nf_cleanup(&csi2rx->notifier); + media_entity_cleanup(&csi2rx->subdev.entity); err_free_priv: kfree(csi2rx); return ret; @@ -483,6 +484,7 @@ static int csi2rx_remove(struct platform_device *pdev) v4l2_async_nf_unregister(&csi2rx->notifier); v4l2_async_nf_cleanup(&csi2rx->notifier); v4l2_async_unregister_subdev(&csi2rx->subdev); + media_entity_cleanup(&csi2rx->subdev.entity); kfree(csi2rx); return 0; From patchwork Tue Mar 14 11:55:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaishnav Achath X-Patchwork-Id: 69532 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1717899wrd; Tue, 14 Mar 2023 05:10:42 -0700 (PDT) X-Google-Smtp-Source: AK7set+OAPPXA+5X2VVQQT6BGmtOvWXyRoDEh1gz5hhnJ+dwrFeu8FF87pCtlMNMVC5VRsoT2HEt X-Received: by 2002:a17:903:4cd:b0:19c:ed28:66ec with SMTP id jm13-20020a17090304cd00b0019ced2866ecmr31290367plb.21.1678795842056; Tue, 14 Mar 2023 05:10:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678795842; cv=none; d=google.com; s=arc-20160816; b=I0wWmxTtWJ1eMw6FGIY6nLxaWx/H/Ynm2AfBR6HEpftj4xe6ORNI1IJ+5IJ8M/k682 tftrxPCO4xejYCI9QnGuXw/kYyTk9NIcQ0Ja/Ngd+wmXPITHvZi0E7ejP3UIEw7cu36t 4/MfNWOXVRMN2G6athtfieXZurSTb5ey24DuzuV3sQJIFvEuz/YvD8DPOgqPlua9iKtZ B7nJ5cF6hq8aE8yOxyM9CXRn4a8rvpr67gZJ9CxSmaciDFW3fcCf1cYJctTQznOR7dFb MOA1diDRASTBul7ycXvGVjyr40LSoo5YjTplua2bdC36MFszJXUCnWtWiTH/B08eLrIZ UMEQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=IFJsUQk232s7e8N9uoqezRx3OBmYY8+n+kXrVuwBMoI=; b=o6tmB5Y5CNZW1FrQEFRPaLgTzYjdWstST17iWYFJxZmd4hoOlE7GoIr+j3z0NrXC6F WCtSv8rSMu3nBH+waSaQdMTiF1zOy5barYri9+nSzz7svP1XpQI9PEfntEnHuAZ7W9c6 iEKYI4xoETUiYuhy8kWcFpuB05DhgEC7cWhlN98yj9DlAgFEZL6Ki+29XgyDQscUK/Ku SkWWtJi/uIFKEfe0nZkbV2CEg5vDM1KFac4Q2bxG1dmEdYuDQw7ck5zQV4GYvljzUI3l Xw1ofRpbtow8xuYZJThFElnh3nEVmDI7xmN+QkocmjKyXOyFL4cjdLUDJEcnferGZWqu 1vMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=iL8UVw+V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ko12-20020a17090307cc00b0019a71e14c19si2368447plb.320.2023.03.14.05.10.26; Tue, 14 Mar 2023 05:10:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=iL8UVw+V; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231572AbjCNLzw (ORCPT + 99 others); Tue, 14 Mar 2023 07:55:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231526AbjCNLzr (ORCPT ); Tue, 14 Mar 2023 07:55:47 -0400 Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 082348A3AE; Tue, 14 Mar 2023 04:55:45 -0700 (PDT) Received: from lelv0266.itg.ti.com ([10.180.67.225]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtP8m105671; Tue, 14 Mar 2023 06:55:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1678794925; bh=IFJsUQk232s7e8N9uoqezRx3OBmYY8+n+kXrVuwBMoI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=iL8UVw+V8s4vUm8sj2/h7wrug3M7mhZRcR1T5acfpLO9/ylMq4AjTuq4+4VH2kEdk +d4b2kOa92/XWqIU+RSZ9Cs+tGyKasqlvP97igKH2A5r6lQhUvE7+MJIqru6j7PBNh GxKp/ysJzsrvMD/DE2/Cr29aQQOy7ruRNbbwwfpQ= Received: from DLEE106.ent.ti.com (dlee106.ent.ti.com [157.170.170.36]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 32EBtPp1112494 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 14 Mar 2023 06:55:25 -0500 Received: from DLEE109.ent.ti.com (157.170.170.41) by DLEE106.ent.ti.com (157.170.170.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Tue, 14 Mar 2023 06:55:24 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DLEE109.ent.ti.com (157.170.170.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Tue, 14 Mar 2023 06:55:24 -0500 Received: from localhost (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtNok111799; Tue, 14 Mar 2023 06:55:24 -0500 From: Vaishnav Achath To: , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v7 03/13] media: cadence: csi2rx: Add get_fmt and set_fmt pad ops Date: Tue, 14 Mar 2023 17:25:06 +0530 Message-ID: <20230314115516.667-4-vaishnav.a@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314115516.667-1-vaishnav.a@ti.com> References: <20230314115516.667-1-vaishnav.a@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760345028516203799?= X-GMAIL-MSGID: =?utf-8?q?1760345028516203799?= From: Pratyush Yadav The format is needed to calculate the link speed for the external DPHY configuration. It is not right to query the format from the source subdev. Add get_fmt and set_fmt pad operations so that the format can be configured and correct bpp be selected. Signed-off-by: Pratyush Yadav Signed-off-by: Vaishnav Achath Reviewed-by: Laurent Pinchart --- Changes in v7: - Add Laurent's R-by. Changes in v6: - Move the lock around the dereference for framefmt in csi2rx_{get,set}_fmt() instead of when we get the pointer. - Do not return an error when an unsupported format is set. Instead adjust the code to the first format in the list. - Not adding Laurent's R-by since I am making changes in csi2rx_set_fmt() that he didn't explicitly recommend. Changes in v5: - Use YUV 1X16 formats instead of 2X8. - New in v5. drivers/media/platform/cadence/cdns-csi2rx.c | 131 +++++++++++++++++++ 1 file changed, 131 insertions(+) diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c index 2547903f2e8e..ae3ebdb3890d 100644 --- a/drivers/media/platform/cadence/cdns-csi2rx.c +++ b/drivers/media/platform/cadence/cdns-csi2rx.c @@ -54,6 +54,11 @@ enum csi2rx_pads { CSI2RX_PAD_MAX, }; +struct csi2rx_fmt { + u32 code; + u8 bpp; +}; + struct csi2rx_priv { struct device *dev; unsigned int count; @@ -79,12 +84,43 @@ struct csi2rx_priv { struct v4l2_subdev subdev; struct v4l2_async_notifier notifier; struct media_pad pads[CSI2RX_PAD_MAX]; + struct v4l2_mbus_framefmt fmt; /* Remote source */ struct v4l2_subdev *source_subdev; int source_pad; }; +static const struct csi2rx_fmt formats[] = { + { + .code = MEDIA_BUS_FMT_YUYV8_1X16, + .bpp = 16, + }, + { + .code = MEDIA_BUS_FMT_UYVY8_1X16, + .bpp = 16, + }, + { + .code = MEDIA_BUS_FMT_YVYU8_1X16, + .bpp = 16, + }, + { + .code = MEDIA_BUS_FMT_VYUY8_1X16, + .bpp = 16, + }, +}; + +static const struct csi2rx_fmt *csi2rx_get_fmt_by_code(u32 code) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(formats); i++) + if (formats[i].code == code) + return &formats[i]; + + return NULL; +} + static inline struct csi2rx_priv *v4l2_subdev_to_csi2rx(struct v4l2_subdev *subdev) { @@ -236,12 +272,103 @@ static int csi2rx_s_stream(struct v4l2_subdev *subdev, int enable) return ret; } +static struct v4l2_mbus_framefmt * +csi2rx_get_pad_format(struct csi2rx_priv *csi2rx, + struct v4l2_subdev_state *state, + unsigned int pad, u32 which) +{ + switch (which) { + case V4L2_SUBDEV_FORMAT_TRY: + return v4l2_subdev_get_try_format(&csi2rx->subdev, state, pad); + case V4L2_SUBDEV_FORMAT_ACTIVE: + return &csi2rx->fmt; + default: + return NULL; + } +} + +static int csi2rx_get_fmt(struct v4l2_subdev *subdev, + struct v4l2_subdev_state *state, + struct v4l2_subdev_format *format) +{ + struct csi2rx_priv *csi2rx = v4l2_subdev_to_csi2rx(subdev); + struct v4l2_mbus_framefmt *framefmt; + + framefmt = csi2rx_get_pad_format(csi2rx, state, format->pad, + format->which); + if (!framefmt) + return -EINVAL; + + mutex_lock(&csi2rx->lock); + format->format = *framefmt; + mutex_unlock(&csi2rx->lock); + + return 0; +} + +static int csi2rx_set_fmt(struct v4l2_subdev *subdev, + struct v4l2_subdev_state *state, + struct v4l2_subdev_format *format) +{ + struct csi2rx_priv *csi2rx = v4l2_subdev_to_csi2rx(subdev); + struct v4l2_mbus_framefmt *framefmt; + + /* No transcoding, source and sink formats must match. */ + if (format->pad != CSI2RX_PAD_SINK) + return csi2rx_get_fmt(subdev, state, format); + + if (!csi2rx_get_fmt_by_code(format->format.code)) + format->format.code = formats[0].code; + + format->format.field = V4L2_FIELD_NONE; + + framefmt = csi2rx_get_pad_format(csi2rx, state, format->pad, + format->which); + if (!framefmt) + return -EINVAL; + + mutex_lock(&csi2rx->lock); + *framefmt = format->format; + mutex_unlock(&csi2rx->lock); + + return 0; +} + +static int csi2rx_init_cfg(struct v4l2_subdev *subdev, + struct v4l2_subdev_state *state) +{ + struct v4l2_subdev_format format = { + .which = state ? V4L2_SUBDEV_FORMAT_TRY + : V4L2_SUBDEV_FORMAT_ACTIVE, + .pad = CSI2RX_PAD_SINK, + .format = { + .width = 640, + .height = 480, + .code = MEDIA_BUS_FMT_UYVY8_1X16, + .field = V4L2_FIELD_NONE, + .colorspace = V4L2_COLORSPACE_SRGB, + .ycbcr_enc = V4L2_YCBCR_ENC_601, + .quantization = V4L2_QUANTIZATION_LIM_RANGE, + .xfer_func = V4L2_XFER_FUNC_SRGB, + }, + }; + + return csi2rx_set_fmt(subdev, state, &format); +} + +static const struct v4l2_subdev_pad_ops csi2rx_pad_ops = { + .get_fmt = csi2rx_get_fmt, + .set_fmt = csi2rx_set_fmt, + .init_cfg = csi2rx_init_cfg, +}; + static const struct v4l2_subdev_video_ops csi2rx_video_ops = { .s_stream = csi2rx_s_stream, }; static const struct v4l2_subdev_ops csi2rx_subdev_ops = { .video = &csi2rx_video_ops, + .pad = &csi2rx_pad_ops, }; static int csi2rx_async_bound(struct v4l2_async_notifier *notifier, @@ -457,6 +584,10 @@ static int csi2rx_probe(struct platform_device *pdev) if (ret) goto err_cleanup; + ret = csi2rx_init_cfg(&csi2rx->subdev, NULL); + if (ret) + goto err_cleanup; + ret = v4l2_async_register_subdev(&csi2rx->subdev); if (ret < 0) goto err_cleanup; From patchwork Tue Mar 14 11:55:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaishnav Achath X-Patchwork-Id: 69539 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1719651wrd; Tue, 14 Mar 2023 05:13:52 -0700 (PDT) X-Google-Smtp-Source: AK7set+hm0bw/r3n72Djr0hdhVbqUlTqFqfgJWJuk4cVfIauHaoq8SFhGa3jkYgFtou2O0gHkfgm X-Received: by 2002:a05:6a20:a8a4:b0:d5:c0dc:6440 with SMTP id ca36-20020a056a20a8a400b000d5c0dc6440mr385058pzb.29.1678796031783; Tue, 14 Mar 2023 05:13:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678796031; cv=none; d=google.com; s=arc-20160816; b=WPKgdFzGyWujTE9/ut65qaLD+0x5YZH8W7fyYb0HIwA10vl/O8vLCeXvjUP0ef2xPB Tu8WhPcmx6E1PIWX1lMvHOdaYsqlTPQ+N7ArDSLzpf1F7sFwzyKwdmh0/A6E+lNTyvX4 HLJcyDnBmT4yDSrEpizwU6n5thcpC6kyxtSK7++WUh0pTpAfkS0q04yYkJtq+VPbBllx vXc9UvT6k6wuaehjA3k4mUSYqzvgKiEGSvpXnF+CtY1SKrKtCrYveGwEuPwYtXATpyAH a22ABCa3yhBBEEPwaJFDttUP/CdbIJBKcyP5Hr0sgvd7s5edenxeeIq+VQQAbYeeHuHw Km4Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=FuuIJz7b+r/3tvO7KloWUCDRPlQQamJpoTHl/xJ5evA=; b=M2Ah7dArkIUFRgqZtMgWyc8ic+06mE7y0hwFa/MkYDaIOAfwa22Jeih290pjCYiY+X vU6vezqg5sNu8fjf00tCcFtVimwqAqRPPgzBiJeZSL6WKPHdcZ3hTMFssjnQtzEIFQQp DyZoHQi0XNDXQRa8m+IY53G+hRzORcCtLvzJR7RUfg/Nx9l7t+s6SH3kG4yH21eDzscC 20VqlzDBvsn2H1gVquzW0yQVLTkDuajxxWb36MqHEHWnrU8z1yi8wFPLZESjxxOFwAEd NWXBVcPUqK7il5WrBs+NgmKaL6zCxsWcp3Nel5tcUFl3yShtO/3HUwSIhWx5TyWcHlUB i0hw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=zFL2Arda; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w29-20020a63161d000000b00507766aea63si2069374pgl.864.2023.03.14.05.13.36; Tue, 14 Mar 2023 05:13:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=zFL2Arda; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231645AbjCNL4X (ORCPT + 99 others); Tue, 14 Mar 2023 07:56:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231569AbjCNL4P (ORCPT ); Tue, 14 Mar 2023 07:56:15 -0400 Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E5C99FBEE; Tue, 14 Mar 2023 04:55:57 -0700 (PDT) Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtQWW051512; Tue, 14 Mar 2023 06:55:26 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1678794926; bh=FuuIJz7b+r/3tvO7KloWUCDRPlQQamJpoTHl/xJ5evA=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=zFL2ArdawyK+w1qNzX1smmEj2bfDmrXEvwbeK+ojpqYa1iH9bVzXtoxngR6XZZIeD Sm8yg9SLrTrxXAbj/YmWNGmp/fctXvfGfDVxfpCMpV5srGnNn50U/Kyofly82FQ1Ub UNh+HQXAVmRHYI27VEjaIuOx9SNAgOOkV0bh0zOA= Received: from DFLE113.ent.ti.com (dfle113.ent.ti.com [10.64.6.34]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 32EBtQbe003003 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 14 Mar 2023 06:55:26 -0500 Received: from DFLE114.ent.ti.com (10.64.6.35) by DFLE113.ent.ti.com (10.64.6.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Tue, 14 Mar 2023 06:55:26 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE114.ent.ti.com (10.64.6.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Tue, 14 Mar 2023 06:55:26 -0500 Received: from localhost (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtPOs002336; Tue, 14 Mar 2023 06:55:25 -0500 From: Vaishnav Achath To: , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v7 04/13] media: cadence: csi2rx: Add external DPHY support Date: Tue, 14 Mar 2023 17:25:07 +0530 Message-ID: <20230314115516.667-5-vaishnav.a@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314115516.667-1-vaishnav.a@ti.com> References: <20230314115516.667-1-vaishnav.a@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760345227780284861?= X-GMAIL-MSGID: =?utf-8?q?1760345227780284861?= From: Pratyush Yadav Some platforms like TI's J721E can have the CSI2RX paired with an external DPHY. Add support to enable and configure the DPHY using the generic PHY framework. Signed-off-by: Pratyush Yadav Signed-off-by: Vaishnav Achath Reviewed-by: Laurent Pinchart --- Changes in v7: - Fix multiplier and divider in v4l2_get_link_freq() which caused failures during streaming. Changes in v6: - Drop variable bpp and use fmt->bpp directly. - Drop variable got_pm. Call phy_pm_runtime_put() unconditionally since it will just return an error if runtime PM is not enabled. - Add Laurent's R-by. Changes in v5: - Only error out when phy_pm_runtime_get_sync() returns a negative value. A positive value can be returned if the phy was already resumed. - Do not query the source subdev for format. Use the newly added internal format instead. Changes in v4: - Drop the call to set PHY submode. It is now being done via compatible on the DPHY side. Changes in v3: - Use v4l2_get_link_freq() to calculate pixel clock. Changes in v2: - Use phy_pm_runtime_get_sync() and phy_pm_runtime_put() before making calls to set PHY mode, etc. to make sure it is ready. drivers/media/platform/cadence/cdns-csi2rx.c | 90 +++++++++++++++++--- 1 file changed, 80 insertions(+), 10 deletions(-) diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c index ae3ebdb3890d..6933626adfc8 100644 --- a/drivers/media/platform/cadence/cdns-csi2rx.c +++ b/drivers/media/platform/cadence/cdns-csi2rx.c @@ -30,6 +30,12 @@ #define CSI2RX_STATIC_CFG_DLANE_MAP(llane, plane) ((plane) << (16 + (llane) * 4)) #define CSI2RX_STATIC_CFG_LANES_MASK GENMASK(11, 8) +#define CSI2RX_DPHY_LANE_CTRL_REG 0x40 +#define CSI2RX_DPHY_CL_RST BIT(16) +#define CSI2RX_DPHY_DL_RST(i) BIT((i) + 12) +#define CSI2RX_DPHY_CL_EN BIT(4) +#define CSI2RX_DPHY_DL_EN(i) BIT(i) + #define CSI2RX_STREAM_BASE(n) (((n) + 1) * 0x100) #define CSI2RX_STREAM_CTRL_REG(n) (CSI2RX_STREAM_BASE(n) + 0x000) @@ -137,6 +143,49 @@ static void csi2rx_reset(struct csi2rx_priv *csi2rx) writel(0, csi2rx->base + CSI2RX_SOFT_RESET_REG); } +static int csi2rx_configure_external_dphy(struct csi2rx_priv *csi2rx) +{ + union phy_configure_opts opts = { }; + struct phy_configure_opts_mipi_dphy *cfg = &opts.mipi_dphy; + const struct csi2rx_fmt *fmt; + s64 pixel_clock; + int ret; + + fmt = csi2rx_get_fmt_by_code(csi2rx->fmt.code); + + /* + * Do not divide by the number of lanes here. That will be done by + * phy_mipi_dphy_get_default_config(). + */ + pixel_clock = v4l2_get_link_freq(csi2rx->source_subdev->ctrl_handler, + fmt->bpp, 2 * csi2rx->num_lanes); + if (pixel_clock < 0) + return pixel_clock; + + ret = phy_mipi_dphy_get_default_config(pixel_clock, 1, 1, cfg); + if (ret) + return ret; + + ret = phy_pm_runtime_get_sync(csi2rx->dphy); + if (ret < 0 && ret != -ENOTSUPP) + return ret; + + ret = phy_power_on(csi2rx->dphy); + if (ret) + goto out; + + ret = phy_configure(csi2rx->dphy, &opts); + if (ret) { + /* Can't do anything if it fails. Ignore the return value. */ + phy_power_off(csi2rx->dphy); + goto out; + } + +out: + phy_pm_runtime_put(csi2rx->dphy); + return ret; +} + static int csi2rx_start(struct csi2rx_priv *csi2rx) { unsigned int i; @@ -175,6 +224,17 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx) if (ret) goto err_disable_pclk; + /* Enable DPHY clk and data lanes. */ + if (csi2rx->dphy) { + reg = CSI2RX_DPHY_CL_EN | CSI2RX_DPHY_CL_RST; + for (i = 0; i < csi2rx->num_lanes; i++) { + reg |= CSI2RX_DPHY_DL_EN(csi2rx->lanes[i] - 1); + reg |= CSI2RX_DPHY_DL_RST(csi2rx->lanes[i] - 1); + } + + writel(reg, csi2rx->base + CSI2RX_DPHY_LANE_CTRL_REG); + } + /* * Create a static mapping between the CSI virtual channels * and the output stream. @@ -205,10 +265,21 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx) if (ret) goto err_disable_pixclk; + if (csi2rx->dphy) { + ret = csi2rx_configure_external_dphy(csi2rx); + if (ret) { + dev_err(csi2rx->dev, + "Failed to configure external DPHY: %d\n", ret); + goto err_disable_sysclk; + } + } + clk_disable_unprepare(csi2rx->p_clk); return 0; +err_disable_sysclk: + clk_disable_unprepare(csi2rx->sys_clk); err_disable_pixclk: for (; i > 0; i--) clk_disable_unprepare(csi2rx->pixel_clk[i - 1]); @@ -236,6 +307,13 @@ static void csi2rx_stop(struct csi2rx_priv *csi2rx) if (v4l2_subdev_call(csi2rx->source_subdev, video, s_stream, false)) dev_warn(csi2rx->dev, "Couldn't disable our subdev\n"); + + if (csi2rx->dphy) { + writel(0, csi2rx->base + CSI2RX_DPHY_LANE_CTRL_REG); + + if (phy_power_off(csi2rx->dphy)) + dev_warn(csi2rx->dev, "Couldn't power off DPHY\n"); + } } static int csi2rx_s_stream(struct v4l2_subdev *subdev, int enable) @@ -432,15 +510,6 @@ static int csi2rx_get_resources(struct csi2rx_priv *csi2rx, return PTR_ERR(csi2rx->dphy); } - /* - * FIXME: Once we'll have external D-PHY support, the check - * will need to be removed. - */ - if (csi2rx->dphy) { - dev_err(&pdev->dev, "External D-PHY not supported yet\n"); - return -EINVAL; - } - ret = clk_prepare_enable(csi2rx->p_clk); if (ret) { dev_err(&pdev->dev, "Couldn't prepare and enable P clock\n"); @@ -470,7 +539,7 @@ static int csi2rx_get_resources(struct csi2rx_priv *csi2rx, * FIXME: Once we'll have internal D-PHY support, the check * will need to be removed. */ - if (csi2rx->has_internal_dphy) { + if (!csi2rx->dphy && csi2rx->has_internal_dphy) { dev_err(&pdev->dev, "Internal D-PHY not supported yet\n"); return -EINVAL; } @@ -595,6 +664,7 @@ static int csi2rx_probe(struct platform_device *pdev) dev_info(&pdev->dev, "Probed CSI2RX with %u/%u lanes, %u streams, %s D-PHY\n", csi2rx->num_lanes, csi2rx->max_lanes, csi2rx->max_streams, + csi2rx->dphy ? "external" : csi2rx->has_internal_dphy ? "internal" : "no"); return 0; From patchwork Tue Mar 14 11:55:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaishnav Achath X-Patchwork-Id: 69551 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1720685wrd; Tue, 14 Mar 2023 05:15:49 -0700 (PDT) X-Google-Smtp-Source: AK7set+0oRjrcoVbVIW/jtTjG65KhC6WgrXktlp/BEGCeZ9bQoLGUSlqRTPfXUCgzJ2FDyJGKQ4B X-Received: by 2002:a17:903:1251:b0:19e:d60a:e9e with SMTP id u17-20020a170903125100b0019ed60a0e9emr29349805plh.42.1678796149180; Tue, 14 Mar 2023 05:15:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678796149; cv=none; d=google.com; s=arc-20160816; b=yJ7ldUR1+JPuaaVgG1DttuyDnuoqm7l3YE0lgNWhJs1DLzSXWFTxR0Syvj2E7I16gF PzX9K0CoffIzA7BJFZt0ghuHdlhYYgkJOt1E/I6uda1211D+siRF9WrcpUKfjj6GyFZq AWUOSwd34gv7cTwduIyt5+S2CD4M6AidSTHYyhwki0m6tVRSlei3rbCakQy/RAgEloT8 wyacTuIMQUV0ovBkSFgdFz+OFBHU3pPt5fmVMLDi9HlAgRDcVOXeb58Iuh1bzI6QIAbr fD+r5cVVmEz39eqEf8Zab33s4DTBxyLdUQo+F/SPtyAWhTf6uyEZgurD5lpf6yHzUXKV EL4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=O4xsDatyGPKQX0onRSd0fgi9UJM7fBoDvmCijQM4SEw=; b=IqkE3+UjMZ+VZIiw1pTtZ4F6ONxdCxsDIEYZtIkNvtw2AxRGA++gTtzW2mWae4PPj3 dHjVEriBRX5mCTSaPP3Rkz7oizbwB+UXrWajAfrDGdK46ww2+Zxi9MrFeEmkKa1e4sFV OjZnxC+yjrqqMO/7OdxsygWNIGfQmlHpdwz1IdOQivKmKwH1jGRnt8QbCFNPmshLQBNm OR7l016lv0/3K/9NejEWSyhvgqRrVa/+T15CQEZ6lHD3/GkW/ed+2fNGOuWyQsVJYVUG PahfgYeq5rH+pqG+WQ9/40nrtkPDOj//XiLNCggwps45kaHnB5Q5BmRd2n6rOhEl04oT w3pA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=HOaKGRpr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lh4-20020a170903290400b0019ea9a23140si2309463plb.309.2023.03.14.05.15.35; Tue, 14 Mar 2023 05:15:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=HOaKGRpr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231531AbjCNLzr (ORCPT + 99 others); Tue, 14 Mar 2023 07:55:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229735AbjCNLzp (ORCPT ); Tue, 14 Mar 2023 07:55:45 -0400 Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9926382A99; Tue, 14 Mar 2023 04:55:44 -0700 (PDT) Received: from fllv0034.itg.ti.com ([10.64.40.246]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtT4n056385; Tue, 14 Mar 2023 06:55:29 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1678794929; bh=O4xsDatyGPKQX0onRSd0fgi9UJM7fBoDvmCijQM4SEw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=HOaKGRprFKhOYXhPxc/z+dr3IyNBFaRLPVBKEM5MMs0flh/F2CHNz8kLPK6qYaYCF PGmcltUmucXdeCHj1pBrLJg3H2Torba/ZxxvLs4ZEvMuV38k05gcTzEBjtfJxh13sI UAuKY01eUEA7wDyZsC4AYVbXB3cLr0HmzTTM1a6U= Received: from DLEE103.ent.ti.com (dlee103.ent.ti.com [157.170.170.33]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 32EBtSGJ003014 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 14 Mar 2023 06:55:28 -0500 Received: from DLEE102.ent.ti.com (157.170.170.32) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Tue, 14 Mar 2023 06:55:28 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE102.ent.ti.com (157.170.170.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Tue, 14 Mar 2023 06:55:28 -0500 Received: from localhost (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtRfF057265; Tue, 14 Mar 2023 06:55:27 -0500 From: Vaishnav Achath To: , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v7 05/13] media: cadence: csi2rx: Soft reset the streams before starting capture Date: Tue, 14 Mar 2023 17:25:08 +0530 Message-ID: <20230314115516.667-6-vaishnav.a@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314115516.667-1-vaishnav.a@ti.com> References: <20230314115516.667-1-vaishnav.a@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760345350806368525?= X-GMAIL-MSGID: =?utf-8?q?1760345350806368525?= From: Pratyush Yadav This resets the stream state machines and FIFOs, giving them a clean slate. On J721E if the streams are not reset before starting the capture, the captured frame gets wrapped around vertically on every run after the first. Signed-off-by: Pratyush Yadav Signed-off-by: Vaishnav Achath Reviewed-by: Laurent Pinchart --- (no changes since v5) Changes in v5: - Make i unsigned. - Add Laurent's R-by. drivers/media/platform/cadence/cdns-csi2rx.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c index 6933626adfc8..8ecd889690b7 100644 --- a/drivers/media/platform/cadence/cdns-csi2rx.c +++ b/drivers/media/platform/cadence/cdns-csi2rx.c @@ -39,6 +39,7 @@ #define CSI2RX_STREAM_BASE(n) (((n) + 1) * 0x100) #define CSI2RX_STREAM_CTRL_REG(n) (CSI2RX_STREAM_BASE(n) + 0x000) +#define CSI2RX_STREAM_CTRL_SOFT_RST BIT(4) #define CSI2RX_STREAM_CTRL_START BIT(0) #define CSI2RX_STREAM_DATA_CFG_REG(n) (CSI2RX_STREAM_BASE(n) + 0x008) @@ -135,12 +136,22 @@ struct csi2rx_priv *v4l2_subdev_to_csi2rx(struct v4l2_subdev *subdev) static void csi2rx_reset(struct csi2rx_priv *csi2rx) { + unsigned int i; + writel(CSI2RX_SOFT_RESET_PROTOCOL | CSI2RX_SOFT_RESET_FRONT, csi2rx->base + CSI2RX_SOFT_RESET_REG); udelay(10); writel(0, csi2rx->base + CSI2RX_SOFT_RESET_REG); + + /* Reset individual streams. */ + for (i = 0; i < csi2rx->max_streams; i++) { + writel(CSI2RX_STREAM_CTRL_SOFT_RST, + csi2rx->base + CSI2RX_STREAM_CTRL_REG(i)); + usleep_range(10, 20); + writel(0, csi2rx->base + CSI2RX_STREAM_CTRL_REG(i)); + } } static int csi2rx_configure_external_dphy(struct csi2rx_priv *csi2rx) From patchwork Tue Mar 14 11:55:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaishnav Achath X-Patchwork-Id: 69525 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1715001wrd; Tue, 14 Mar 2023 05:05:29 -0700 (PDT) X-Google-Smtp-Source: AK7set/HqB4PusiBfL2mzqGK+hjHQlDMGZLVuc2GH1H3o+SIBXslnN+AkAf0lBe1oIKfD10LYJGN X-Received: by 2002:a05:6a20:918c:b0:d3:3e9b:4907 with SMTP id v12-20020a056a20918c00b000d33e9b4907mr13268870pzd.39.1678795529125; Tue, 14 Mar 2023 05:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678795529; cv=none; d=google.com; s=arc-20160816; b=AxN/yJlV+K3Pe0Nta0kBeXkEyvMFjoMM1T6ZkwnzcsoWUHUZEJYy2d0RqvhBuMNoeA 6BvbE8ld1rzEQUSg5zdAUSIeTnO6JuSSg/4uMUIFOfbneIe496lXqZIyzrHKkBhUIG7e R0fFTgag5jHkow2Ps3nO50aKwTD0RJ3ybxM1QTU1mCQKxrxFyFqt/NO3+FmxWTrdtaMe SIMew/vKhHUk+HPlbHEY916rT+w3jBwi2lm6PvycPJ9UtdRnhZ+8AB6j2kng0ATHov55 7if5QpgDMjh6BsPcgnBUeOC1AYbQ1yAJ7/T3qKGosIPJuY/m6Rn+2+EeEjZRO/LyTNFS lgOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=JGSN//92xgAzRXhFvRWWriqMgsTJzBHHxKA2Y6028FI=; b=RibfM/40qP0dOyq7KOPxJs8KokfwynMP2hzZcDX4AsFsggJgzVPO3fZpWaeWtn97pW CVqAr4zB5AmJ9UetlhqPyg9UeY4XeU8N0ctP/i//olnkO2Is9uZRY5S/m4R6YWIiBg0F KI+Yo9RjgfcJ4eTaMDhwGl2ramgIYb+67lJJDKEDiYz5eJIhEuhK/k7vdp+Z2SbtRHFt 4LJjptbCzPyfi8udyDYCeMaFu8VSioVZBMLQGhPF3T4XiLpV7UcanmrljH9PZUnn0VwA drytYTU5Y2YfVvH7AkJUpTOd8+xqBvUKZlNHLf0xO6CUhdTa3pLHSA7OE2IWnb9A5aC/ npNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="XNi/HoXE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t6-20020aa79466000000b005a8b3c6b5c1si1994375pfq.245.2023.03.14.05.05.14; Tue, 14 Mar 2023 05:05:29 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="XNi/HoXE"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231550AbjCNLzt (ORCPT + 99 others); Tue, 14 Mar 2023 07:55:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231520AbjCNLzr (ORCPT ); Tue, 14 Mar 2023 07:55:47 -0400 Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 048CF86DF3; Tue, 14 Mar 2023 04:55:45 -0700 (PDT) Received: from lelv0265.itg.ti.com ([10.180.67.224]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtULE105814; Tue, 14 Mar 2023 06:55:30 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1678794930; bh=JGSN//92xgAzRXhFvRWWriqMgsTJzBHHxKA2Y6028FI=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=XNi/HoXEnzqQaQ77lAH5e76/8fMAZvFDq+/0IGnWvj7q6YXHToRfzmcCrkvJnqlhB 3fMfM6tMNDao4N5XLEjKPaoIcNTY1P/LSsuJnYXeO1xHhJQldkLL4tD6/MrC+NKrBe ox9/jcf/ArwkZpNl/4vv2+P/J331OQNa0tU13Gf4= Received: from DFLE109.ent.ti.com (dfle109.ent.ti.com [10.64.6.30]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 32EBtUT3003074 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 14 Mar 2023 06:55:30 -0500 Received: from DFLE104.ent.ti.com (10.64.6.25) by DFLE109.ent.ti.com (10.64.6.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Tue, 14 Mar 2023 06:55:30 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Tue, 14 Mar 2023 06:55:30 -0500 Received: from localhost (ileaxei01-snat.itg.ti.com [10.180.69.5]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtTgY111843; Tue, 14 Mar 2023 06:55:29 -0500 From: Vaishnav Achath To: , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v7 06/13] media: cadence: csi2rx: Set the STOP bit when stopping a stream Date: Tue, 14 Mar 2023 17:25:09 +0530 Message-ID: <20230314115516.667-7-vaishnav.a@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314115516.667-1-vaishnav.a@ti.com> References: <20230314115516.667-1-vaishnav.a@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760344700565746652?= X-GMAIL-MSGID: =?utf-8?q?1760344700565746652?= From: Pratyush Yadav The stream stop procedure says that the STOP bit should be set when the stream is to be stopped, and then the ready bit in stream status register polled to make sure the STOP operation is finished. Signed-off-by: Pratyush Yadav Signed-off-by: Vaishnav Achath Reviewed-by: Laurent Pinchart --- (no changes since v5) Changes in v5: - Change %d to %u - Add Laurent's R-by. drivers/media/platform/cadence/cdns-csi2rx.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c index 8ecd889690b7..e80220840e93 100644 --- a/drivers/media/platform/cadence/cdns-csi2rx.c +++ b/drivers/media/platform/cadence/cdns-csi2rx.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -40,8 +41,12 @@ #define CSI2RX_STREAM_CTRL_REG(n) (CSI2RX_STREAM_BASE(n) + 0x000) #define CSI2RX_STREAM_CTRL_SOFT_RST BIT(4) +#define CSI2RX_STREAM_CTRL_STOP BIT(1) #define CSI2RX_STREAM_CTRL_START BIT(0) +#define CSI2RX_STREAM_STATUS_REG(n) (CSI2RX_STREAM_BASE(n) + 0x004) +#define CSI2RX_STREAM_STATUS_RDY BIT(31) + #define CSI2RX_STREAM_DATA_CFG_REG(n) (CSI2RX_STREAM_BASE(n) + 0x008) #define CSI2RX_STREAM_DATA_CFG_EN_VC_SELECT BIT(31) #define CSI2RX_STREAM_DATA_CFG_VC_SELECT(n) BIT((n) + 16) @@ -304,12 +309,23 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx) static void csi2rx_stop(struct csi2rx_priv *csi2rx) { unsigned int i; + u32 val; + int ret; clk_prepare_enable(csi2rx->p_clk); clk_disable_unprepare(csi2rx->sys_clk); for (i = 0; i < csi2rx->max_streams; i++) { - writel(0, csi2rx->base + CSI2RX_STREAM_CTRL_REG(i)); + writel(CSI2RX_STREAM_CTRL_STOP, + csi2rx->base + CSI2RX_STREAM_CTRL_REG(i)); + + ret = readl_relaxed_poll_timeout(csi2rx->base + + CSI2RX_STREAM_STATUS_REG(i), + val, + (val & CSI2RX_STREAM_STATUS_RDY), + 10, 10000); + if (ret) + dev_warn(csi2rx->dev, "Failed to stop stream%u\n", i); clk_disable_unprepare(csi2rx->pixel_clk[i]); } From patchwork Tue Mar 14 11:55:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaishnav Achath X-Patchwork-Id: 69537 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1719145wrd; Tue, 14 Mar 2023 05:12:54 -0700 (PDT) X-Google-Smtp-Source: AK7set/lDXTwPuaVR8+ne9sGPIX3zNAt5HF7CfBrN08mCnSxZBGHPayHWI1yszd+jxDPZKIY9cvs X-Received: by 2002:a05:6a20:3d03:b0:d5:58df:fb80 with SMTP id y3-20020a056a203d0300b000d558dffb80mr2903606pzi.62.1678795974412; Tue, 14 Mar 2023 05:12:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678795974; cv=none; d=google.com; s=arc-20160816; b=Avyv+YCT6KqmXfTiOb5aC9/gXRs8Gl1wv02TAoByR/qEgG4IH84RHIEfpTJVxc37nm 1A85El4bQPmGuWVysfHQsqgknyeciXxL2AFhj+/cjVmM5DLWatYN2NsUdG6UTXqlAmqs fmwgUO74mi3zADM6YJlh5nsV8RKo1axPciHep6v6oj2X/yr6Amc7evGiFXKCG9+lZPXk wPzX6+cORspcOLyhIACqgOk1ffJYxXw8qq3uI+2WASCqsG2IhhyNvVYvR9aJY6hrGrLH v5SkzHKxURwJ66Xt7jFSnf4mFAm5ha9G+yM0Wxstbu7I8yq5YS6yOF+5263ciKWiztz1 GOXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=kdF/1Nr7CR+dcXyDeXuh/C6QNDhPFPgYOllESZB4OZ4=; b=fWcnGX0wIbW836CBOZSl5Cp45isvJfrNDx7zQK+L/DH4h7EVNrMuShNvn2GoITGKPV acDetsMQUlLQKLPxVPVSkWO+MZpdpX32hE7zGYADn4/WXKD0ZF0Jzlbni+utjq1ULgiI ltv+PQp93kkD91i6N8RiLYNeVDIOtOUNkc2o52wpER8bJ9HrThYo2eNGGtfc+gNFlQm0 ydsahm7UlRG6D6Ond9jNTTod0DZXIvFbHWcph1eLUwwzVB+InTP3PoYqw+QVznGIw0eX CsiCjMhplBNIIkJ+vePKTDAXAVezcnIWzS8smR6hLEESR4pT+EtsjiLioSlFZ6XyxeB6 /QcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=DcCSyk8q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y7-20020a623207000000b005a8a1ea9ab9si2034758pfy.370.2023.03.14.05.12.38; Tue, 14 Mar 2023 05:12:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=DcCSyk8q; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231666AbjCNL40 (ORCPT + 99 others); Tue, 14 Mar 2023 07:56:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231624AbjCNL4Q (ORCPT ); Tue, 14 Mar 2023 07:56:16 -0400 Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13D3E9FBF7; Tue, 14 Mar 2023 04:55:58 -0700 (PDT) Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtW4H118702; Tue, 14 Mar 2023 06:55:32 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1678794932; bh=kdF/1Nr7CR+dcXyDeXuh/C6QNDhPFPgYOllESZB4OZ4=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=DcCSyk8qVBfM9unK0eM0tYrgH88ngjb+uA9q0lTeK8E4fPGdLZC2JwH9jQZloMKjq ByWilbPQ5JX5TOFlkOH+1MiQVn2aIMRq36XOI7Bs1egTuBtPXFNaOWG+GSaZhPpLgM ipoOMVZkbwhi3eK1nB70CCLuyGWrYVzgMiRTuorg= Received: from DFLE115.ent.ti.com (dfle115.ent.ti.com [10.64.6.36]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 32EBtWu4003059 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 14 Mar 2023 06:55:32 -0500 Received: from DFLE110.ent.ti.com (10.64.6.31) by DFLE115.ent.ti.com (10.64.6.36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Tue, 14 Mar 2023 06:55:32 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DFLE110.ent.ti.com (10.64.6.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Tue, 14 Mar 2023 06:55:32 -0500 Received: from localhost (ileaxei01-snat.itg.ti.com [10.180.69.5]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtUTP002389; Tue, 14 Mar 2023 06:55:31 -0500 From: Vaishnav Achath To: , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v7 07/13] media: cadence: csi2rx: Fix stream data configuration Date: Tue, 14 Mar 2023 17:25:10 +0530 Message-ID: <20230314115516.667-8-vaishnav.a@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314115516.667-1-vaishnav.a@ti.com> References: <20230314115516.667-1-vaishnav.a@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760345167885748213?= X-GMAIL-MSGID: =?utf-8?q?1760345167885748213?= From: Pratyush Yadav Firstly, there is no VC_EN bit present in the STREAM_DATA_CFG register. Bit 31 is part of the VL_SELECT field. Remove it completely. Secondly, it makes little sense to enable ith virtual channel for ith stream. Sure, there might be a use-case that demands it. But there might also be a use case that demands all streams to use the 0th virtual channel. Prefer this case over the former because it is less arbitrary and also makes it very clear what the limitations of the current driver is instead of giving a false impression that multiple virtual channels are supported. Signed-off-by: Pratyush Yadav Signed-off-by: Vaishnav Achath Reviewed-by: Laurent Pinchart --- (no changes since v1) drivers/media/platform/cadence/cdns-csi2rx.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c index e80220840e93..f8ce9360bfb0 100644 --- a/drivers/media/platform/cadence/cdns-csi2rx.c +++ b/drivers/media/platform/cadence/cdns-csi2rx.c @@ -48,7 +48,6 @@ #define CSI2RX_STREAM_STATUS_RDY BIT(31) #define CSI2RX_STREAM_DATA_CFG_REG(n) (CSI2RX_STREAM_BASE(n) + 0x008) -#define CSI2RX_STREAM_DATA_CFG_EN_VC_SELECT BIT(31) #define CSI2RX_STREAM_DATA_CFG_VC_SELECT(n) BIT((n) + 16) #define CSI2RX_STREAM_CFG_REG(n) (CSI2RX_STREAM_BASE(n) + 0x00c) @@ -269,8 +268,11 @@ static int csi2rx_start(struct csi2rx_priv *csi2rx) writel(CSI2RX_STREAM_CFG_FIFO_MODE_LARGE_BUF, csi2rx->base + CSI2RX_STREAM_CFG_REG(i)); - writel(CSI2RX_STREAM_DATA_CFG_EN_VC_SELECT | - CSI2RX_STREAM_DATA_CFG_VC_SELECT(i), + /* + * Enable one virtual channel. When multiple virtual channels + * are supported this will have to be changed. + */ + writel(CSI2RX_STREAM_DATA_CFG_VC_SELECT(0), csi2rx->base + CSI2RX_STREAM_DATA_CFG_REG(i)); writel(CSI2RX_STREAM_CTRL_START, From patchwork Tue Mar 14 11:55:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaishnav Achath X-Patchwork-Id: 69548 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1720398wrd; Tue, 14 Mar 2023 05:15:19 -0700 (PDT) X-Google-Smtp-Source: AK7set9yOVRCDlFyNZOassqIkfSd32K6NtMB/bake7BuDzSRvuTzY/WR7z9YUwxBCcEr0jwEXWka X-Received: by 2002:a05:6a00:cd:b0:5a8:cbcc:4b58 with SMTP id e13-20020a056a0000cd00b005a8cbcc4b58mr35639126pfj.12.1678796118807; Tue, 14 Mar 2023 05:15:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678796118; cv=none; d=google.com; s=arc-20160816; b=Xo7ImejfM6str6ZIX4xpPcbkCQerXqDB5IFQHYpD28k+9KMpoILL7dIpSjhbMBxvzD Q7zghOhGjtJHH0d3e0mOk8hcSB5PaIL2AqiPTe+HfxTJ8ohar9AqWqU0EmoOGwK88AWm ypao7WcxVmX5yDWSrzACFNIrDvf8ibHp7uTpvLMEg/pXBmqbasmSL7C8qEg6DVIBEoVp T8/NGuw+wv80pIWqeaQCny+QcFNu0drM9Kf/eopvco8ueJDth1MsjpYquMsencgsItDC tNgTpz3G5n4+RoMVM0UyCVPY3tDELPGRtN3Gcd9yWngYkDWtkeEBgwXjLFLXfKqRt2LK VqMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=c6aDqoAsbT1dBhEldNdWqv8Ad1QA4DE50tP0KhQ3cUs=; b=nIUakR2kaTawXnKcLChDcNu2la7P14DAjZHEyjECimlHqvU9yWWnbuun/ejnVuI6gT 1mujKn0tZ4xLubw5Wib78qi6T/iFN+gkSZd/9lk9QBYQsbP6i5t1Bdai4p7kxoajzTxm Obxd0DriniDgH6yvICucHj/6N110X0SbMLxIIZS5w+I/Eh4uDJPqRMcGdmYbCQsmADRF yVS7bH0Ft2FmwvEpNIqiC9wdmSEnPjGmBrpU67G+hQNy/GXlc3nmiSjCQERo84Zx0pb1 uYY9FriABXLey2ndNMSnJ9a99EG7jvmCmQzAUKagQPJLnHzW+COKJa8oclCDoV2HjNFA ncxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=S3lpwN3w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w18-20020aa79552000000b0062578d18ba1si647584pfq.54.2023.03.14.05.15.03; Tue, 14 Mar 2023 05:15:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=S3lpwN3w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231547AbjCNLz7 (ORCPT + 99 others); Tue, 14 Mar 2023 07:55:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44850 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231542AbjCNLzs (ORCPT ); Tue, 14 Mar 2023 07:55:48 -0400 Received: from lelv0143.ext.ti.com (lelv0143.ext.ti.com [198.47.23.248]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EF3482A99; Tue, 14 Mar 2023 04:55:47 -0700 (PDT) Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtYr7118828; Tue, 14 Mar 2023 06:55:34 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1678794934; bh=c6aDqoAsbT1dBhEldNdWqv8Ad1QA4DE50tP0KhQ3cUs=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=S3lpwN3wAtH+EU8Go5ga8V6l61GsmQ/Yxm5FFA3yEKpJvOMcnGuFuqWQ3JNZff1n2 j0B4OlEsoWj+HeXmo2nY5wIuTiQJPNurlXAq38cs2EuhHoDLGwcF245Vk0yF0yjiDO iAVQZR5zXqeTkUWe89jpHxCh52P2oOn9ngPQ4snU= Received: from DLEE104.ent.ti.com (dlee104.ent.ti.com [157.170.170.34]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 32EBtYF7003105 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 14 Mar 2023 06:55:34 -0500 Received: from DLEE100.ent.ti.com (157.170.170.30) by DLEE104.ent.ti.com (157.170.170.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Tue, 14 Mar 2023 06:55:33 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Tue, 14 Mar 2023 06:55:34 -0500 Received: from localhost (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtWES111879; Tue, 14 Mar 2023 06:55:33 -0500 From: Vaishnav Achath To: , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v7 08/13] media: cadence: csi2rx: Populate subdev devnode Date: Tue, 14 Mar 2023 17:25:11 +0530 Message-ID: <20230314115516.667-9-vaishnav.a@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314115516.667-1-vaishnav.a@ti.com> References: <20230314115516.667-1-vaishnav.a@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760345319016290309?= X-GMAIL-MSGID: =?utf-8?q?1760345319016290309?= From: Pratyush Yadav The devnode can be used by media-ctl and other userspace tools to perform configurations on the subdev. Without it, media-ctl returns ENOENT when setting format on the sensor subdev. Signed-off-by: Pratyush Yadav Signed-off-by: Vaishnav Achath Reviewed-by: Laurent Pinchart --- (no changes since v5) Changes in v5: - Add Laurent's R-by. Changes in v2: - New in v2. drivers/media/platform/cadence/cdns-csi2rx.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c index f8ce9360bfb0..639ade97b998 100644 --- a/drivers/media/platform/cadence/cdns-csi2rx.c +++ b/drivers/media/platform/cadence/cdns-csi2rx.c @@ -676,6 +676,7 @@ static int csi2rx_probe(struct platform_device *pdev) csi2rx->pads[CSI2RX_PAD_SINK].flags = MEDIA_PAD_FL_SINK; for (i = CSI2RX_PAD_SOURCE_STREAM0; i < CSI2RX_PAD_MAX; i++) csi2rx->pads[i].flags = MEDIA_PAD_FL_SOURCE; + csi2rx->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; ret = media_entity_pads_init(&csi2rx->subdev.entity, CSI2RX_PAD_MAX, csi2rx->pads); From patchwork Tue Mar 14 11:55:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaishnav Achath X-Patchwork-Id: 69535 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1719015wrd; Tue, 14 Mar 2023 05:12:42 -0700 (PDT) X-Google-Smtp-Source: AK7set9nqBnw4SG9SUP5ga3JMDHoUrSyUYFULM3LEMgZzpHq/gBmy/ZhDrhOnzs/ZqI64hgD/y0t X-Received: by 2002:a05:6e02:e0b:b0:316:b0b2:beff with SMTP id a11-20020a056e020e0b00b00316b0b2beffmr1763237ilk.4.1678795962162; Tue, 14 Mar 2023 05:12:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678795962; cv=none; d=google.com; s=arc-20160816; b=P0yVIo86org1EUM/+qacpFL8azOvt9p8PFcJN0r1Ic4Nu+KVyq3ZLjbgDFQO2EGxqX L6Rkf/s8pG7quVSpMEpK/4Q2QOLgBqjZapitG0fSUab8vReG8EyY1shCHfjG4H92e12G jmRqDiMA0d7jJZIL/p4km7XH75lc6W1ytlsOlNdKMNS9GIZ3r2+yBsF6AFrqfPqPXvX7 dU4udfBHKrtyJvGZiPC37q2nFMsx2Tj2Kuoe2vkJ58MKN6Yjmjzz5F9bLGP1vW8mEo6t qUQL70S1J3riTlaom1deyK7O9Uq6nO/cm68tntxNANZmr2FOpX/v8kxR0IUu6oEg9xnM f/gQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=PSh3JOfebxzHh7OMYrBExmtN8GkKJtYIG5XeSZ5WRJ8=; b=FVTq7LVfJX7UBJ0cAIIgjusksHMPdvPybgYSGS7KajhkWbT72EkOzwiunRzXGmbiq2 +HZwZ9ygPS3A8KqGCj0vjdJLV4zqyjYjbcDP2lNYGCx/dVxu0r5LVlWVBRXHy959blH4 zGOVITzuIZFYKF9Q+A6I3uq7VNo1q089D4+NElvuMXVaeDvcdk8Jnx2jK6MtvO7gaSkT 87fC7puFOxfKS535TDo/3J4/cqq2dV3WID+20/MYWW3UEoIg9YoAiuCA/XU4dcvuOxiC SziWgUY6a+lyH7f3G4j+6mvhOlvGTfvGiK5o3iJUptajiYZINmQhKHX7UNBaEDMYw2+K nQXw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="Su7nFBh/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j18-20020a056e02219200b0031402bfcb5esi2570749ila.3.2023.03.14.05.12.27; Tue, 14 Mar 2023 05:12:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="Su7nFBh/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231715AbjCNL44 (ORCPT + 99 others); Tue, 14 Mar 2023 07:56:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231664AbjCNL40 (ORCPT ); Tue, 14 Mar 2023 07:56:26 -0400 Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22349A02A1; Tue, 14 Mar 2023 04:56:06 -0700 (PDT) Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtaYc051532; Tue, 14 Mar 2023 06:55:36 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1678794936; bh=PSh3JOfebxzHh7OMYrBExmtN8GkKJtYIG5XeSZ5WRJ8=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=Su7nFBh/KSWTs/gEusIwMC03o1mZfShIYEvkjrsIqUp/RVF3zrgz1MBWuLWmkC66u LGWGfjhUFKCVZ9+5nsD6tkY3+iITTccZalS8EqCa4AyvGbYUxmDPZ7ybHw+Mr17jIf IyENeFY2VCjPh5Va+/khHY9e6YdtSZM5yNmJTVtE= Received: from DLEE113.ent.ti.com (dlee113.ent.ti.com [157.170.170.24]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 32EBtaXV003130 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 14 Mar 2023 06:55:36 -0500 Received: from DLEE110.ent.ti.com (157.170.170.21) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Tue, 14 Mar 2023 06:55:36 -0500 Received: from fllv0039.itg.ti.com (10.64.41.19) by DLEE110.ent.ti.com (157.170.170.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Tue, 14 Mar 2023 06:55:35 -0500 Received: from localhost (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by fllv0039.itg.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtYXt072629; Tue, 14 Mar 2023 06:55:35 -0500 From: Vaishnav Achath To: , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v7 09/13] media: cadence: csi2rx: Add link validation Date: Tue, 14 Mar 2023 17:25:12 +0530 Message-ID: <20230314115516.667-10-vaishnav.a@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314115516.667-1-vaishnav.a@ti.com> References: <20230314115516.667-1-vaishnav.a@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760345154512111697?= X-GMAIL-MSGID: =?utf-8?q?1760345154512111697?= From: Pratyush Yadav Add media link validation to make sure incorrectly configured pipelines are caught. Signed-off-by: Pratyush Yadav Signed-off-by: Vaishnav Achath Reviewed-by: Laurent Pinchart --- (no changes since v6) Changes in v6: - Drop transcoding from the commit message. - Make csi2rx_media_ops const. - Add Laurent's R-by. Changes in v5: - New in v5. drivers/media/platform/cadence/cdns-csi2rx.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/media/platform/cadence/cdns-csi2rx.c b/drivers/media/platform/cadence/cdns-csi2rx.c index 639ade97b998..026d95d60654 100644 --- a/drivers/media/platform/cadence/cdns-csi2rx.c +++ b/drivers/media/platform/cadence/cdns-csi2rx.c @@ -478,6 +478,10 @@ static const struct v4l2_subdev_ops csi2rx_subdev_ops = { .pad = &csi2rx_pad_ops, }; +static const struct media_entity_operations csi2rx_media_ops = { + .link_validate = v4l2_subdev_link_validate, +}; + static int csi2rx_async_bound(struct v4l2_async_notifier *notifier, struct v4l2_subdev *s_subdev, struct v4l2_async_subdev *asd) @@ -677,6 +681,7 @@ static int csi2rx_probe(struct platform_device *pdev) for (i = CSI2RX_PAD_SOURCE_STREAM0; i < CSI2RX_PAD_MAX; i++) csi2rx->pads[i].flags = MEDIA_PAD_FL_SOURCE; csi2rx->subdev.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; + csi2rx->subdev.entity.ops = &csi2rx_media_ops; ret = media_entity_pads_init(&csi2rx->subdev.entity, CSI2RX_PAD_MAX, csi2rx->pads); From patchwork Tue Mar 14 11:55:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaishnav Achath X-Patchwork-Id: 69526 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1715239wrd; Tue, 14 Mar 2023 05:05:51 -0700 (PDT) X-Google-Smtp-Source: AK7set/KBCn1QS+yeAQVx9IQeXEZCB0LSaI5YeFVIcpihJz4DAerLgAaMJaBtKO1th+XWxwBUe5T X-Received: by 2002:a05:6a20:549e:b0:d4:faa7:be99 with SMTP id i30-20020a056a20549e00b000d4faa7be99mr3858414pzk.16.1678795551015; Tue, 14 Mar 2023 05:05:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678795550; cv=none; d=google.com; s=arc-20160816; b=IsyeCtiODoL24j7ozDtfNPJmxiMw0VcAXeXBhw9qBD55JX0PqyGItRL1cyZguHC+Kk OZo2KAyqqEgV2GKkKoIMsDPeNhvTZPkt8UDC9if8aEp7otjm6gMNLpG+y27qVK8hfj7Z XlHsM0GwUgykyfTClM13cRWC5J2d/hv7T+2lFCHPjTmfp2Yfj+nw9vra91E+9Pima9oj 9NtegxfNnRjiSLUSO3tYxsUlFIXvBGNb0krLgQgoYAEoXGQANEb+g9/QEGBlj1aYUPyk 0l3uFAa5g98krzlcEXp6PmlmJgAGnY+cgfhhtr0AyLyyh7chixIRyVLzZfQ8xJlXtq3P PBmQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=AJ0juSq3I5SM626nI9JwNqH+xHEcn0u6uTEZg3d/ySk=; b=as9J7F0TLm3ZNU/K+mC+jqDV6JSU6LtMuQLlnEihCrBDqPbKFv2kOjxdcew0iXN4qj tGQwq/kj+CyMiNwbA6r/c2OADW9ZKI63Iwbb92shx9IBKbYEld2ZT+dGYDL9UyWmkYO0 I5YzieU3v4fx7Klms9Fi8zfJRPpyM00BzjLDV1cJTPqZbbdplVeJfJF/2pyoLDE7Iuma 2czpUOyVS+RcI5H3ZBoX8TGoFPtGtAPR8n4m6uVTzuCFt/DwymkSc0RRm/IrQGMnr3j7 AkEpb37DcEmkoXKjGHyNO2LWoy//62NQbLCHBy7zdm7SYT0oW9L2QMwlqvyOSil1UeWF xpHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=f5Umcog4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z189-20020a6365c6000000b0050983bc7c1fsi1970139pgb.788.2023.03.14.05.05.37; Tue, 14 Mar 2023 05:05:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=f5Umcog4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231532AbjCNL4C (ORCPT + 99 others); Tue, 14 Mar 2023 07:56:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231583AbjCNLzz (ORCPT ); Tue, 14 Mar 2023 07:55:55 -0400 Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68EFE98845; Tue, 14 Mar 2023 04:55:49 -0700 (PDT) Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtcT0056408; Tue, 14 Mar 2023 06:55:38 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1678794938; bh=AJ0juSq3I5SM626nI9JwNqH+xHEcn0u6uTEZg3d/ySk=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=f5Umcog4DjxSqsBUZvYY5X3rHPv93BVPvcouLbHGzvFVsxGqvY0yu9Byk0FUnjm5j H9WRDQQs05jjW/158cAXHrUDflYS+8g0NFm1/tFO2bDd9zQV+Nsn8PvxewibSpqNC1 zr0NcSjpVbhUoUPzpEb33gl9CbEjB+S4KfUbFBzM= Received: from DLEE103.ent.ti.com (dlee103.ent.ti.com [157.170.170.33]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 32EBtckf114840 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 14 Mar 2023 06:55:38 -0500 Received: from DLEE113.ent.ti.com (157.170.170.24) by DLEE103.ent.ti.com (157.170.170.33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Tue, 14 Mar 2023 06:55:37 -0500 Received: from lelv0327.itg.ti.com (10.180.67.183) by DLEE113.ent.ti.com (157.170.170.24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Tue, 14 Mar 2023 06:55:37 -0500 Received: from localhost (ileaxei01-snat.itg.ti.com [10.180.69.5]) by lelv0327.itg.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtaeo111910; Tue, 14 Mar 2023 06:55:37 -0500 From: Vaishnav Achath To: , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v7 10/13] media: ti: Add CSI2RX support for J721E Date: Tue, 14 Mar 2023 17:25:13 +0530 Message-ID: <20230314115516.667-11-vaishnav.a@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314115516.667-1-vaishnav.a@ti.com> References: <20230314115516.667-1-vaishnav.a@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760344723567671505?= X-GMAIL-MSGID: =?utf-8?q?1760344723567671505?= From: Pratyush Yadav TI's J721E uses the Cadence CSI2RX and DPHY peripherals to facilitate capture over a CSI-2 bus. The Cadence CSI2RX IP acts as a bridge between the TI specific parts and the CSI-2 protocol parts. TI then has a wrapper on top of this bridge called the SHIM layer. It takes in data from stream 0, repacks it, and sends it to memory over PSI-L DMA. This driver acts as the "front end" to V4L2 client applications. It implements the required ioctls and buffer operations, passes the necessary calls on to the bridge, programs the SHIM layer, and performs DMA via the dmaengine API to finally return the data to a buffer supplied by the application. Signed-off-by: Pratyush Yadav Signed-off-by: Jai Luthra Signed-off-by: Vaishnav Achath --- Changes in v7: - Fix incorrect value written in SHIM_PSI_CFG0_DST_TAG - Drop support for 2X8 formats. - Update maintainer to Vaishnav as Pratyush moved out of TI. - Address Sakari's review comments: - Update MAX_HEIGHT_LINES, MAX_WIDTH_BYTES to prevent overflow. - Assign dma_slave_config during declaration, drop memset(). - dma_release_channel() on slave_config failure. - provide entity ops for the vdev entity with link_validate(). - mutex_destroy() on ti_csi2rx_probe failure path. - Drop busy check in remove(). - mutex_destroy() in ti_csi2rx_remove(). - Address Laurent's review comments: - Update entries in Makefile in alphabetical order. - include headers in alphabetical order. - Drop redundant CSI DT defines and use from media/mipi-csi2.h. - Rename csi_df to csi_dt. - Drop v4l2_colorspace from ti_csi2rx_fmt and set default in ti_csi2rx_v4l2_init() - Adjust field and not return EINVAL in ti_csi2rx_try_fmt_vid_cap(). - inline ti_csi2rx_video_register(). - start DMA before starting source subdev. - move buffer cleanup to separate function ti_csi2rx_cleanup_buffers() to be used in ti_csi2rx_stop_streaming() and ti_csi2rx_start_streaming() failure path. - Drop VB2_USERPTR, VB2_READ and V4L2_CAP_READWRITE. Changes in v5: - Add dependency on PHY_CADENCE_DPHY_RX instead of PHY_CADENCE_DPHY since the Rx mode DPHY now has a separate driver. - Drop ti_csi2rx_validate_pipeline(). Pipeline validation should be done at media_pipeline_start(). - Do not assign flags. - Fix error handling in ti_csi2rx_start_streaming(). Free up vb2 buffers when media_pipeline_start() fails. Changes in v4: - Acquire the media device's graph_mutex before starting the graph walk. - Call media_graph_walk_init() and media_graph_walk_cleanup() when starting and ending the graph walk respectively. - Reduce max frame height and width in enum_framesizes. Currently they are set to UINT_MAX but they must be a multiple of step_width, so they need to be rounded down. Also, these values are absurdly large which causes some userspace applications like gstreamer to trip up. While it is not generally right to change the kernel for an application bug, it is not such a big deal here. This change is replacing one set of absurdly large arbitrary values with another set of smaller but still absurdly large arbitrary values. Both limits are unlikely to be hit in practice. Changes in v3: - Move DMA related fields in struct ti_csi2rx_dma. - Protect DMA buffer queue with a spinlock to make sure the queue buffer and DMA callback don't race on it. - Track the current DMA state. It might go idle because of a lack of buffers. This state can be used to restart it if needed. - Do not include the current buffer in the pending queue. It is slightly better modelling than leaving it at the head of the pending queue. - Use the buffer as the callback argument, and add a reference to csi in it. - If queueing a buffer to DMA fails, the buffer gets leaked and DMA gets stalled with. Instead, report the error to vb2 and queue the next buffer in the pending queue. - DMA gets stalled if we run out of buffers since the callback is the only one that fires subsequent transfers and it is no longer being called. Check for that when queueing buffers and restart DMA if needed. - Do not put of node until we are done using the fwnode. - Set inital format to UYVY 640x480. Changes in v2: - Use dmaengine_get_dma_device() instead of directly accessing dma->device->dev. - Do not set dst_addr_width when configuring slave DMA. - Move to a separate subdir and rename to j721e-csi2rx.c - Convert compatible to ti,j721e-csi2rx. - Move to use Media Controller centric APIs. - Improve cleanup in probe when one of the steps fails. - Add colorspace to formats database. - Set hw_revision on media_device. - Move video device initialization to probe time instead of register time. MAINTAINERS | 6 + drivers/media/platform/ti/Kconfig | 12 + drivers/media/platform/ti/Makefile | 1 + .../media/platform/ti/j721e-csi2rx/Makefile | 2 + .../platform/ti/j721e-csi2rx/j721e-csi2rx.c | 1022 +++++++++++++++++ 5 files changed, 1043 insertions(+) create mode 100644 drivers/media/platform/ti/j721e-csi2rx/Makefile create mode 100644 drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c diff --git a/MAINTAINERS b/MAINTAINERS index 2892858cb040..69c2b0f48073 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20901,6 +20901,12 @@ S: Odd Fixes F: drivers/clk/ti/ F: include/linux/clk/ti.h +TI J721E CSI2RX DRIVER +M: Vaishnav Achath +L: linux-media@vger.kernel.org +S: Supported +F: drivers/media/platform/ti/j721e-csi2rx/ + TI DAVINCI MACHINE SUPPORT M: Bartosz Golaszewski L: linux-arm-kernel@lists.infradead.org (moderated for non-subscribers) diff --git a/drivers/media/platform/ti/Kconfig b/drivers/media/platform/ti/Kconfig index e1ab56c3be1f..42c908f6e1ae 100644 --- a/drivers/media/platform/ti/Kconfig +++ b/drivers/media/platform/ti/Kconfig @@ -63,6 +63,18 @@ config VIDEO_TI_VPE_DEBUG help Enable debug messages on VPE driver. +config VIDEO_TI_J721E_CSI2RX + tristate "TI J721E CSI2RX wrapper layer driver" + depends on VIDEO_DEV && VIDEO_V4L2_SUBDEV_API + depends on MEDIA_SUPPORT && MEDIA_CONTROLLER + depends on PHY_CADENCE_DPHY_RX && VIDEO_CADENCE_CSI2RX + depends on ARCH_K3 || COMPILE_TEST + select VIDEOBUF2_DMA_CONTIG + select V4L2_FWNODE + help + Support for TI CSI2RX wrapper layer. This just enables the wrapper driver. + The Cadence CSI2RX bridge driver needs to be enabled separately. + source "drivers/media/platform/ti/am437x/Kconfig" source "drivers/media/platform/ti/davinci/Kconfig" source "drivers/media/platform/ti/omap/Kconfig" diff --git a/drivers/media/platform/ti/Makefile b/drivers/media/platform/ti/Makefile index 98c5fe5c40d6..8a2f74c9380e 100644 --- a/drivers/media/platform/ti/Makefile +++ b/drivers/media/platform/ti/Makefile @@ -3,5 +3,6 @@ obj-y += am437x/ obj-y += cal/ obj-y += vpe/ obj-y += davinci/ +obj-y += j721e-csi2rx/ obj-y += omap/ obj-y += omap3isp/ diff --git a/drivers/media/platform/ti/j721e-csi2rx/Makefile b/drivers/media/platform/ti/j721e-csi2rx/Makefile new file mode 100644 index 000000000000..377afc1d6280 --- /dev/null +++ b/drivers/media/platform/ti/j721e-csi2rx/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0 +obj-$(CONFIG_VIDEO_TI_J721E_CSI2RX) += j721e-csi2rx.o diff --git a/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c new file mode 100644 index 000000000000..0c8dad049f5b --- /dev/null +++ b/drivers/media/platform/ti/j721e-csi2rx/j721e-csi2rx.c @@ -0,0 +1,1022 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * TI CSI2 RX driver. + * + * Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com/ + * + * Author: Pratyush Yadav + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#define TI_CSI2RX_MODULE_NAME "j721e-csi2rx" + +#define SHIM_CNTL 0x10 +#define SHIM_CNTL_PIX_RST BIT(0) + +#define SHIM_DMACNTX 0x20 +#define SHIM_DMACNTX_EN BIT(31) +#define SHIM_DMACNTX_YUV422 GENMASK(27, 26) +#define SHIM_DMACNTX_FMT GENMASK(5, 0) +#define SHIM_DMACNTX_UYVY 0 +#define SHIM_DMACNTX_VYUY 1 +#define SHIM_DMACNTX_YUYV 2 +#define SHIM_DMACNTX_YVYU 3 + +#define SHIM_PSI_CFG0 0x24 +#define SHIM_PSI_CFG0_SRC_TAG GENMASK(15, 0) +#define SHIM_PSI_CFG0_DST_TAG GENMASK(31, 15) + +#define PSIL_WORD_SIZE_BYTES 16 +/* + * There are no hard limits on the width or height. The DMA engine can handle + * all sizes. The max width and height are arbitrary numbers for this driver. + * Use 16K * 16K as the arbitrary limit. It is large enough that it is unlikely + * the limit will be hit in practice. + */ +#define MAX_WIDTH_BYTES SZ_16K +#define MAX_HEIGHT_LINES SZ_16K + +struct ti_csi2rx_fmt { + u32 fourcc; /* Four character code. */ + u32 code; /* Mbus code. */ + u32 csi_dt; /* CSI Data type. */ + u8 bpp; /* Bits per pixel. */ +}; + +struct ti_csi2rx_buffer { + /* Common v4l2 buffer. Must be first. */ + struct vb2_v4l2_buffer vb; + struct list_head list; + struct ti_csi2rx_dev *csi; +}; + +enum ti_csi2rx_dma_state { + TI_CSI2RX_DMA_STOPPED, /* Streaming not started yet. */ + TI_CSI2RX_DMA_IDLE, /* Streaming but no pending DMA operation. */ + TI_CSI2RX_DMA_ACTIVE, /* Streaming and pending DMA operation. */ +}; + +struct ti_csi2rx_dma { + /* Protects all fields in this struct. */ + spinlock_t lock; + struct dma_chan *chan; + /* Buffers queued to the driver, waiting to be processed by DMA. */ + struct list_head queue; + enum ti_csi2rx_dma_state state; + /* + * Current buffer being processed by DMA. NULL if no buffer is being + * processed. + */ + struct ti_csi2rx_buffer *curr; +}; + +struct ti_csi2rx_dev { + struct device *dev; + void __iomem *shim; + struct v4l2_device v4l2_dev; + struct video_device vdev; + struct media_device mdev; + struct media_pipeline pipe; + struct media_pad pad; + struct v4l2_async_notifier notifier; + struct v4l2_subdev *subdev; + struct vb2_queue vidq; + struct mutex mutex; /* To serialize ioctls. */ + struct v4l2_format v_fmt; + struct ti_csi2rx_dma dma; + u32 sequence; +}; + +static const struct ti_csi2rx_fmt formats[] = { + { + .fourcc = V4L2_PIX_FMT_YUYV, + .code = MEDIA_BUS_FMT_YUYV8_1X16, + .csi_dt = MIPI_CSI2_DT_YUV422_8B, + .bpp = 16, + }, { + .fourcc = V4L2_PIX_FMT_UYVY, + .code = MEDIA_BUS_FMT_UYVY8_1X16, + .csi_dt = MIPI_CSI2_DT_YUV422_8B, + .bpp = 16, + }, { + .fourcc = V4L2_PIX_FMT_YVYU, + .code = MEDIA_BUS_FMT_YVYU8_1X16, + .csi_dt = MIPI_CSI2_DT_YUV422_8B, + .bpp = 16, + }, { + .fourcc = V4L2_PIX_FMT_VYUY, + .code = MEDIA_BUS_FMT_VYUY8_1X16, + .csi_dt = MIPI_CSI2_DT_YUV422_8B, + .bpp = 16, + }, + + /* More formats can be supported but they are not listed for now. */ +}; + +static const unsigned int num_formats = ARRAY_SIZE(formats); + +/* Forward declaration needed by ti_csi2rx_dma_callback. */ +static int ti_csi2rx_start_dma(struct ti_csi2rx_dev *csi, + struct ti_csi2rx_buffer *buf); + +static const struct ti_csi2rx_fmt *find_format_by_pix(u32 pixelformat) +{ + unsigned int i; + + for (i = 0; i < num_formats; i++) { + if (formats[i].fourcc == pixelformat) + return &formats[i]; + } + + return NULL; +} + +static const struct ti_csi2rx_fmt *find_format_by_code(u32 code) +{ + unsigned int i; + + for (i = 0; i < num_formats; i++) { + if (formats[i].code == code) + return &formats[i]; + } + + return NULL; +} + +static void ti_csi2rx_fill_fmt(const struct ti_csi2rx_fmt *csi_fmt, + struct v4l2_format *v4l2_fmt) +{ + struct v4l2_pix_format *pix = &v4l2_fmt->fmt.pix; + unsigned int pixels_in_word; + u8 bpp = csi_fmt->bpp; + u32 bpl; + + /* TODO: Figure this out. */ + + pixels_in_word = PSIL_WORD_SIZE_BYTES * 8 / bpp; + + pix->width = clamp_t(unsigned int, pix->width, + pixels_in_word, + MAX_WIDTH_BYTES * 8 / bpp); + pix->width = rounddown(pix->width, pixels_in_word); + + pix->height = clamp_t(unsigned int, pix->height, 1, MAX_HEIGHT_LINES); + + v4l2_fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + pix->pixelformat = csi_fmt->fourcc; + pix->colorspace = V4L2_COLORSPACE_SRGB; + pix->sizeimage = pix->height * pix->width * (bpp / 8); + + bpl = (pix->width * ALIGN(bpp, 8)) >> 3; + pix->bytesperline = ALIGN(bpl, 16); +} + +static int ti_csi2rx_querycap(struct file *file, void *priv, + struct v4l2_capability *cap) +{ + struct ti_csi2rx_dev *csi = video_drvdata(file); + + strscpy(cap->driver, TI_CSI2RX_MODULE_NAME, sizeof(cap->driver)); + strscpy(cap->card, TI_CSI2RX_MODULE_NAME, sizeof(cap->card)); + + snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", + dev_name(csi->dev)); + + return 0; +} + +static int ti_csi2rx_enum_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_fmtdesc *f) +{ + if (f->index >= num_formats) + return -EINVAL; + + memset(f->reserved, 0, sizeof(f->reserved)); + f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + f->pixelformat = formats[f->index].fourcc; + + return 0; +} + +static int ti_csi2rx_g_fmt_vid_cap(struct file *file, void *prov, + struct v4l2_format *f) +{ + struct ti_csi2rx_dev *csi = video_drvdata(file); + + *f = csi->v_fmt; + + return 0; +} + +static int ti_csi2rx_try_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_format *f) +{ + const struct ti_csi2rx_fmt *fmt; + + /* + * Default to the first format if the requested pixel format code isn't + * supported. + */ + fmt = find_format_by_pix(f->fmt.pix.pixelformat); + if (!fmt) + fmt = &formats[0]; + + if (f->fmt.pix.field == V4L2_FIELD_ANY) + f->fmt.pix.field = V4L2_FIELD_NONE; + + if (f->fmt.pix.field != V4L2_FIELD_NONE) + /* Interlaced formats are not supported. */ + f->fmt.pix.field = V4L2_FIELD_NONE; + + ti_csi2rx_fill_fmt(fmt, f); + + return 0; +} + +static int ti_csi2rx_s_fmt_vid_cap(struct file *file, void *priv, + struct v4l2_format *f) +{ + struct ti_csi2rx_dev *csi = video_drvdata(file); + struct vb2_queue *q = &csi->vidq; + int ret; + + if (vb2_is_busy(q)) + return -EBUSY; + + ret = ti_csi2rx_try_fmt_vid_cap(file, priv, f); + if (ret < 0) + return ret; + + csi->v_fmt = *f; + + return 0; +} + +static int ti_csi2rx_enum_framesizes(struct file *file, void *fh, + struct v4l2_frmsizeenum *fsize) +{ + const struct ti_csi2rx_fmt *fmt; + unsigned int pixels_in_word; + u8 bpp; + + fmt = find_format_by_pix(fsize->pixel_format); + if (!fmt) + return -EINVAL; + + bpp = ALIGN(fmt->bpp, 8); + + /* + * Number of pixels in one PSI-L word. The transfer happens in multiples + * of PSI-L word sizes. + */ + pixels_in_word = PSIL_WORD_SIZE_BYTES * 8 / bpp; + + fsize->type = V4L2_FRMSIZE_TYPE_STEPWISE; + fsize->stepwise.min_width = pixels_in_word; + fsize->stepwise.max_width = rounddown(MAX_WIDTH_BYTES * 8 / bpp, + pixels_in_word); + fsize->stepwise.step_width = pixels_in_word; + fsize->stepwise.min_height = 1; + fsize->stepwise.max_height = MAX_HEIGHT_LINES; + fsize->stepwise.step_height = 1; + + return 0; +} + +static const struct v4l2_ioctl_ops csi_ioctl_ops = { + .vidioc_querycap = ti_csi2rx_querycap, + .vidioc_enum_fmt_vid_cap = ti_csi2rx_enum_fmt_vid_cap, + .vidioc_try_fmt_vid_cap = ti_csi2rx_try_fmt_vid_cap, + .vidioc_g_fmt_vid_cap = ti_csi2rx_g_fmt_vid_cap, + .vidioc_s_fmt_vid_cap = ti_csi2rx_s_fmt_vid_cap, + .vidioc_enum_framesizes = ti_csi2rx_enum_framesizes, + .vidioc_reqbufs = vb2_ioctl_reqbufs, + .vidioc_create_bufs = vb2_ioctl_create_bufs, + .vidioc_prepare_buf = vb2_ioctl_prepare_buf, + .vidioc_querybuf = vb2_ioctl_querybuf, + .vidioc_qbuf = vb2_ioctl_qbuf, + .vidioc_dqbuf = vb2_ioctl_dqbuf, + .vidioc_expbuf = vb2_ioctl_expbuf, + .vidioc_streamon = vb2_ioctl_streamon, + .vidioc_streamoff = vb2_ioctl_streamoff, +}; + +static const struct v4l2_file_operations csi_fops = { + .owner = THIS_MODULE, + .open = v4l2_fh_open, + .release = vb2_fop_release, + .read = vb2_fop_read, + .poll = vb2_fop_poll, + .unlocked_ioctl = video_ioctl2, + .mmap = vb2_fop_mmap, +}; + +static inline int ti_csi2rx_video_register(struct ti_csi2rx_dev *csi) +{ + struct video_device *vdev = &csi->vdev; + int ret, src_pad; + + ret = video_register_device(vdev, VFL_TYPE_VIDEO, -1); + if (ret) + return ret; + + src_pad = media_entity_get_fwnode_pad(&csi->subdev->entity, + csi->subdev->fwnode, + MEDIA_PAD_FL_SOURCE); + if (src_pad < 0) { + dev_err(csi->dev, "Couldn't find source pad for subdev\n"); + return src_pad; + } + + ret = media_create_pad_link(&csi->subdev->entity, src_pad, + &vdev->entity, 0, + MEDIA_LNK_FL_IMMUTABLE | + MEDIA_LNK_FL_ENABLED); + if (ret) { + video_unregister_device(vdev); + return ret; + } + + return 0; +} + +static int csi_async_notifier_bound(struct v4l2_async_notifier *notifier, + struct v4l2_subdev *subdev, + struct v4l2_async_subdev *asd) +{ + struct ti_csi2rx_dev *csi = dev_get_drvdata(notifier->v4l2_dev->dev); + + csi->subdev = subdev; + + return 0; +} + +static int csi_async_notifier_complete(struct v4l2_async_notifier *notifier) +{ + struct ti_csi2rx_dev *csi = dev_get_drvdata(notifier->v4l2_dev->dev); + int ret; + + ret = ti_csi2rx_video_register(csi); + if (ret) + return ret; + + return v4l2_device_register_subdev_nodes(&csi->v4l2_dev); +} + +static const struct v4l2_async_notifier_operations csi_async_notifier_ops = { + .bound = csi_async_notifier_bound, + .complete = csi_async_notifier_complete, +}; + +static int ti_csi2rx_init_subdev(struct ti_csi2rx_dev *csi) +{ + struct fwnode_handle *fwnode; + struct v4l2_async_subdev *asd; + struct device_node *node; + int ret; + + node = of_get_child_by_name(csi->dev->of_node, "csi-bridge"); + if (!node) + return -EINVAL; + + fwnode = of_fwnode_handle(node); + if (!fwnode) { + of_node_put(node); + return -EINVAL; + } + + v4l2_async_nf_init(&csi->notifier); + csi->notifier.ops = &csi_async_notifier_ops; + + asd = v4l2_async_nf_add_fwnode(&csi->notifier, fwnode, + struct v4l2_async_subdev); + of_node_put(node); + if (IS_ERR(asd)) { + v4l2_async_nf_cleanup(&csi->notifier); + return PTR_ERR(asd); + } + + ret = v4l2_async_nf_register(&csi->v4l2_dev, &csi->notifier); + if (ret) { + v4l2_async_nf_cleanup(&csi->notifier); + return ret; + } + + return 0; +} + +static void ti_csi2rx_setup_shim(struct ti_csi2rx_dev *csi) +{ + const struct ti_csi2rx_fmt *fmt; + unsigned int reg; + + fmt = find_format_by_pix(csi->v_fmt.fmt.pix.pixelformat); + if (!fmt) { + dev_err(csi->dev, "Unknown format\n"); + return; + } + + /* De-assert the pixel interface reset. */ + reg = SHIM_CNTL_PIX_RST; + writel(reg, csi->shim + SHIM_CNTL); + + reg = SHIM_DMACNTX_EN; + reg |= FIELD_PREP(SHIM_DMACNTX_FMT, fmt->csi_dt); + + /* + * Using the values from the documentation gives incorrect ordering for + * the luma and chroma components. In practice, the "reverse" format + * gives the correct image. So for example, if the image is in UYVY, the + * reverse would be YVYU. + */ + switch (fmt->fourcc) { + case V4L2_PIX_FMT_UYVY: + reg |= FIELD_PREP(SHIM_DMACNTX_YUV422, + SHIM_DMACNTX_YVYU); + break; + case V4L2_PIX_FMT_VYUY: + reg |= FIELD_PREP(SHIM_DMACNTX_YUV422, + SHIM_DMACNTX_YUYV); + break; + case V4L2_PIX_FMT_YUYV: + reg |= FIELD_PREP(SHIM_DMACNTX_YUV422, + SHIM_DMACNTX_VYUY); + break; + case V4L2_PIX_FMT_YVYU: + reg |= FIELD_PREP(SHIM_DMACNTX_YUV422, + SHIM_DMACNTX_UYVY); + break; + default: + /* Ignore if not YUV 4:2:2 */ + break; + } + + writel(reg, csi->shim + SHIM_DMACNTX); + + reg = FIELD_PREP(SHIM_PSI_CFG0_SRC_TAG, 0) | + FIELD_PREP(SHIM_PSI_CFG0_DST_TAG, 0); + writel(reg, csi->shim + SHIM_PSI_CFG0); +} + +static void ti_csi2rx_dma_callback(void *param) +{ + struct ti_csi2rx_buffer *buf = param; + struct ti_csi2rx_dev *csi = buf->csi; + struct ti_csi2rx_dma *dma = &csi->dma; + unsigned long flags; + + buf->vb.vb2_buf.timestamp = ktime_get_ns(); + buf->vb.sequence = csi->sequence++; + + spin_lock_irqsave(&dma->lock, flags); + + WARN_ON(dma->curr != buf); + vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE); + + /* If there are more buffers to process then start their transfer. */ + dma->curr = NULL; + while (!list_empty(&dma->queue)) { + buf = list_entry(dma->queue.next, struct ti_csi2rx_buffer, list); + list_del(&buf->list); + + if (ti_csi2rx_start_dma(csi, buf)) { + dev_err(csi->dev, "Failed to queue the next buffer for DMA\n"); + vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_ERROR); + } else { + dma->curr = buf; + break; + } + } + + if (!dma->curr) + dma->state = TI_CSI2RX_DMA_IDLE; + + spin_unlock_irqrestore(&dma->lock, flags); +} + +static int ti_csi2rx_start_dma(struct ti_csi2rx_dev *csi, + struct ti_csi2rx_buffer *buf) +{ + unsigned long addr; + struct dma_async_tx_descriptor *desc; + size_t len = csi->v_fmt.fmt.pix.sizeimage; + dma_cookie_t cookie; + int ret = 0; + + addr = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0); + desc = dmaengine_prep_slave_single(csi->dma.chan, addr, len, + DMA_DEV_TO_MEM, + DMA_PREP_INTERRUPT | DMA_CTRL_ACK); + if (!desc) + return -EIO; + + desc->callback = ti_csi2rx_dma_callback; + desc->callback_param = buf; + + cookie = dmaengine_submit(desc); + ret = dma_submit_error(cookie); + if (ret) + return ret; + + dma_async_issue_pending(csi->dma.chan); + + return 0; +} + +static void ti_csi2rx_cleanup_buffers(struct ti_csi2rx_dev *csi, + enum vb2_buffer_state state) +{ + struct ti_csi2rx_dma *dma = &csi->dma; + struct ti_csi2rx_buffer *buf = NULL, *tmp; + unsigned long flags; + + spin_lock_irqsave(&dma->lock, flags); + list_for_each_entry_safe(buf, tmp, &csi->dma.queue, list) { + list_del(&buf->list); + vb2_buffer_done(&buf->vb.vb2_buf, state); + } + + if (dma->curr) + vb2_buffer_done(&dma->curr->vb.vb2_buf, state); + + dma->curr = NULL; + dma->state = TI_CSI2RX_DMA_STOPPED; + spin_unlock_irqrestore(&dma->lock, flags); +} + +static int ti_csi2rx_queue_setup(struct vb2_queue *q, unsigned int *nbuffers, + unsigned int *nplanes, unsigned int sizes[], + struct device *alloc_devs[]) +{ + struct ti_csi2rx_dev *csi = vb2_get_drv_priv(q); + unsigned int size = csi->v_fmt.fmt.pix.sizeimage; + + if (*nplanes) { + if (sizes[0] < size) + return -EINVAL; + size = sizes[0]; + } + + *nplanes = 1; + sizes[0] = size; + + return 0; +} + +static int ti_csi2rx_buffer_prepare(struct vb2_buffer *vb) +{ + struct ti_csi2rx_dev *csi = vb2_get_drv_priv(vb->vb2_queue); + unsigned long size = csi->v_fmt.fmt.pix.sizeimage; + + if (vb2_plane_size(vb, 0) < size) { + dev_err(csi->dev, "Data will not fit into plane\n"); + return -EINVAL; + } + + vb2_set_plane_payload(vb, 0, size); + return 0; +} + +static void ti_csi2rx_buffer_queue(struct vb2_buffer *vb) +{ + struct ti_csi2rx_dev *csi = vb2_get_drv_priv(vb->vb2_queue); + struct ti_csi2rx_buffer *buf; + struct ti_csi2rx_dma *dma = &csi->dma; + unsigned long flags = 0; + int ret; + + buf = container_of(vb, struct ti_csi2rx_buffer, vb.vb2_buf); + buf->csi = csi; + + spin_lock_irqsave(&dma->lock, flags); + /* + * Usually the DMA callback takes care of queueing the pending buffers. + * But if DMA has stalled due to lack of buffers, restart it now. + */ + if (dma->state == TI_CSI2RX_DMA_IDLE) { + ret = ti_csi2rx_start_dma(csi, buf); + if (ret) { + dev_err(csi->dev, "Failed to start DMA: %d\n", ret); + vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_QUEUED); + goto unlock; + } + + dma->curr = buf; + dma->state = TI_CSI2RX_DMA_ACTIVE; + } else { + list_add_tail(&buf->list, &dma->queue); + } + +unlock: + spin_unlock_irqrestore(&dma->lock, flags); +} + +static int ti_csi2rx_start_streaming(struct vb2_queue *vq, unsigned int count) +{ + struct ti_csi2rx_dev *csi = vb2_get_drv_priv(vq); + struct ti_csi2rx_dma *dma = &csi->dma; + struct ti_csi2rx_buffer *buf; + unsigned long flags; + int ret = 0; + + spin_lock_irqsave(&dma->lock, flags); + if (list_empty(&dma->queue)) + ret = -EIO; + spin_unlock_irqrestore(&dma->lock, flags); + if (ret) + return ret; + + ret = media_pipeline_start(&csi->vdev.entity.pads[0], &csi->pipe); + if (ret) + goto err; + + ti_csi2rx_setup_shim(csi); + + csi->sequence = 0; + + spin_lock_irqsave(&dma->lock, flags); + buf = list_entry(dma->queue.next, struct ti_csi2rx_buffer, list); + list_del(&buf->list); + dma->state = TI_CSI2RX_DMA_ACTIVE; + dma->curr = buf; + + ret = ti_csi2rx_start_dma(csi, buf); + if (ret) { + dev_err(csi->dev, "Failed to start DMA: %d\n", ret); + spin_unlock_irqrestore(&dma->lock, flags); + goto err_pipeline; + } + + spin_unlock_irqrestore(&dma->lock, flags); + + ret = v4l2_subdev_call(csi->subdev, video, s_stream, 1); + if (ret) + goto err_dma; + + return 0; + +err_dma: + dmaengine_terminate_sync(csi->dma.chan); + writel(0, csi->shim + SHIM_DMACNTX); +err_pipeline: + media_pipeline_stop(&csi->vdev.entity.pads[0]); +err: + ti_csi2rx_cleanup_buffers(csi, VB2_BUF_STATE_QUEUED); + return ret; +} + +static void ti_csi2rx_stop_streaming(struct vb2_queue *vq) +{ + struct ti_csi2rx_dev *csi = vb2_get_drv_priv(vq); + int ret; + + media_pipeline_stop(&csi->vdev.entity.pads[0]); + + ret = v4l2_subdev_call(csi->subdev, video, s_stream, 0); + if (ret) + dev_err(csi->dev, "Failed to stop subdev stream\n"); + + writel(0, csi->shim + SHIM_CNTL); + + ret = dmaengine_terminate_sync(csi->dma.chan); + if (ret) + dev_err(csi->dev, "Failed to stop DMA: %d\n", ret); + + writel(0, csi->shim + SHIM_DMACNTX); + + ti_csi2rx_cleanup_buffers(csi, VB2_BUF_STATE_ERROR); +} + +static const struct vb2_ops csi_vb2_qops = { + .queue_setup = ti_csi2rx_queue_setup, + .buf_prepare = ti_csi2rx_buffer_prepare, + .buf_queue = ti_csi2rx_buffer_queue, + .start_streaming = ti_csi2rx_start_streaming, + .stop_streaming = ti_csi2rx_stop_streaming, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, +}; + +static int ti_csi2rx_init_vb2q(struct ti_csi2rx_dev *csi) +{ + struct vb2_queue *q = &csi->vidq; + int ret; + + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + q->io_modes = VB2_MMAP | VB2_DMABUF | VB2_READ; + q->drv_priv = csi; + q->buf_struct_size = sizeof(struct ti_csi2rx_buffer); + q->ops = &csi_vb2_qops; + q->mem_ops = &vb2_dma_contig_memops; + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; + q->dev = dmaengine_get_dma_device(csi->dma.chan); + q->lock = &csi->mutex; + q->min_buffers_needed = 1; + + ret = vb2_queue_init(q); + if (ret) + return ret; + + csi->vdev.queue = q; + + return 0; +} + +static int ti_csi2rx_link_validate_get_fmt(struct media_pad *pad, + struct v4l2_subdev_format *fmt) +{ + if (is_media_entity_v4l2_subdev(pad->entity)) { + struct v4l2_subdev *sd = + media_entity_to_v4l2_subdev(pad->entity); + + fmt->which = V4L2_SUBDEV_FORMAT_ACTIVE; + fmt->pad = pad->index; + return v4l2_subdev_call(sd, pad, get_fmt, NULL, fmt); + } + + WARN(pad->entity->function != MEDIA_ENT_F_IO_V4L, + "Driver bug! Wrong media entity type 0x%08x, entity %s\n", + pad->entity->function, pad->entity->name); + + return -EINVAL; +} + +static int ti_csi2rx_link_validate(struct media_link *link) +{ + struct media_entity *entity = link->sink->entity; + struct video_device *vdev = media_entity_to_video_device(entity); + struct ti_csi2rx_dev *csi = container_of(vdev, struct ti_csi2rx_dev, vdev); + struct v4l2_pix_format *csi_fmt = &csi->v_fmt.fmt.pix; + struct v4l2_subdev_format source_fmt; + const struct ti_csi2rx_fmt *ti_fmt; + int ret; + + if (!(link->flags & MEDIA_LNK_FL_ENABLED)) { + dev_info(csi->dev, "video node %s pad not connected\n", + vdev->name); + return -ENOTCONN; + } + + ret = ti_csi2rx_link_validate_get_fmt(link->source, &source_fmt); + if (ret) + return ret; + + if (source_fmt.format.width != csi_fmt->width) { + dev_err(csi->dev, "Width does not match (source %u, sink %u)\n", + source_fmt.format.width, csi_fmt->width); + return -EPIPE; + } + + if (source_fmt.format.height != csi_fmt->height) { + dev_err(csi->dev, "Height does not match (source %u, sink %u)\n", + source_fmt.format.height, csi_fmt->height); + return -EPIPE; + } + + if (source_fmt.format.field != csi_fmt->field && + csi_fmt->field != V4L2_FIELD_NONE) { + dev_err(csi->dev, "Field does not match (source %u, sink %u)\n", + source_fmt.format.field, csi_fmt->field); + return -EPIPE; + } + + ti_fmt = find_format_by_code(source_fmt.format.code); + if (!ti_fmt) { + dev_err(csi->dev, "Media bus format 0x%x not supported\n", + source_fmt.format.code); + return -EPIPE; + } + + if (source_fmt.format.code == MEDIA_BUS_FMT_YUYV8_2X8 || + source_fmt.format.code == MEDIA_BUS_FMT_VYUY8_2X8 || + source_fmt.format.code == MEDIA_BUS_FMT_YVYU8_2X8) { + dev_err(csi->dev, + "Only UYVY input allowed for YUV422 8-bit. Output format can be configured.\n"); + return -EPIPE; + } + + if (source_fmt.format.code != ti_fmt->code) { + dev_err(csi->dev, + "Cannot transform source fmt 0x%x to sink fmt 0x%x\n", + source_fmt.format.code, ti_fmt->code); + return -EPIPE; + } + + return 0; +} + +static const struct media_entity_operations ti_csi2rx_video_entity_ops = { + .link_validate = ti_csi2rx_link_validate, +}; + +static int ti_csi2rx_init_dma(struct ti_csi2rx_dev *csi) +{ + struct dma_slave_config cfg = { + .src_addr_width = DMA_SLAVE_BUSWIDTH_16_BYTES }; + int ret; + + INIT_LIST_HEAD(&csi->dma.queue); + spin_lock_init(&csi->dma.lock); + + csi->dma.state = TI_CSI2RX_DMA_STOPPED; + + csi->dma.chan = dma_request_chan(csi->dev, "rx0"); + if (IS_ERR(csi->dma.chan)) + return PTR_ERR(csi->dma.chan); + + ret = dmaengine_slave_config(csi->dma.chan, &cfg); + if (ret) { + dma_release_channel(csi->dma.chan); + return ret; + } + + return 0; +} + +static int ti_csi2rx_v4l2_init(struct ti_csi2rx_dev *csi) +{ + struct media_device *mdev = &csi->mdev; + struct video_device *vdev = &csi->vdev; + const struct ti_csi2rx_fmt *fmt; + struct v4l2_pix_format *pix_fmt = &csi->v_fmt.fmt.pix; + int ret; + + fmt = find_format_by_pix(V4L2_PIX_FMT_UYVY); + if (!fmt) + return -EINVAL; + + pix_fmt->width = 640; + pix_fmt->height = 480; + pix_fmt->field = V4L2_FIELD_NONE; + + ti_csi2rx_fill_fmt(fmt, &csi->v_fmt); + + mdev->dev = csi->dev; + mdev->hw_revision = 1; + strscpy(mdev->model, "TI-CSI2RX", sizeof(mdev->model)); + snprintf(mdev->bus_info, sizeof(mdev->bus_info), "platform:%s", + dev_name(mdev->dev)); + + media_device_init(mdev); + + strscpy(vdev->name, TI_CSI2RX_MODULE_NAME, sizeof(vdev->name)); + vdev->v4l2_dev = &csi->v4l2_dev; + vdev->vfl_dir = VFL_DIR_RX; + vdev->fops = &csi_fops; + vdev->ioctl_ops = &csi_ioctl_ops; + vdev->release = video_device_release_empty; + vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING | + V4L2_CAP_IO_MC; + vdev->lock = &csi->mutex; + video_set_drvdata(vdev, csi); + + csi->pad.flags = MEDIA_PAD_FL_SINK; + vdev->entity.ops = &ti_csi2rx_video_entity_ops; + ret = media_entity_pads_init(&csi->vdev.entity, 1, &csi->pad); + if (ret) + return ret; + + csi->v4l2_dev.mdev = mdev; + + ret = v4l2_device_register(csi->dev, &csi->v4l2_dev); + if (ret) + return ret; + + ret = media_device_register(mdev); + if (ret) { + v4l2_device_unregister(&csi->v4l2_dev); + media_device_cleanup(mdev); + return ret; + } + + return 0; +} + +static void ti_csi2rx_cleanup_dma(struct ti_csi2rx_dev *csi) +{ + dma_release_channel(csi->dma.chan); +} + +static void ti_csi2rx_cleanup_v4l2(struct ti_csi2rx_dev *csi) +{ + media_device_unregister(&csi->mdev); + v4l2_device_unregister(&csi->v4l2_dev); + media_device_cleanup(&csi->mdev); +} + +static void ti_csi2rx_cleanup_subdev(struct ti_csi2rx_dev *csi) +{ + v4l2_async_nf_unregister(&csi->notifier); + v4l2_async_nf_cleanup(&csi->notifier); +} + +static void ti_csi2rx_cleanup_vb2q(struct ti_csi2rx_dev *csi) +{ + vb2_queue_release(&csi->vidq); +} + +static int ti_csi2rx_probe(struct platform_device *pdev) +{ + struct ti_csi2rx_dev *csi; + struct resource *res; + int ret; + + csi = devm_kzalloc(&pdev->dev, sizeof(*csi), GFP_KERNEL); + if (!csi) + return -ENOMEM; + + csi->dev = &pdev->dev; + platform_set_drvdata(pdev, csi); + + mutex_init(&csi->mutex); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + csi->shim = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(csi->shim)) { + ret = PTR_ERR(csi->shim); + goto err_mutex; + } + + ret = ti_csi2rx_init_dma(csi); + if (ret) + goto err_mutex; + + ret = ti_csi2rx_v4l2_init(csi); + if (ret) + goto err_dma; + + ret = ti_csi2rx_init_vb2q(csi); + if (ret) + goto err_v4l2; + + ret = ti_csi2rx_init_subdev(csi); + if (ret) + goto err_vb2q; + + ret = of_platform_populate(csi->dev->of_node, NULL, NULL, csi->dev); + if (ret) { + dev_err(csi->dev, "Failed to create children: %d\n", ret); + goto err_subdev; + } + + return 0; + +err_subdev: + ti_csi2rx_cleanup_subdev(csi); +err_vb2q: + ti_csi2rx_cleanup_vb2q(csi); +err_v4l2: + ti_csi2rx_cleanup_v4l2(csi); +err_dma: + ti_csi2rx_cleanup_dma(csi); +err_mutex: + mutex_destroy(&csi->mutex); + return ret; +} + +static int ti_csi2rx_remove(struct platform_device *pdev) +{ + struct ti_csi2rx_dev *csi = platform_get_drvdata(pdev); + + video_unregister_device(&csi->vdev); + + ti_csi2rx_cleanup_vb2q(csi); + ti_csi2rx_cleanup_subdev(csi); + ti_csi2rx_cleanup_v4l2(csi); + ti_csi2rx_cleanup_dma(csi); + + mutex_destroy(&csi->mutex); + + return 0; +} + +static const struct of_device_id ti_csi2rx_of_match[] = { + { .compatible = "ti,j721e-csi2rx", }, + { }, +}; +MODULE_DEVICE_TABLE(of, ti_csi2rx_of_match); + +static struct platform_driver ti_csi2rx_pdrv = { + .probe = ti_csi2rx_probe, + .remove = ti_csi2rx_remove, + .driver = { + .name = TI_CSI2RX_MODULE_NAME, + .of_match_table = ti_csi2rx_of_match, + }, +}; + +module_platform_driver(ti_csi2rx_pdrv); + +MODULE_DESCRIPTION("TI J721E CSI2 RX Driver"); +MODULE_AUTHOR("Pratyush Yadav "); +MODULE_LICENSE("GPL"); From patchwork Tue Mar 14 11:55:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaishnav Achath X-Patchwork-Id: 69530 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1716342wrd; Tue, 14 Mar 2023 05:07:49 -0700 (PDT) X-Google-Smtp-Source: AK7set+ZxIOsmtbfHhzLpZZ0CfonpfJUt0qQbL6CidmEI2rTWzfxhs3FlLPyRYci/FM5dZtvHv8R X-Received: by 2002:a17:902:740c:b0:19f:2dff:2199 with SMTP id g12-20020a170902740c00b0019f2dff2199mr9166677pll.68.1678795669272; Tue, 14 Mar 2023 05:07:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678795669; cv=none; d=google.com; s=arc-20160816; b=KBTCbNr+7Jz+62GBMNq8BhFXEpecOubEWXx0z8d0lAit7/HvCPF1SdjXvuDni6ztMu v5SCMMEQfvHlfufj8NZm/ZwkCcrqyc/qmFz6dNdsWmE85i6l//kHVj4uuHhJSeFK5K60 gvZFlMYF6tvPoDjKtIyM2BRGtITDKMY+lJocovT4aVN8EMUUlsB0wT8PXxWvH1mVUbVE BBtYOD954emesD8IhgwE+rVJ3rM+NFnpzN4EeWTjpQjL/ZDDmSF5TF1d9vYHLVWh/3JH mdfGqXT9zYNCtaz4kNbYSPHH9XH52Gemaomv6ZPePYSvF9OsfBSYWtkdWhmR8dcM9aig 6qiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=VDtUJrgTjd2rb4VAXloCWsnsEJXWfY/RvZ3NEQMYfyw=; b=z83esFS2OSFurHLhPcnjOO3X6FoMeqeJv9/U3QdMfvdqQTp/quNfZZ9cao938Uzxxr 6kbNCR+owC0A104xZYZRTq3HD+iEktNi1W/Z+7n5vq+zD3TtJBZOElnrr3m+reWkM1aZ B2iqdJTwl1473MJBS+A/xviVhYyYCJ0oDqetvHlwljIYOYVX//9KWkdNzTF/jkLRAiKC 59OAulr32nTKVT6ZLzoiTQ1NdHpP4pBXkjUoH0vGzCBQNy/RKwg2nyn+/QUj/6eMPuu3 cZ4zDnN/Opt3hwPobcRBUIH2G3Jsqr8WGgAW8amA/tSWTU3KkgPRzabSCSelzbXomm8d mNNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=P4AkvQHC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x1-20020a1709028ec100b0019f31a90472si2254446plo.636.2023.03.14.05.07.36; Tue, 14 Mar 2023 05:07:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=P4AkvQHC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231597AbjCNL4l (ORCPT + 99 others); Tue, 14 Mar 2023 07:56:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231553AbjCNL4V (ORCPT ); Tue, 14 Mar 2023 07:56:21 -0400 Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C2A29FE6C; Tue, 14 Mar 2023 04:56:05 -0700 (PDT) Received: from fllv0035.itg.ti.com ([10.64.41.0]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtekY051556; Tue, 14 Mar 2023 06:55:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1678794940; bh=VDtUJrgTjd2rb4VAXloCWsnsEJXWfY/RvZ3NEQMYfyw=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=P4AkvQHC6WXuDCZ0e1/TCz1DOMfrlFQpHOtxIrt8tWehBUPi08wGMEsD5GEifn8s+ OSr82bt32m0nsZmALI53ZWfzKxNZuR7YaiztMMwqb2Re1+uM/EXoOQGVUfkktuQjoF 7xU2DAPARS3UkrE12961HY9BplZS1OzTHg3scu4s= Received: from DFLE106.ent.ti.com (dfle106.ent.ti.com [10.64.6.27]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 32EBteUS114865 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 14 Mar 2023 06:55:40 -0500 Received: from DFLE108.ent.ti.com (10.64.6.29) by DFLE106.ent.ti.com (10.64.6.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Tue, 14 Mar 2023 06:55:39 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DFLE108.ent.ti.com (10.64.6.29) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Tue, 14 Mar 2023 06:55:39 -0500 Received: from localhost (ileaxei01-snat.itg.ti.com [10.180.69.5]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtcI4057373; Tue, 14 Mar 2023 06:55:39 -0500 From: Vaishnav Achath To: , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v7 11/13] media: dt-bindings: Make sure items in data-lanes are unique Date: Tue, 14 Mar 2023 17:25:14 +0530 Message-ID: <20230314115516.667-12-vaishnav.a@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314115516.667-1-vaishnav.a@ti.com> References: <20230314115516.667-1-vaishnav.a@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760344847776023119?= X-GMAIL-MSGID: =?utf-8?q?1760344847776023119?= From: Pratyush Yadav The data-lanes property maps the logical lane numbers to the physical lane numbers. The position of an entry is the logical lane number and its value is the physical lane number. Since one physical lane can only map to one logical lane, no number in the list should repeat. Add the uniqueItems constraint on the property to enforce this. Signed-off-by: Pratyush Yadav Signed-off-by: Vaishnav Achath Reviewed-by: Laurent Pinchart Acked-by: Rob Herring --- (no changes since v5) Changes in v5: - Add Laurent's R-by and Rob's Ack. Changes in v4: - New in v4. Documentation/devicetree/bindings/media/video-interfaces.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/media/video-interfaces.yaml b/Documentation/devicetree/bindings/media/video-interfaces.yaml index a211d49dc2ac..26e3e7d7c67b 100644 --- a/Documentation/devicetree/bindings/media/video-interfaces.yaml +++ b/Documentation/devicetree/bindings/media/video-interfaces.yaml @@ -160,6 +160,7 @@ properties: $ref: /schemas/types.yaml#/definitions/uint32-array minItems: 1 maxItems: 8 + uniqueItems: true items: # Assume up to 9 physical lane indices maximum: 8 From patchwork Tue Mar 14 11:55:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaishnav Achath X-Patchwork-Id: 69523 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1711194wrd; Tue, 14 Mar 2023 04:59:05 -0700 (PDT) X-Google-Smtp-Source: AK7set/dhJiLPEengwpAVOC8dqGeGu5tQJfD/C15mhNSR/GY2CB+h8gwOpkRds7MOqq8nK9mQdci X-Received: by 2002:a17:90b:1d88:b0:233:ccd2:40a5 with SMTP id pf8-20020a17090b1d8800b00233ccd240a5mr37651361pjb.32.1678795144962; Tue, 14 Mar 2023 04:59:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678795144; cv=none; d=google.com; s=arc-20160816; b=jdiCzBS18QcpA9DwVtpKyQuH19Di9fKtPpHrzalM32DlzlmeUcIcJjhDvbSCYCLbVk L+7nfIvH91EafFeN7ZxJuubHzx2o5lW/fOia6umSPKdNbHtM2ZgXdN1dT4yfwLHYGVRF +6/wNS7UDOhEOmY/htorZ3CVUqO2s+iGtOH/KTXuciqDx/jezS/vRZIHA7JnSpw24o+f J8YIVK0FeRJcDG36omDnwqUDaCMlSpDqdy+FiI7FrCv8ahp7Td1TDB+yBAuMuZXu8YtY i1FyKgQ9h1Mm+CBgFW0LIBhhai01BfCJh4nzrYWZBRQw8eI3BFBzYAmvf1M4ZHyHc15f 8fnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=ddovUNv2LEGp3gIShbawH913wqA8KX1RQrHrCXJXEQo=; b=YH8H2+rgy9Eao5q/kCHMcVwU2mNnqIaFLPYxhTY3r/5C0M6DAUjrPD7twvm5kzeH+V jOQMUL92Pu8HI2UD2mxphQwaMeDDuWVag4srg7VDZoAHnIiil7i4PQHn6N3Ta5fTCbIw CxsufflICHrPHw7JL6TLYhkjGlFKYHjcfl5cjbfyDH/lr3CY1T+ka4B0Ytzrkk6WpgSI vC61qgpIqt8WtS9TyTqj879//xLGTlQ6YxdyPf8BSKHl9lk21qNeAWVuygQmcZ2N/K/B YOy/KFEt/pIjoXGYahaGBSkz23FRJIG9R9ep/hOh4KM17DCmChY6vDzHRXt2xMBQmVch oRQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=BEODxeeC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 24-20020a631258000000b0050bd14260basi692271pgs.239.2023.03.14.04.58.49; Tue, 14 Mar 2023 04:59:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=BEODxeeC; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231544AbjCNL4x (ORCPT + 99 others); Tue, 14 Mar 2023 07:56:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231628AbjCNL40 (ORCPT ); Tue, 14 Mar 2023 07:56:26 -0400 Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EAB13A029F; Tue, 14 Mar 2023 04:56:06 -0700 (PDT) Received: from lelv0266.itg.ti.com ([10.180.67.225]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtgKl051569; Tue, 14 Mar 2023 06:55:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1678794942; bh=ddovUNv2LEGp3gIShbawH913wqA8KX1RQrHrCXJXEQo=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=BEODxeeC3mjlTpmQjBsG4eppkr2hZxdsR65mf3hk8Yost8oHEeV8RffpRHtd07iAv VDZJqBEnDFMRZKNWsrvXWzYDeSzErKJmi0GFnzNPIYCFSrRxlTaicVS2p1YN8X3sk9 gma7io2O4HBdWYU1BDzPsVKwjml+vFrNLyBPq+oc= Received: from DLEE105.ent.ti.com (dlee105.ent.ti.com [157.170.170.35]) by lelv0266.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 32EBtfmK112617 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 14 Mar 2023 06:55:42 -0500 Received: from DLEE102.ent.ti.com (157.170.170.32) by DLEE105.ent.ti.com (157.170.170.35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Tue, 14 Mar 2023 06:55:41 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE102.ent.ti.com (157.170.170.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Tue, 14 Mar 2023 06:55:41 -0500 Received: from localhost (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtelG002476; Tue, 14 Mar 2023 06:55:41 -0500 From: Vaishnav Achath To: , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v7 12/13] media: dt-bindings: Add DT bindings for TI J721E CSI2RX driver Date: Tue, 14 Mar 2023 17:25:15 +0530 Message-ID: <20230314115516.667-13-vaishnav.a@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314115516.667-1-vaishnav.a@ti.com> References: <20230314115516.667-1-vaishnav.a@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760344297813379876?= X-GMAIL-MSGID: =?utf-8?q?1760344297813379876?= From: Pratyush Yadav TI's J721E uses the Cadence CSI2RX and DPHY peripherals to facilitate capture over a CSI-2 bus. The TI CSI2RX platform driver glues all the parts together. Signed-off-by: Pratyush Yadav Signed-off-by: Vaishnav Achath Reviewed-by: Laurent Pinchart Reviewed-by: Rob Herring --- (no changes since v5) Changes in v5: - Add Laurent's and Rob's R-by. Changes in v2: - Rename to ti,j721e-csi2rx.yaml - Add an entry in MAINTAINERS. - Add a description for the binding. - Change compatible to ti,j721e-csi2rx to make it SoC specific. - Remove description from dmas, reg, power-domains. - Remove a limit of 2 from #address-cells and #size-cells. - Fix add ^ to csi-bridge subnode regex. - Make ranges mandatory. - Add unit address in example. - Add a reference to cdns,csi2rx in csi-bridge subnode. - Expand the example to include the csi-bridge subnode as well. - Re-order subject prefixes. .../bindings/media/ti,j721e-csi2rx.yaml | 101 ++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 102 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/ti,j721e-csi2rx.yaml diff --git a/Documentation/devicetree/bindings/media/ti,j721e-csi2rx.yaml b/Documentation/devicetree/bindings/media/ti,j721e-csi2rx.yaml new file mode 100644 index 000000000000..db87cfd65bed --- /dev/null +++ b/Documentation/devicetree/bindings/media/ti,j721e-csi2rx.yaml @@ -0,0 +1,101 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/ti,j721e-csi2rx.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: TI J721E CSI2RX Wrapper Device Tree Bindings + +description: | + The TI J721E CSI2RX Wrapper is a wrapper around Cadence CSI2RX bridge that + enables sending captured frames to memory over PSI-L DMA. In the J721E + Technical Reference Manual (SPRUIL1B) it is referred to as "SHIM" under the + CSI_RX_IF section. + +maintainers: + - Pratyush Yadav + +properties: + compatible: + items: + - const: ti,j721e-csi2rx + + dmas: + maxItems: 1 + + dma-names: + items: + - const: rx0 + + reg: + maxItems: 1 + + power-domains: + maxItems: 1 + + ranges: true + + "#address-cells": true + + "#size-cells": true + +patternProperties: + "^csi-bridge@": + type: object + description: CSI2 bridge node. + $ref: cdns,csi2rx.yaml# + +required: + - compatible + - reg + - dmas + - dma-names + - power-domains + - ranges + - "#address-cells" + - "#size-cells" + +additionalProperties: false + +examples: + - | + #include + + ti_csi2rx0: ticsi2rx@4500000 { + compatible = "ti,j721e-csi2rx"; + dmas = <&main_udmap 0x4940>; + dma-names = "rx0"; + reg = <0x4500000 0x1000>; + power-domains = <&k3_pds 26 TI_SCI_PD_EXCLUSIVE>; + #address-cells = <1>; + #size-cells = <1>; + ranges; + + cdns_csi2rx: csi-bridge@4504000 { + compatible = "cdns,csi2rx"; + reg = <0x4504000 0x1000>; + clocks = <&k3_clks 26 2>, <&k3_clks 26 0>, <&k3_clks 26 2>, + <&k3_clks 26 2>, <&k3_clks 26 3>, <&k3_clks 26 3>; + clock-names = "sys_clk", "p_clk", "pixel_if0_clk", + "pixel_if1_clk", "pixel_if2_clk", "pixel_if3_clk"; + phys = <&dphy0>; + phy-names = "dphy"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + csi2_0: port@0 { + + reg = <0>; + + csi2rx0_in_sensor: endpoint { + remote-endpoint = <&csi2_cam0>; + bus-type = <4>; /* CSI2 DPHY. */ + clock-lanes = <0>; + data-lanes = <1 2>; + }; + }; + }; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 69c2b0f48073..796be64bc54f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -20905,6 +20905,7 @@ TI J721E CSI2RX DRIVER M: Vaishnav Achath L: linux-media@vger.kernel.org S: Supported +F: Documentation/devicetree/bindings/media/ti,j721e-csi2rx.yaml F: drivers/media/platform/ti/j721e-csi2rx/ TI DAVINCI MACHINE SUPPORT From patchwork Tue Mar 14 11:55:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vaishnav Achath X-Patchwork-Id: 69543 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp1719817wrd; Tue, 14 Mar 2023 05:14:12 -0700 (PDT) X-Google-Smtp-Source: AK7set/niNFiGEcpX0AQXpqUhrnON45yfF3lydiFbw4TIaetoyF38wyiBSNek3yejbgqeneu8beJ X-Received: by 2002:a05:6a20:7343:b0:cc:fbdc:886 with SMTP id v3-20020a056a20734300b000ccfbdc0886mr41522767pzc.18.1678796051889; Tue, 14 Mar 2023 05:14:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678796051; cv=none; d=google.com; s=arc-20160816; b=gaO2xJSCrmyo2r2Os/gutGZQkrCsnJr53XBHRL1LAlB8mJ3IubPnDExKZvS75wbjSi 6tZVsqYQBC744I4JPLhz5Ev+XQWszVDIuM34OBOcwQZr2PfSMPQ0b/IYxUsji/nsrZL2 NMNhbIQOgisFpbq/dWzjKEbJiEHnjMQ/8fyGNxOKM0boaBmSa05dP4L3Nq1h74vTgU85 xMnaFCtwmdAY2CMuzwZ1f//C1FWj4bAEmF4zUuSdZxZzeVciiyiYfkl+7CMb0/qJm7lo 5D/Tc0lPH5PgIzTKgq1NnQiM/Cpib+sm8mMUYnBg9ZJyXaPy4Xz5vN5jDbsHbBeB3193 RAbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=P+wE79vRwOpKW9fwKzkdEBQ32lwhEd06NzQVILyQMjo=; b=oB5QvfDNVU83mtpjQi1jiLE0zqYfQ7DjTx6LAzgbvWRs3mYolyk/1ff0uzy4WvAc7q 6rXlEGFF7gVty5TKkk9nNmqxu0b8d4BlMZ9z+nOQyFg2xmj7zJBSdyR9Kl0U+4sNDR9c 3Nr9FR+tq1GHpzRF2Via6qiXgX1jIqDl6z0rKnhR5gl8bzycWVs8Y2Fx+LDRxpLHBjeo 3vFODdJRTM6UOutbunyo1oWsq3nX8+JN90f4exoo5/uwiRNLVeFiMDPNXwLnuVpA9j1d Vpp+UY8mp6AStW60atnawORKfSe8gogKGYu/zWuw/9oRT8I9LmJSy1Z3SvNlgui3nHWa ATKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=fxhRQMb+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b127-20020a62cf85000000b005a8cf0d93cbsi42831pfg.3.2023.03.14.05.13.54; Tue, 14 Mar 2023 05:14:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b=fxhRQMb+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231721AbjCNL47 (ORCPT + 99 others); Tue, 14 Mar 2023 07:56:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231665AbjCNL40 (ORCPT ); Tue, 14 Mar 2023 07:56:26 -0400 Received: from lelv0142.ext.ti.com (lelv0142.ext.ti.com [198.47.23.249]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 201DE9FE6B; Tue, 14 Mar 2023 04:56:06 -0700 (PDT) Received: from lelv0265.itg.ti.com ([10.180.67.224]) by lelv0142.ext.ti.com (8.15.2/8.15.2) with ESMTP id 32EBthGt051579; Tue, 14 Mar 2023 06:55:43 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1678794943; bh=P+wE79vRwOpKW9fwKzkdEBQ32lwhEd06NzQVILyQMjo=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=fxhRQMb+6mvdTMPWlZpk0Vg9amc4D6eC3hWmqFX72BRBtQC2dvHans/RwLnl3ZN4P C3IUZ9nJMUcUXcX5iuazgDTZWaJvJSiYD/WFk8FPTHmD8oqO0dFcy5KICKEphAP+WO FvIITLxtSCWslYUsoFK1RmtIOQQmrsEkgQ3dCUuw= Received: from DLEE102.ent.ti.com (dlee102.ent.ti.com [157.170.170.32]) by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 32EBthot003196 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 14 Mar 2023 06:55:43 -0500 Received: from DLEE112.ent.ti.com (157.170.170.23) by DLEE102.ent.ti.com (157.170.170.32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16; Tue, 14 Mar 2023 06:55:43 -0500 Received: from fllv0040.itg.ti.com (10.64.41.20) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2507.16 via Frontend Transport; Tue, 14 Mar 2023 06:55:43 -0500 Received: from localhost (ileaxei01-snat2.itg.ti.com [10.180.69.6]) by fllv0040.itg.ti.com (8.15.2/8.15.2) with ESMTP id 32EBtgMI057421; Tue, 14 Mar 2023 06:55:42 -0500 From: Vaishnav Achath To: , , , , , , , , CC: , , , , , , , , , , Subject: [PATCH v7 13/13] media: dt-bindings: Convert Cadence CSI2RX binding to YAML Date: Tue, 14 Mar 2023 17:25:16 +0530 Message-ID: <20230314115516.667-14-vaishnav.a@ti.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230314115516.667-1-vaishnav.a@ti.com> References: <20230314115516.667-1-vaishnav.a@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1760345248856748370?= X-GMAIL-MSGID: =?utf-8?q?1760345248856748370?= From: Pratyush Yadav Convert the Cadence CSI2RX binding to use YAML schema. Signed-off-by: Pratyush Yadav Signed-off-by: Vaishnav Achath Reviewed-by: Rob Herring Reviewed-by: Laurent Pinchart --- (no changes since v5) Changes in v5: - Move clock description in comments under the clocks property. - Make ports required. - Add Rob's and Laurent's R-by. Changes in v4: - Add power-domains property. - Drop maxItems from clock-names. - Drop the type for data-lanes. - Drop uniqueItems from data-lanes. Move it to video-interfaces.yaml instead. Changes in v3: - Add compatible: contains: const: cdns,csi2rx to allow SoC specific compatible. - Add more constraints for data-lanes property. Changes in v2: - New in v2. .../devicetree/bindings/media/cdns,csi2rx.txt | 100 ---------- .../bindings/media/cdns,csi2rx.yaml | 176 ++++++++++++++++++ 2 files changed, 176 insertions(+), 100 deletions(-) delete mode 100644 Documentation/devicetree/bindings/media/cdns,csi2rx.txt create mode 100644 Documentation/devicetree/bindings/media/cdns,csi2rx.yaml diff --git a/Documentation/devicetree/bindings/media/cdns,csi2rx.txt b/Documentation/devicetree/bindings/media/cdns,csi2rx.txt deleted file mode 100644 index 6b02a0657ad9..000000000000 --- a/Documentation/devicetree/bindings/media/cdns,csi2rx.txt +++ /dev/null @@ -1,100 +0,0 @@ -Cadence MIPI-CSI2 RX controller -=============================== - -The Cadence MIPI-CSI2 RX controller is a CSI-2 bridge supporting up to 4 CSI -lanes in input, and 4 different pixel streams in output. - -Required properties: - - compatible: must be set to "cdns,csi2rx" and an SoC-specific compatible - - reg: base address and size of the memory mapped region - - clocks: phandles to the clocks driving the controller - - clock-names: must contain: - * sys_clk: main clock - * p_clk: register bank clock - * pixel_if[0-3]_clk: pixel stream output clock, one for each stream - implemented in hardware, between 0 and 3 - -Optional properties: - - phys: phandle to the external D-PHY, phy-names must be provided - - phy-names: must contain "dphy", if the implementation uses an - external D-PHY - -Required subnodes: - - ports: A ports node with one port child node per device input and output - port, in accordance with the video interface bindings defined in - Documentation/devicetree/bindings/media/video-interfaces.txt. The - port nodes are numbered as follows: - - Port Description - ----------------------------- - 0 CSI-2 input - 1 Stream 0 output - 2 Stream 1 output - 3 Stream 2 output - 4 Stream 3 output - - The stream output port nodes are optional if they are not - connected to anything at the hardware level or implemented - in the design.Since there is only one endpoint per port, - the endpoints are not numbered. - - -Example: - -csi2rx: csi-bridge@0d060000 { - compatible = "cdns,csi2rx"; - reg = <0x0d060000 0x1000>; - clocks = <&byteclock>, <&byteclock> - <&coreclock>, <&coreclock>, - <&coreclock>, <&coreclock>; - clock-names = "sys_clk", "p_clk", - "pixel_if0_clk", "pixel_if1_clk", - "pixel_if2_clk", "pixel_if3_clk"; - - ports { - #address-cells = <1>; - #size-cells = <0>; - - port@0 { - reg = <0>; - - csi2rx_in_sensor: endpoint { - remote-endpoint = <&sensor_out_csi2rx>; - clock-lanes = <0>; - data-lanes = <1 2>; - }; - }; - - port@1 { - reg = <1>; - - csi2rx_out_grabber0: endpoint { - remote-endpoint = <&grabber0_in_csi2rx>; - }; - }; - - port@2 { - reg = <2>; - - csi2rx_out_grabber1: endpoint { - remote-endpoint = <&grabber1_in_csi2rx>; - }; - }; - - port@3 { - reg = <3>; - - csi2rx_out_grabber2: endpoint { - remote-endpoint = <&grabber2_in_csi2rx>; - }; - }; - - port@4 { - reg = <4>; - - csi2rx_out_grabber3: endpoint { - remote-endpoint = <&grabber3_in_csi2rx>; - }; - }; - }; -}; diff --git a/Documentation/devicetree/bindings/media/cdns,csi2rx.yaml b/Documentation/devicetree/bindings/media/cdns,csi2rx.yaml new file mode 100644 index 000000000000..399fe619377d --- /dev/null +++ b/Documentation/devicetree/bindings/media/cdns,csi2rx.yaml @@ -0,0 +1,176 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/cdns,csi2rx.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Cadence MIPI-CSI2 RX controller + +description: | + The Cadence MIPI-CSI2 RX controller is a CSI-2 bridge supporting up to 4 CSI + lanes in input, and 4 different pixel streams in output. + +maintainers: + - Pratyush Yadav + +properties: + compatible: + contains: + const: cdns,csi2rx + + reg: + maxItems: 1 + + clocks: + minItems: 3 + items: + - description: Main clock + - description: Register bank clock + - description: Pixel stream 0 output clock + - description: Pixel stream 1 output clock + - description: Pixel stream 2 output clock + - description: Pixel stream 3 output clock + + clock-names: + minItems: 3 + items: + - const: sys_clk + - const: p_clk + - const: pixel_if0_clk + - const: pixel_if1_clk + - const: pixel_if2_clk + - const: pixel_if3_clk + + phys: + maxItems: 1 + description: phandle to the external D-PHY + + phy-names: + items: + - const: dphy + + power-domains: + maxItems: 1 + + ports: + $ref: /schemas/graph.yaml#/properties/ports + + properties: + port@0: + $ref: /schemas/graph.yaml#/$defs/port-base + unevaluatedProperties: false + description: CSI-2 input + + properties: + endpoint: + $ref: video-interfaces.yaml# + unevaluatedProperties: false + + properties: + clock-lanes: + maxItems: 1 + + data-lanes: + minItems: 1 + maxItems: 4 + items: + maximum: 4 + + required: + - clock-lanes + - data-lanes + + port@1: + $ref: /schemas/graph.yaml#/properties/port + description: Stream 0 output + + port@2: + $ref: /schemas/graph.yaml#/properties/port + description: Stream 1 output + + port@3: + $ref: /schemas/graph.yaml#/properties/port + description: Stream 2 output + + port@4: + $ref: /schemas/graph.yaml#/properties/port + description: Stream 3 output + + required: + - port@0 + + +dependencies: + phys: [ 'phy-names' ] + phy-names: [ 'phys' ] + +required: + - compatible + - reg + - clocks + - clock-names + - ports + +additionalProperties: false + +examples: + - | + csi2rx: csi-bridge@d060000 { + compatible = "cdns,csi2rx"; + reg = <0x0d060000 0x1000>; + clocks = <&byteclock>, <&byteclock>, + <&coreclock>, <&coreclock>, + <&coreclock>, <&coreclock>; + clock-names = "sys_clk", "p_clk", + "pixel_if0_clk", "pixel_if1_clk", + "pixel_if2_clk", "pixel_if3_clk"; + phys = <&dphy0>; + phy-names = "dphy"; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + port@0 { + reg = <0>; + + csi2rx_in_sensor: endpoint { + remote-endpoint = <&sensor_out_csi2rx>; + clock-lanes = <0>; + data-lanes = <1 2>; + }; + }; + + port@1 { + reg = <1>; + + csi2rx_out_grabber0: endpoint { + remote-endpoint = <&grabber0_in_csi2rx>; + }; + }; + + port@2 { + reg = <2>; + + csi2rx_out_grabber1: endpoint { + remote-endpoint = <&grabber1_in_csi2rx>; + }; + }; + + port@3 { + reg = <3>; + + csi2rx_out_grabber2: endpoint { + remote-endpoint = <&grabber2_in_csi2rx>; + }; + }; + + port@4 { + reg = <4>; + + csi2rx_out_grabber3: endpoint { + remote-endpoint = <&grabber3_in_csi2rx>; + }; + }; + }; + };