From patchwork Tue Apr 16 09:30:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902403 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1B73B922 for ; Tue, 16 Apr 2019 09:32:22 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 065DB2892A for ; Tue, 16 Apr 2019 09:32:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ED5F72892C; Tue, 16 Apr 2019 09:32:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0854D2892A for ; Tue, 16 Apr 2019 09:32:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=C30nY9IuHhwhvVDt2lCPMsSJNTuD4X8pCFJtD2V/g6Y=; b=kAzxAfs68s99V3 aw07FT/eT4nWdjmu2PzfXghXouF1yNSWwYYGhZdqSiw6PGbpz2Z8wLZiX0Lyb2jCDBFNAkVJADGqd e0Jtsj6Jkn77k2rfJxfvH1nMVM6Y8vtnzz7OCfMu95ulqnLuN6+0XRmsmRHu/UgvNNa5socpmLRj9 QYQf4A19sLZvMrzSdMqEMFBjS7BVLE77A2+NQUIclVWLVDgWOrtFHE/9Lqvx65fQAS8+jat/6JZ7H KgFz8TB0yPo51R+6mnM7nADJcFEw5zKo9pyToNMTq0d4d/5OZQzFKwuEif1jUuVdu91RPKUaz7f6A hTT+gc9A9PsvX2Z4RbXw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKRv-00077T-OU; Tue, 16 Apr 2019 09:32:19 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQK-0005JX-2E; Tue, 16 Apr 2019 09:30:40 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Jd1TMA/XErF3Mc/Z9GL4Fu8yf305n8i3UaJyg4W4ybc=; b=AkA8IYM1Cyjq/JREZKd1+bY4c hznNzwWd2xLz5VGgh8RdUSXhERkfFtOFgopWagXcanLdIx7Vk/Xg+sbOJ9sIZGkmA5fXhfnFxCbd4 mAiCaQxneqtQY6xQWNoHZxFPPldECJ2cbgyrlsGkCLmRdlSlP9+qw46T2+yXFhKZ06fkaPoHFR6dM 29MEl2snfbL2Mf/sunGuviMEqWFkX5yzUVynR1OK1IZmFYP7Cu+N7CsZBuGpFBhKRs8CaqZWz7JeO mpTsqE2ZxNg0sbVoLeOJf2RuEygm4DXy3S1rIBjbLbUnhwPRPIJ6ioFsrKNrfh25q4grHMa0V/wID m1NZBFxMQ==; Received: from mailgw01.mediatek.com ([216.200.240.184]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQG-0001GE-R3; Tue, 16 Apr 2019 09:30:38 +0000 X-UUID: 56cdefcdc9674c2d99c97a606deac1af-20190416 X-UUID: 56cdefcdc9674c2d99c97a606deac1af-20190416 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 205400643; Tue, 16 Apr 2019 01:30:20 -0800 Received: from mtkmbs03n1.mediatek.inc (172.21.101.181) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:30:18 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs03n1.mediatek.inc (172.21.101.181) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 17:30:17 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 17:30:17 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v2 01/15] dt-bindings: media: Add binding for MT2712 MIPI-CSI2 Date: Tue, 16 Apr 2019 17:30:01 +0800 Message-ID: <1555407015-18130-2-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> References: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_053037_100283_311D73C9 X-CRM114-Status: GOOD ( 14.00 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add MIPI-CSI2 dt-binding for Mediatek MT2712 SoC Signed-off-by: Stu Hsieh --- .../bindings/media/mediatek-mipicsi-camsv.txt | 53 ++++++++++++++++++ .../media/mediatek-mipicsi-common.txt | 19 +++++++ .../bindings/media/mediatek-mipicsi.txt | 54 +++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/mediatek-mipicsi-camsv.txt create mode 100644 Documentation/devicetree/bindings/media/mediatek-mipicsi-common.txt create mode 100644 Documentation/devicetree/bindings/media/mediatek-mipicsi.txt diff --git a/Documentation/devicetree/bindings/media/mediatek-mipicsi-camsv.txt b/Documentation/devicetree/bindings/media/mediatek-mipicsi-camsv.txt new file mode 100644 index 000000000000..5f34974f12ac --- /dev/null +++ b/Documentation/devicetree/bindings/media/mediatek-mipicsi-camsv.txt @@ -0,0 +1,53 @@ +* Mediatek MIPI-CSI2 receiver camsv + +Mediatek MIPI-CSI2 receiver camsv transfer data to DRAM in Mediatek SoCs + +Required properties: +- reg : physical base address of the mipicsi receiver registers and length of + memory mapped region. +- clocks: device clocks, see + Documentation/devicetree/bindings/clock/clock-bindings.txt for details. +- interrupts : interrupt number to the interrupt controller. + +Example: + seninf1_mux_camsv0: seninf_mux_camsv@15002100 { + reg = <0 0x15002120 0 0x40>, + <0 0x15004000 0 0x1000>; + clocks = <&imgsys CLK_IMG_CAM_SV_EN>; + interrupts = ; + }; + + seninf2_mux_camsv1: seninf_mux_camsv@15002500 { + reg = <0 0x15002520 0 0x40>, + <0 0x15005000 0 0x1000>; + clocks = <&imgsys CLK_IMG_CAM_SV_EN>; + interrupts = ; + }; + + seninf3_mux_camsv2: seninf_mux_camsv@15002900 { + reg = <0 0x15002920 0 0x40>, + <0 0x15006000 0 0x1000>; + clocks = <&imgsys CLK_IMG_CAM_SV1_EN>; + interrupts = ; + }; + + seninf4_mux_camsv3: seninf_mux_camsv@15002D00 { + reg = <0 0x15002D20 0 0x40>, + <0 0x15007000 0 0x1000>; + clocks = <&imgsys CLK_IMG_CAM_SV1_EN>; + interrupts = ; + }; + + seninf5_mux_camsv4: seninf_mux_camsv@15003100 { + reg = <0 0x15003120 0 0x40>, + <0 0x15008000 0 0x1000>; + clocks = <&imgsys CLK_IMG_CAM_SV2_EN>; + interrupts = ; + }; + + seninf6_mux_camsv5: seninf_mux_camsv@15003500 { + reg = <0 0x15003520 0 0x40>, + <0 0x15009000 0 0x1000>; + clocks = <&imgsys CLK_IMG_CAM_SV2_EN>; + interrupts = ; + }; diff --git a/Documentation/devicetree/bindings/media/mediatek-mipicsi-common.txt b/Documentation/devicetree/bindings/media/mediatek-mipicsi-common.txt new file mode 100644 index 000000000000..a67c744b75f0 --- /dev/null +++ b/Documentation/devicetree/bindings/media/mediatek-mipicsi-common.txt @@ -0,0 +1,19 @@ +* Mediatek MIPI-CSI2 receiver common + +Mediatek MIPI-CSI2 receiver is the MIPI Signal capture hardware present in Mediatek SoCs + +Required properties: +- compatible: should be "mediatek,mt2712-mipicsi-common" +- reg : physical base address of the mipicsi receiver registers and length of + memory mapped region. +- clocks: device clocks, see + Documentation/devicetree/bindings/clock/clock-bindings.txt for details. + + +Example: + mipicsi: mipicsi@15002000 { + compatible = "mediatek,mt2712-mipicsi-common", "syscon"; + reg = <0 0x15002000 0 0x10>; + clocks = <&imgsys CLK_IMG_SENINF_CAM_EN>, + <&imgsys CLK_IMG_SENINF_SCAM_EN>; + }; diff --git a/Documentation/devicetree/bindings/media/mediatek-mipicsi.txt b/Documentation/devicetree/bindings/media/mediatek-mipicsi.txt new file mode 100644 index 000000000000..24741ed62b25 --- /dev/null +++ b/Documentation/devicetree/bindings/media/mediatek-mipicsi.txt @@ -0,0 +1,54 @@ +* Mediatek MIPI-CSI2 receiver + +Mediatek MIPI-CSI2 receiver is the MIPI Signal capture hardware present in Mediatek SoCs + +Required properties: +- compatible: should be "mediatek,mt2712-mipicsi" +- reg : physical base address of the mipicsi receiver registers and length of + memory mapped region. +- power-domains: a phandle to the power domain, see + Documentation/devicetree/bindings/power/power_domain.txt for details. +- mediatek,larb: must contain the local arbiters in the current Socs, see + Documentation/devicetree/bindings/memory-controllers/mediatek,smi-larb.txt + for details. +- iommus: should point to the respective IOMMU block with master port as + argument, see Documentation/devicetree/bindings/iommu/mediatek,iommu.txt + for details. +- mediatek,seninf_mux_camsv: seninf_mux_camsv the data go through of the mipicsi port +- mediatek,mipicsiid: the id of the mipicsi port +- mediatek,mipicsi: the common component of the two mipicsi port + +Example: + mipicsi0: mipicsi@10217000 { + compatible = "mediatek,mt2712-mipicsi"; + mediatek,mipicsi = <&mipicsi>; + iommus = <&iommu0 M4U_PORT_CAM_DMA0>, + <&iommu0 M4U_PORT_CAM_DMA1>; + mediatek,larb = <&larb2>; + power-domains = <&scpsys MT2712_POWER_DOMAIN_ISP>; + + mediatek,seninf_mux_camsv = <&seninf1_mux_camsv0 + &seninf2_mux_camsv1 + &seninf3_mux_camsv2 + &seninf4_mux_camsv3>; + reg = <0 0x10217000 0 0x60>, + <0 0x15002100 0 0x4>, + <0 0x15002300 0 0x100>; + mediatek,mipicsiid = <0>; + status="disabled"; + }; + + mipicsi1: mipicsi@10218000 { + compatible = "mediatek,mt2712-mipicsi"; + mediatek,mipicsi = <&mipicsi>; + iommus = <&iommu0 M4U_PORT_CAM_DMA2>; + mediatek,larb = <&larb2>; + power-domains = <&scpsys MT2712_POWER_DOMAIN_ISP>; + mediatek,seninf_mux_camsv = <&seninf5_mux_camsv4 + &seninf6_mux_camsv5>; + reg = <0 0x10218000 0 0x60>, + <0 0x15002500 0 0x4>, + <0 0x15002700 0 0x100>; + mediatek,mipicsiid = <1>; + status="disabled"; + }; \ No newline at end of file From patchwork Tue Apr 16 09:30:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902503 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A98B5161F for ; Tue, 16 Apr 2019 09:44:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8973628591 for ; Tue, 16 Apr 2019 09:44:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7D33828618; Tue, 16 Apr 2019 09:44:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 416CA28591 for ; Tue, 16 Apr 2019 09:44:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=if3OjkXzT7oPxCzcUB7KeelHQXyzRYwQGFMCHqr1bPM=; b=sghuYxJsmZAm0R MngvKS/oYlxOx3A3GBE1pCOUQ+E7ZL/WfB1+QR4NY0emxHfJWL/oNWoHPBRAnZnVrZv+xEZWsul3g aP9IAjnnfhc8DIgpSp/KxTHIhekdOLp19sAdtOlrONEsbsuQA345v9NzbDXWtWPX/DNqaA10A9S1e D/ty0FJKAQ6BrUPENPXA/c+VzrzLvfcoEZ+1I4SDoQvlDcDzz2Ib95qvDgPfW+MBFTdD50jCslBII xbxXF2xdz05WUrdAnxw9q5rljjMzGpIICwjauSjjDk+zqyrNYFoKZjpLHqUGybQzF1ZaA2zu1U/2g jeMfPJh4rlxK149b3dcQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKdu-000595-Ol; Tue, 16 Apr 2019 09:44:42 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKdT-0004Ge-MC; Tue, 16 Apr 2019 09:44:15 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Ua249gcNJoju6hNwfECGXD1u+l3y3vt93ebfLakQtqw=; b=P4dSLx9PFndg0JgegprhVwrtj edKOXarlr9yVQhBxNEa/Oaa+UsZDHTw34Zi/gIibPGylUGPj0f4oQbuPmoDX6BiVdoyfocHWje1ax cRYkYRfLH/9i7lm0WrWTiNPzRM7yyB1OoiEhvfwMC974zd7Etdk3p4sXw8WncEBz0yRzTt66dARpw aZ+JD+d3AXVTDt0RCMQJfCSsdcxPBb9nvirsQmk6q6pmSr1APSUc0kljCaNIXQLIzb7iezA2YHbIe qyL/84OTiWv6xV8EaViccqnfPxwfS9zw3FwS3g8gUfbvSmEWQ/XM8Auqvth2pZtGQwv8OAB+UYjAT 0rmPWI7XA==; Received: from mailgw02.mediatek.com ([216.200.240.185]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQS-0002lZ-SF; Tue, 16 Apr 2019 09:30:52 +0000 X-UUID: 1e6cfe5b2c6c4c6988aa68074425110c-20190416 X-UUID: 1e6cfe5b2c6c4c6988aa68074425110c-20190416 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1313956144; Tue, 16 Apr 2019 01:30:27 -0800 Received: from mtkmbs03n2.mediatek.inc (172.21.101.182) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:30:25 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs03n2.mediatek.inc (172.21.101.182) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 17:30:17 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 17:30:17 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v2 02/15] [media] mtk-mipicsi: add mediatek mipicsi driver for mt2712 Date: Tue, 16 Apr 2019 17:30:02 +0800 Message-ID: <1555407015-18130-3-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> References: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: 7D592B0F8D4B3640168D262C7E2F9C7E007F2E75DC76164832CB6BC268D544132000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_103049_369764_F50FEA6E X-CRM114-Status: GOOD ( 28.76 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add mediatek mipicsi driver for mt2712, including probe function to get the value from device tree, and register to v4l2 the host device. Signed-off-by: Stu Hsieh --- drivers/media/platform/mtk-mipicsi/Makefile | 4 + .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 767 ++++++++++++++++++ 2 files changed, 771 insertions(+) create mode 100644 drivers/media/platform/mtk-mipicsi/Makefile create mode 100644 drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c diff --git a/drivers/media/platform/mtk-mipicsi/Makefile b/drivers/media/platform/mtk-mipicsi/Makefile new file mode 100644 index 000000000000..326a5e3808fa --- /dev/null +++ b/drivers/media/platform/mtk-mipicsi/Makefile @@ -0,0 +1,4 @@ +mtk-mipicsi-y += mtk_mipicsi.o + +obj-$(CONFIG_VIDEO_MEDIATEK_MIPICSI) += mtk-mipicsi.o + diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c new file mode 100644 index 000000000000..e26bebe17fe5 --- /dev/null +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -0,0 +1,767 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2017 MediaTek Inc. + * Author: Ricky Zhang + * Baoyin Zhang + * Alan Yue + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * http://www.gnu.org/licenses/gpl-2.0.html for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_VB2_MEDIATEK_DMA_SG +#include "mtkbuf-dma-cache-sg.h" +#endif + +#define MTK_MIPICSI_DRV_NAME "mtk-mipicsi" +#define MTK_PLATFORM_STR "platform:mt2712" +#define MIPICSI_COMMON_CLK 2 +#define MTK_CAMDMA_MAX_NUM 4U +#define MIPICSI_CLK (MIPICSI_COMMON_CLK + MTK_CAMDMA_MAX_NUM) +#define MTK_DATAWIDTH_8 (0x01U << 7U) +#define MAX_SUPPORT_WIDTH 4096U +#define MAX_SUPPORT_HEIGHT 4096U +#define MAX_BUFFER_NUM 32U +#define VID_LIMIT_BYTES (100U * 1024U * 1024U) + +/* buffer for one video frame */ +struct mtk_mipicsi_buf { + struct list_head queue; + struct vb2_buffer *vb; + dma_addr_t vb_dma_addr_phy; + int prepare_flag; +}; + +struct mtk_mipicsi_dev { + struct soc_camera_host soc_host; + struct platform_device *pdev; + unsigned int camsv_num; + struct v4l2_device v4l2_dev; + struct device *larb_pdev; + void __iomem *ana; + void __iomem *seninf_ctrl; + void __iomem *seninf; + struct regmap *seninf_top; + void __iomem *seninf_mux[MTK_CAMDMA_MAX_NUM]; + void __iomem *camsv[MTK_CAMDMA_MAX_NUM]; + const struct soc_camera_format_xlate *current_fmt; + u16 width_flags; /* max 12 bits */ + struct list_head capture_list[MTK_CAMDMA_MAX_NUM]; + struct list_head fb_list; + spinlock_t lock; + spinlock_t queue_lock; + struct mtk_mipicsi_buf cam_buf[MAX_BUFFER_NUM]; + bool streamon; + unsigned long frame_cnt[MTK_CAMDMA_MAX_NUM]; + unsigned int link; + unsigned long enqueue_cnt; + unsigned long dequeue_cnt; + struct v4l2_ctrl_handler ctrl_hdl; + char drv_name[16]; + u32 id; + int clk_num; + struct clk *clk[MIPICSI_CLK]; +}; + +#define MTK_MIPICSI_BUS_PARAM (V4L2_MBUS_MASTER | \ + V4L2_MBUS_HSYNC_ACTIVE_HIGH | \ + V4L2_MBUS_HSYNC_ACTIVE_LOW | \ + V4L2_MBUS_VSYNC_ACTIVE_HIGH | \ + V4L2_MBUS_VSYNC_ACTIVE_LOW | \ + V4L2_MBUS_PCLK_SAMPLE_RISING | \ + V4L2_MBUS_PCLK_SAMPLE_FALLING | \ + V4L2_MBUS_DATA_ACTIVE_HIGH) + +static int mtk_mipicsi_add_device(struct soc_camera_device *icd) +{ + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + struct v4l2_subdev_format format = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + }; + int ret; + + /* Get width/height info from subdev. Then use them to set register */ + ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &format); + if (ret < 0) { + dev_err(icd->parent, "sub device get_fmt fail\n"); + return ret; + } + + /* + * If power domain was closed before, it will be open. + * Then clock will be open and register will be set + */ + (void)pm_runtime_get_sync(icd->parent); + return 0; +} + +static void mtk_mipicsi_remove_device(struct soc_camera_device *icd) +{ + (void)pm_runtime_put_sync(icd->parent); +} + +static int mtk_mipicsi_set_fmt(struct soc_camera_device *icd, + struct v4l2_format *f) +{ + struct soc_camera_host *ici = to_soc_camera_host(icd->parent); + struct mtk_mipicsi_dev *mipicsi = ici->priv; + struct device *dev = &mipicsi->pdev->dev; + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + const struct soc_camera_format_xlate *xlate = NULL; + struct v4l2_pix_format *pix = &f->fmt.pix; + struct v4l2_subdev_format format = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + }; + struct v4l2_mbus_framefmt *mf = &format.format; + int ret = 0; + + xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); + if (xlate == NULL) { + dev_err(dev, "Format 0x%x not found\n", pix->pixelformat); + return -EINVAL; + } + + mf->width = pix->width; + mf->height = pix->height; + mf->field = pix->field; + mf->colorspace = pix->colorspace; + mf->code = xlate->code; + + ret = v4l2_subdev_call(sd, pad, set_fmt, NULL, &format); + pix->width = mf->width; + pix->height = mf->height; + pix->field = mf->field; + pix->colorspace = mf->colorspace; + icd->current_fmt = xlate; + if (pix->pixelformat == V4L2_PIX_FMT_YUYV) + pix->sizeimage = pix->width * pix->height * 2U; + + if (mf->code != xlate->code) + return -EINVAL; + + return ret; +} + +static int mtk_mipicsi_try_fmt(struct soc_camera_device *icd, + struct v4l2_format *f) +{ + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + const struct soc_camera_format_xlate *xlate = NULL; + struct v4l2_pix_format *pix = &f->fmt.pix; + struct v4l2_subdev_pad_config pad_cfg; + struct v4l2_subdev_format format = { + .which = V4L2_SUBDEV_FORMAT_TRY, + }; + struct v4l2_mbus_framefmt *mf = &format.format; + u32 pixfmt = pix->pixelformat; + int ret = 0; + + xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); + if (xlate == NULL) { + xlate = icd->current_fmt; + dev_dbg(icd->parent, "Format %x not found, keeping %x\n", + pixfmt, xlate->host_fmt->fourcc); + pixfmt = xlate->host_fmt->fourcc; + pix->pixelformat = pixfmt; + pix->colorspace = icd->colorspace; + } + + /* limit to MTK hardware capabilities */ + pix->height = min(pix->height, MAX_SUPPORT_HEIGHT); + pix->width = min(pix->width, MAX_SUPPORT_WIDTH); + + /* limit to sensor capabilities */ + mf->width = pix->width; + mf->height = pix->height; + mf->field = pix->field; + mf->colorspace = pix->colorspace; + mf->code = xlate->code; + + ret = v4l2_subdev_call(sd, pad, set_fmt, &pad_cfg, &format); + if (ret < 0) + return ret; + + pix->width = mf->width; + pix->height = mf->height; + pix->field = mf->field; + pix->colorspace = mf->colorspace; + pix->bytesperline = pix->width * 2U; + pix->sizeimage = pix->bytesperline * pix->height; + + return ret; +} + +static int mtk_mipicsi_vb2_queue_setup(struct vb2_queue *vq, + unsigned int *nbufs, + unsigned int *num_planes, unsigned int sizes[], + struct device *alloc_devs[]) +{ + struct soc_camera_device *icd = soc_camera_from_vb2q(vq); + u32 sizeimage = icd->sizeimage; + + if (*nbufs == 0U || *nbufs > MAX_BUFFER_NUM) + *nbufs = MAX_BUFFER_NUM; + if (sizeimage * *nbufs > VID_LIMIT_BYTES) + *nbufs = VID_LIMIT_BYTES / sizeimage; + + /* + * Called from VIDIOC_REQBUFS or in compatibility mode For YUV422P + * format, even if there are 3 planes Y, U and V, we reply there is only + * one plane, containing Y, U and V data, one after the other. + */ + if (*num_planes != 0U) + return sizes[0] < sizeimage ? -EINVAL : 0; + sizes[0] = sizeimage; + *num_planes = 1; + return 0; +} + +static int mtk_mipicsi_vb2_init(struct vb2_buffer *vb) +{ + struct mtk_mipicsi_dev *mipicsi = vb2_get_drv_priv(vb->vb2_queue); + + mipicsi->cam_buf[vb->index].prepare_flag = 0; + + return 0; +} + +static int mtk_mipicsi_vb2_prepare(struct vb2_buffer *vb) +{ + struct soc_camera_device *icd = NULL; + struct soc_camera_host *ici = NULL; + struct mtk_mipicsi_dev *mipicsi = NULL; + struct mtk_mipicsi_buf *buf; + u32 size = 0; + char *va = NULL; + + /* notice that vb->vb2_queue addr equals to soc_camera_device->vb2_vidq. + * It was handled in reqbufs + */ + icd = soc_camera_from_vb2q(vb->vb2_queue); + ici = to_soc_camera_host(icd->parent); + mipicsi = ici->priv; + buf = &mipicsi->cam_buf[vb->index]; + size = icd->sizeimage; + + if (vb2_plane_size(vb, 0) < size) { + dev_err(icd->parent, "data will not fit into plane (%lu < %u)", + vb2_plane_size(vb, 0), size); + return -EINVAL; + } + + vb2_set_plane_payload(vb, 0, size); + + if ((buf->prepare_flag) == 0) { + buf->prepare_flag = 1; +#ifdef CONFIG_VB2_MEDIATEK_DMA_SG + buf->vb_dma_addr_phy = + mtk_dma_sg_plane_dma_addr(vb, 0); +#else + buf->vb_dma_addr_phy = + vb2_dma_contig_plane_dma_addr(vb, 0); +#endif + va = vb2_plane_vaddr(vb, 0); + buf->vb = vb; + } + + return 0; +} + +static void mtk_mipicsi_vb2_queue(struct vb2_buffer *vb) +{ + struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue); + struct soc_camera_host *ici = to_soc_camera_host(icd->parent); + struct mtk_mipicsi_dev *mipicsi = ici->priv; + char *va = NULL; + + spin_lock(&mipicsi->queue_lock); + list_add_tail(&(mipicsi->cam_buf[vb->index].queue), + &(mipicsi->fb_list)); + spin_unlock(&mipicsi->queue_lock); + + va = vb2_plane_vaddr(vb, 0); + + ++(mipicsi->enqueue_cnt); +} + +static int mtk_mipicsi_vb2_start_streaming(struct vb2_queue *vq, + unsigned int count) +{ + struct soc_camera_device *icd = soc_camera_from_vb2q(vq); + struct soc_camera_host *ici = to_soc_camera_host(icd->parent); + struct mtk_mipicsi_dev *mipicsi = ici->priv; + + icd->vdev->queue = vq; + + mipicsi->streamon = true; + return 0; +} + +static void mtk_mipicsi_vb2_stop_streaming(struct vb2_queue *vq) +{ + struct mtk_mipicsi_dev *mipicsi = vb2_get_drv_priv(vq); + struct mtk_mipicsi_buf *buf = NULL; + struct mtk_mipicsi_buf *tmp = NULL; + unsigned int index = 0; + + spin_lock(&mipicsi->queue_lock); + while (list_empty(&(mipicsi->fb_list)) == 0) { + list_for_each_entry_safe(buf, tmp, &(mipicsi->fb_list), queue) { + if (buf->vb->state == VB2_BUF_STATE_ACTIVE) { + vb2_buffer_done(buf->vb, VB2_BUF_STATE_ERROR); + break; + } + } + buf->vb_dma_addr_phy = 0ULL; + buf->prepare_flag = 0; + index = buf->vb->index; + list_del_init(&(mipicsi->cam_buf[index].queue)); + } + spin_unlock(&mipicsi->queue_lock); + mipicsi->streamon = false; + + INIT_LIST_HEAD(&(mipicsi->fb_list)); + + mipicsi->enqueue_cnt = 0UL; + mipicsi->dequeue_cnt = 0UL; +} + +static struct vb2_ops mtk_vb2_ops = { + .queue_setup = mtk_mipicsi_vb2_queue_setup, + .buf_init = mtk_mipicsi_vb2_init, + .buf_prepare = mtk_mipicsi_vb2_prepare, + .buf_queue = mtk_mipicsi_vb2_queue, + .start_streaming = mtk_mipicsi_vb2_start_streaming, + .stop_streaming = mtk_mipicsi_vb2_stop_streaming, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, +}; + +static int mtk_mipicsi_init_videobuf2(struct vb2_queue *q, + struct soc_camera_device *icd) +{ + struct soc_camera_host *ici = to_soc_camera_host(icd->parent); + struct mtk_mipicsi_dev *mipicsi = ici->priv; + struct mutex *q_lock = NULL; + + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + q->io_modes = VB2_MMAP; + q->drv_priv = mipicsi; + q->buf_struct_size = sizeof(struct vb2_buffer); + q->ops = &mtk_vb2_ops; +#ifdef CONFIG_VB2_MEDIATEK_DMA_SG + q->mem_ops = &mtk_dma_sg_memops; +#else + q->mem_ops = &vb2_dma_contig_memops; +#endif + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; + q->dev = ici->v4l2_dev.dev; + q_lock = devm_kzalloc(mipicsi->soc_host.v4l2_dev.dev, + sizeof(*q_lock), GFP_KERNEL); + q->lock = q_lock; + mutex_init(q->lock); + + return vb2_queue_init(q); +} + +static int mtk_mipicsi_querycap(struct soc_camera_host *ici, + struct v4l2_capability *cap) +{ + struct mtk_mipicsi_dev *mipicsi = ici->priv; + + (void)strlcpy(cap->card, MTK_PLATFORM_STR, sizeof(cap->card)); + (void)strlcpy(cap->driver, mipicsi->drv_name, sizeof(cap->driver)); + (void)strlcpy(cap->bus_info, MTK_PLATFORM_STR, sizeof(cap->bus_info)); + cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; + + return 0; +} + +static int mtk_mipicsi_set_bus_param(struct soc_camera_device *icd) +{ + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,}; + unsigned int common_flags = 0U; + int ret = 0; + + ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg); + if (ret == 0) { + common_flags = soc_mbus_config_compatible(&cfg, + MTK_MIPICSI_BUS_PARAM); + if (common_flags == 0U) { + dev_err(icd->parent, "Flags incompatible: camera 0x%x", + cfg.flags); + return -EINVAL; + } + } else { + if (ret != -ENOIOCTLCMD) + return ret; + } + common_flags = MTK_MIPICSI_BUS_PARAM; + + dev_dbg(icd->parent, "Flags cam: 0x%x common: 0x%x\n", + cfg.flags, common_flags); + + cfg.flags = common_flags; + ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg); + if (ret < 0 && ret != -ENOIOCTLCMD) { + dev_dbg(icd->parent, "camera s_mbus_config(0x%x) returned %d\n", + common_flags, ret); + return ret; + } + + return 0; +} + +static struct soc_camera_host_ops mtk_soc_camera_host_ops = { + .owner = THIS_MODULE, + .add = mtk_mipicsi_add_device, + .remove = mtk_mipicsi_remove_device, + .set_fmt = mtk_mipicsi_set_fmt, + .try_fmt = mtk_mipicsi_try_fmt, + .init_videobuf2 = mtk_mipicsi_init_videobuf2, + .poll = vb2_fop_poll, + .querycap = mtk_mipicsi_querycap, + .set_bus_param = mtk_mipicsi_set_bus_param, +}; + +static int seninf_mux_camsv_node_parse(struct mtk_mipicsi_dev *mipicsi, + int index) +{ + struct clk *clk = NULL; + struct device *dev = NULL; + struct resource *res = NULL; + struct platform_device *camdma_pdev = NULL; + struct platform_device *pdev = NULL; + struct device_node *np = NULL; + + if (mipicsi == NULL) + return -EINVAL; + + dev = &mipicsi->pdev->dev; + pdev = mipicsi->pdev; + + np = of_parse_phandle(dev->of_node, + "mediatek,seninf_mux_camsv", index); + if (np == NULL) { + dev_err(dev, "no NO.%d mediatek,seninf_mux_camsv node\n", + index); + return -ENODEV; + } + + camdma_pdev = of_find_device_by_node(np); + of_node_put(np); + if (camdma_pdev == NULL) { + camdma_pdev = of_platform_device_create(np, NULL, + platform_bus_type.dev_root); + if (camdma_pdev == NULL) + return -EPROBE_DEFER; + } + + clk = of_clk_get(np, 0); + if (clk == NULL) { + dev_err(dev, "get clk fail in %s node\n", np->full_name); + return -ENODEV; + } + mipicsi->clk[index] = clk; + + res = platform_get_resource(camdma_pdev, IORESOURCE_MEM, 0); + if (res == NULL) { + dev_err(dev, "get seninf_mux memory failed in %s node\n", + np->full_name); + return -ENODEV; + } + mipicsi->seninf_mux[index] = + devm_ioremap_resource(&camdma_pdev->dev, res); + + res = platform_get_resource(camdma_pdev, IORESOURCE_MEM, 1); + if (res == NULL) { + dev_err(dev, "get camsv memory failed in %s node\n", + np->full_name); + return -ENODEV; + } + mipicsi->camsv[index] = + devm_ioremap_resource(&camdma_pdev->dev, res); + + INIT_LIST_HEAD(&mipicsi->capture_list[index]); + mipicsi->frame_cnt[index] = 0UL; + + dev_info(dev, "%s parse done\n", np->full_name); + + return 0; +} + +static int mtk_mipicsi_common_node_parse(struct mtk_mipicsi_dev *mipicsi, + struct device_node *node) +{ + int i = 0; + struct regmap *seninf_top = NULL; + struct device *dev = NULL; + struct platform_device *pdev = NULL; + struct clk *clk = NULL; + + if ((mipicsi == NULL) || (node == NULL)) + return -EINVAL; + + dev = &mipicsi->pdev->dev; + pdev = mipicsi->pdev; + + /* All the mipicsi HW share the same seninf_top */ + seninf_top = syscon_regmap_lookup_by_phandle(dev->of_node, + "mediatek,mipicsi"); + if (seninf_top == NULL) { + dev_err(dev, "Missing mediadek,mipicsi in %s node\n", + node->full_name); + return -EINVAL; + } + mipicsi->seninf_top = seninf_top; + + /* get IMG_SENINF_CAM_EN and IMG_SENINF_SCAM_EN clk*/ + mipicsi->clk_num = mipicsi->camsv_num; + + for (i = 0; i < MIPICSI_COMMON_CLK; ++i) { + clk = of_clk_get(node, i); + if (clk == NULL) { + dev_err(dev, "get clk fail in %s node\n", + node->full_name); + return -EINVAL; + } + mipicsi->clk[mipicsi->clk_num] = clk; + ++mipicsi->clk_num; + } + + dev_info(dev, "%s parse done\n", node->full_name); + + return 0; +} + +static int mtk_mipicsi_node_parse(struct mtk_mipicsi_dev *mipicsi) +{ + int ret; + int camsv_num = 0; + int i; + struct device *dev = NULL; + struct resource *res = NULL; + struct device_node *common_node = NULL; + struct platform_device *pdev = NULL; + + if (mipicsi == NULL) + return -EINVAL; + + dev = &mipicsi->pdev->dev; + pdev = mipicsi->pdev; + + /* mediatek,mipicsiid is a flag to show which mipicsi HW */ + ret = of_property_read_u32(dev->of_node, "mediatek,mipicsiid", + (u32 *)&mipicsi->id); + if (ret != 0) { + dev_info(dev, "not set mediatek,mipicsiid, use default id 0\n"); + mipicsi->id = 0; + } + (void)sprintf(mipicsi->drv_name, MTK_MIPICSI_DRV_NAME"%d", + mipicsi->id); + + /* get and parse seninf_mux_camsv */ + camsv_num = of_count_phandle_with_args(dev->of_node, + "mediatek,seninf_mux_camsv", NULL); + if (camsv_num <= 0) { + dev_err(dev, "no mediatek,seninf_mux_camsv\n"); + return -EINVAL; + } + mipicsi->camsv_num = camsv_num; + dev_info(dev, "there are %d camsv node\n", camsv_num); + + for (i = 0; i < mipicsi->camsv_num; ++i) { + ret = seninf_mux_camsv_node_parse(mipicsi, i); + if ((ret < 0) && (ret != -EPROBE_DEFER)) { + dev_err(dev, + "NO.%d seninf_mux_camsv node parse fail\n", i); + return ret; + } + } + + /* get mediatek,mipicsi node and its resource */ + common_node = of_parse_phandle(dev->of_node, "mediatek,mipicsi", 0); + if (common_node == NULL) { + dev_err(dev, "no mediadek,mipicsi\n"); + return -EINVAL; + } + + ret = mtk_mipicsi_common_node_parse(mipicsi, common_node); + if (ret < 0) + return ret; + + /*get ana and seninf reg*/ + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (res == NULL) { + dev_err(dev, "get ana register failed\n"); + return -ENODEV; + } + mipicsi->ana = devm_ioremap_resource(&pdev->dev, res); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); + if (res == NULL) { + dev_err(dev, "get seninf_ctrl register failed\n"); + return -ENODEV; + } + mipicsi->seninf_ctrl = devm_ioremap_resource(&pdev->dev, res); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 2); + if (res == NULL) { + dev_err(dev, "get seninf register failed\n"); + return -ENODEV; + } + mipicsi->seninf = devm_ioremap_resource(&pdev->dev, res); + + dev_info(dev, "mipicsi node parse done\n"); + + return 0; +} + +static int mtk_mipicsi_probe(struct platform_device *pdev) +{ + struct mtk_mipicsi_dev *mipicsi = NULL; + int ret = 0; + struct iommu_domain *iommu = NULL; + struct device_node *larb_node = NULL; + struct platform_device *larb_pdev = NULL; + + iommu = iommu_get_domain_for_dev(&pdev->dev); + if (iommu == NULL) { + dev_err(&pdev->dev, "Waiting iommu driver ready...\n"); + return -EPROBE_DEFER; + } + + larb_node = of_parse_phandle(pdev->dev.of_node, "mediatek,larb", 0); + if (larb_node == NULL) { + dev_err(&pdev->dev, "Missing mediadek,larb in %s node\n", + pdev->dev.of_node->full_name); + return -EINVAL; + } + + larb_pdev = of_find_device_by_node(larb_node); + if (larb_pdev == NULL || !larb_pdev->dev.driver) { + dev_err(&pdev->dev, "Waiting for larb device %s\n", + larb_node->full_name); + return -EPROBE_DEFER; + } + of_node_put(larb_node); + + mipicsi = devm_kzalloc(&pdev->dev, sizeof(*mipicsi), GFP_KERNEL); + if (mipicsi == NULL) + return -ENOMEM; + + mipicsi->pdev = pdev; + mipicsi->larb_pdev = &larb_pdev->dev; + + ret = mtk_mipicsi_node_parse(mipicsi); + if (ret < 0) + return ret; + + pm_runtime_enable(&pdev->dev); + + mipicsi->soc_host.drv_name = mipicsi->drv_name; + mipicsi->soc_host.ops = &mtk_soc_camera_host_ops; + mipicsi->soc_host.priv = mipicsi; + mipicsi->soc_host.v4l2_dev.dev = &pdev->dev; + mipicsi->soc_host.nr = mipicsi->id; + mipicsi->width_flags = MTK_DATAWIDTH_8; + mipicsi->streamon = false; + + ret = soc_camera_host_register(&mipicsi->soc_host); + if (ret < 0) { + dev_err(&pdev->dev, "soc camera host register fail\n"); + pm_runtime_disable(&pdev->dev); + return ret; + } + + INIT_LIST_HEAD(&mipicsi->fb_list); + spin_lock_init(&mipicsi->queue_lock); + spin_lock_init(&mipicsi->lock); + mipicsi->enqueue_cnt = 0UL; + mipicsi->dequeue_cnt = 0UL; + +#ifdef CONFIG_VB2_MEDIATEK_DMA_SG + ret = mtk_dma_sg_init_ctx(&pdev->dev); +#else + ret = vb2_dma_contig_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32U)); +#endif + if (ret != 0) { + dev_err(&pdev->dev, "dma set max seg size fail\n"); + goto clean; + } + + dev_info(&pdev->dev, "probe done\n"); + return ret; +clean: + soc_camera_host_unregister(&mipicsi->soc_host); + pm_runtime_disable(&pdev->dev); + return ret; +} + +static int mtk_mipicsi_remove(struct platform_device *pdev) +{ + struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev); + + soc_camera_host_unregister(soc_host); + pm_runtime_disable(&pdev->dev); + + return 0; +} + +static const struct of_device_id mtk_mipicsi_of_match[] = { + { .compatible = "mediatek,mt2712-mipicsi", }, + {}, +}; + +static struct platform_driver mtk_mipicsi_driver = { + .driver = { + .name = MTK_MIPICSI_DRV_NAME, + .of_match_table = of_match_ptr(mtk_mipicsi_of_match), + }, + .probe = mtk_mipicsi_probe, + .remove = mtk_mipicsi_remove, +}; + +module_platform_driver(mtk_mipicsi_driver); +MODULE_DESCRIPTION("MediaTek SoC Camera Host driver"); +MODULE_LICENSE("GPL v2"); From patchwork Tue Apr 16 09:30:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902565 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33E7F161F for ; Tue, 16 Apr 2019 09:59:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CDF92882E for ; Tue, 16 Apr 2019 09:59:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10101288DC; Tue, 16 Apr 2019 09:59:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7247C2892D for ; Tue, 16 Apr 2019 09:59:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=65mLxc9RvkGot5bPGTZMPuZEtZW0IXgwJwz6d6NqURI=; b=AkJjdvMnOjnnC1 XTuzWuuAIUwqHk8/xej5cqTSlW/knrWWBuvU48Or/CAZi7Fya5pDD8WZZU9bzA3zyFvtgeM6iWrmX 7bX85V1DfM5rGumwp4YiYRUHyDvZDRQ1VQxTzXL7o+SISu8w912c9UmpFoD+ZWPtAza4JKAM1NBUD DjaIZpHa/YCXGJPP0tVwkaJc4ISVS4eK7KRVoGcxGeocxe4ZKldfj+dx0PmZgbA6qvVWkBiBaPgrn Kddu54BFH3px1Ysf8Gmwp+AscwQ5zuGuTJuXNmPw05Py/uU9Jx8/EDZ6sNAex7ShaWavGYg7VEcNa Tdl5lvilp72l3tyCIuag==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKs9-0003ec-Mi; Tue, 16 Apr 2019 09:59:25 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKdY-0004By-15 for linux-mediatek@bombadil.infradead.org; Tue, 16 Apr 2019 09:44:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=SqSJf1qx+QuLCgAXmpSaiW9+NBfayUhxGOHTonm2zhc=; b=BiOxRySJxkcnoJ/FDnqZ+cjAW BtGvonSO7o1oPKIyKAdfa6mfqzr7wWiONJMREYasTUs5APXeZGveUePm2R1Yu193zP288PXwxc6HS CimK5fNVVA0MYX523FhK9qA1ap1AImgbCRbzCAREcp3gTYgQC8f4Adfi7knETFzF0I5sHOMMjXwpx l9UCe18dnowIxqG6u493HYlGCkxDyKbQCFsKLFdyrmdYOo2Rm50XSMBTOdrhvELXJjj6swEcaPayA T7F7YSHM0ki7rm0HGOI5aK/voEFXyvMVVVasOd2soixm9e5DfBNmLFrPiQnajAGNLtMeOiiNZWAHZ 4Q4tg6lwA==; Received: from mailgw02.mediatek.com ([216.200.240.185]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQI-0002lY-Cm for linux-mediatek@lists.infradead.org; Tue, 16 Apr 2019 09:30:40 +0000 X-UUID: fdf13d437a7142f388dcdddd390efd85-20190416 X-UUID: fdf13d437a7142f388dcdddd390efd85-20190416 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 995971912; Tue, 16 Apr 2019 01:30:20 -0800 Received: from MTKMBS01N2.mediatek.inc (172.21.101.79) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:30:19 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 17:30:17 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 17:30:17 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v2 03/15] [media] mtk-mipicsi: add pm function Date: Tue, 16 Apr 2019 17:30:03 +0800 Message-ID: <1555407015-18130-4-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> References: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: 48967CEB63FF91E327FD0A2DCBA22904CA4C750A69FB2313E50D2B42E8D872CA2000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_103038_730016_BA493C06 X-CRM114-Status: GOOD ( 17.53 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add PM function to enable/disable clk and larb. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index e26bebe17fe5..ec4f6b503b32 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -464,6 +464,85 @@ static struct soc_camera_host_ops mtk_soc_camera_host_ops = { .set_bus_param = mtk_mipicsi_set_bus_param, }; +static int mtk_mipicsi_pm_suspend(struct device *dev) +{ + struct soc_camera_host *ici = to_soc_camera_host(dev); + struct mtk_mipicsi_dev *mipicsi = NULL; + int ret = 0; + int i = 0; + + mipicsi = container_of(ici, struct mtk_mipicsi_dev, soc_host); + if (mipicsi->soc_host.icd != NULL) { + struct v4l2_subdev *sd = + soc_camera_to_subdev(mipicsi->soc_host.icd); + + ret = v4l2_subdev_call(sd, core, s_power, 0); + if (ret == -ENOIOCTLCMD) + ret = 0; + } + + /* close digtal and analog clock */ + for (i = 0; i < mipicsi->clk_num; ++i) + clk_disable_unprepare(mipicsi->clk[i]); + + if (mipicsi->larb_pdev != NULL) + mtk_smi_larb_put(mipicsi->larb_pdev); + + return ret; +} + +static int mtk_mipicsi_suspend(struct device *dev) +{ + if (pm_runtime_suspended(dev)) + return 0; + + return mtk_mipicsi_pm_suspend(dev); +} + +static int mtk_mipicsi_pm_resume(struct device *dev) +{ + struct soc_camera_host *ici = to_soc_camera_host(dev); + struct mtk_mipicsi_dev *mipicsi = + container_of(ici, struct mtk_mipicsi_dev, soc_host); + int ret = 0; + int i = 0; + + if (mipicsi->soc_host.icd != NULL) { + struct v4l2_subdev *sd = + soc_camera_to_subdev(mipicsi->soc_host.icd); + + ret = v4l2_subdev_call(sd, core, s_power, 1); + if (ret == -ENOIOCTLCMD) + ret = 0; + } + + if (mipicsi->larb_pdev != NULL) { + ret = mtk_smi_larb_get(mipicsi->larb_pdev); + if (ret != 0) + return ret; + } + + /* enable digtal clock */ + for (i = 0; i < mipicsi->clk_num; ++i) + (void)clk_prepare_enable(mipicsi->clk[i]); + + return ret; +} + +static int mtk_mipicsi_resume(struct device *dev) +{ + if (pm_runtime_suspended(dev)) + return 0; + + return mtk_mipicsi_pm_resume(dev); +} + +static const struct dev_pm_ops mtk_mipicsi_pm = { + SET_SYSTEM_SLEEP_PM_OPS(mtk_mipicsi_suspend, mtk_mipicsi_resume) + SET_RUNTIME_PM_OPS(mtk_mipicsi_pm_suspend, + mtk_mipicsi_pm_resume, NULL) +}; + static int seninf_mux_camsv_node_parse(struct mtk_mipicsi_dev *mipicsi, int index) { @@ -756,6 +835,7 @@ static const struct of_device_id mtk_mipicsi_of_match[] = { static struct platform_driver mtk_mipicsi_driver = { .driver = { .name = MTK_MIPICSI_DRV_NAME, + .pm = &mtk_mipicsi_pm, .of_match_table = of_match_ptr(mtk_mipicsi_of_match), }, .probe = mtk_mipicsi_probe, From patchwork Tue Apr 16 09:30:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902407 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2C08A1823 for ; Tue, 16 Apr 2019 09:32:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1294C2892A for ; Tue, 16 Apr 2019 09:32:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 074742892C; Tue, 16 Apr 2019 09:32:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ACD992892A for ; Tue, 16 Apr 2019 09:32:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=jfT78p0QuVmqh0pAbCdoNwnUCiHmvzuRwUtiiXwOztk=; b=AQLyc7WJXnisPY EXihCyO3FpyOEycOdxwK+Er3FkxzI3JD9iDoxbzE2F3TnnmZv1+Kz8Z79k+7l2lDI9d7lqOriA2Xa kvU36CJOuKE0Dwk2G+aCJIU1rrIf1M863Zz/16ryQM+5Gisp3061KF5RNCczJbRqkGuETwdPZ1rnm ZGqa3uK6fTEAcldpUe47A7YcZgOj8S+2FHiUOWVTAC2cgBoQVmwfhi3oeP0ddqnN0SEVLsITZ1VQR cvi35sTVRrsp5z03SD8sSy/hihybbAcK+5ydKd9YfM4UKrC0tBcSldE6YoxpYyYiWT0YdoIqw680E DmityLe3FwfohVoC37XA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKS0-0007F5-JB; Tue, 16 Apr 2019 09:32:24 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQN-0005Nt-JB; Tue, 16 Apr 2019 09:30:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=k0O7t7IRDd+sGsmjG2cdH8o80Apal8RF0adrbe+yTUM=; b=TWy/VgTw+h1H8/Vom+LbgjHzd xMSdwjbUXWcxyAD+hvUnlGc9BSm23B4RN9DCYnIdTB7eCuHRumkEwkfUSqvhln0/G40V1AZ5YM7ns pRSJCpw6ljthpkZvR71XQXwPbDjTJiulXvhkoF8O8IaiZl1W7j/r7DHIRgUYJdmOoz7AJz+GJHHKa VPRuw+12MQgtnY1f6W5B1FAi3HKnvm3sBeWEI26fKF+/okwpo8uI0mQIH3HsM/Ongenp3RZCy1utV 5EGPPNgJ6TwdT+EPUiDgCmgN/MJ0WzOTxjtaubMq9cUZqnuu2gczPOVrOAAMqWPgo3ayQ8YIwpvMU vRZxe4TjA==; Received: from mailgw01.mediatek.com ([216.200.240.184]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQK-0001GE-OO; Tue, 16 Apr 2019 09:30:41 +0000 X-UUID: bf856686b910414b9cb69c44f99d2e3e-20190416 X-UUID: bf856686b910414b9cb69c44f99d2e3e-20190416 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1396419861; Tue, 16 Apr 2019 01:30:20 -0800 Received: from mtkmbs03n1.mediatek.inc (172.21.101.181) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:30:19 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs03n1.mediatek.inc (172.21.101.181) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 17:30:17 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 17:30:17 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v2 04/15] [media] mtk-mipicsi: add color format support for mt2712 Date: Tue, 16 Apr 2019 17:30:04 +0800 Message-ID: <1555407015-18130-5-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> References: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_053040_981567_BFF6BDAF X-CRM114-Status: GOOD ( 13.94 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add color format support for mt2712 Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index ec4f6b503b32..16f6bc480f4e 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -138,6 +138,20 @@ static void mtk_mipicsi_remove_device(struct soc_camera_device *icd) (void)pm_runtime_put_sync(icd->parent); } +static bool is_supported(const u32 pixformat) +{ + switch (pixformat) { + /* YUV422 */ + case V4L2_PIX_FMT_YUYV: + case V4L2_PIX_FMT_UYVY: + case V4L2_PIX_FMT_YVYU: + case V4L2_PIX_FMT_VYUY: + return true; + } + + return false; +} + static int mtk_mipicsi_set_fmt(struct soc_camera_device *icd, struct v4l2_format *f) { @@ -153,6 +167,12 @@ static int mtk_mipicsi_set_fmt(struct soc_camera_device *icd, struct v4l2_mbus_framefmt *mf = &format.format; int ret = 0; + if (!is_supported(pix->pixelformat)) { + dev_err(dev, "Format %x not support. set V4L2_PIX_FMT_YUYV as default\n", + pix->pixelformat); + pix->pixelformat = V4L2_PIX_FMT_YUYV; + } + xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); if (xlate == NULL) { dev_err(dev, "Format 0x%x not found\n", pix->pixelformat); From patchwork Tue Apr 16 09:30:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902549 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2A9391390 for ; Tue, 16 Apr 2019 09:45:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0E31F28591 for ; Tue, 16 Apr 2019 09:45:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0264C28892; Tue, 16 Apr 2019 09:45:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A8E2E28591 for ; Tue, 16 Apr 2019 09:45:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=S3A1EQ27iyEcXSOOo2AR7arYPE5aGZY3e1vADgHp3cE=; b=p74nBRTsy/x8v3 uhWys+cU74I+kthryHVSUM4k/QdESJZT+bjuXTMjFtMLApoMHdyY+Q9KrOaNHYGIZrSUCDgEg2Xeq V5t+00zPLulZ+h72co+Gez7QnrkGv/Cekx6iSgS0nOxpY60u6et36VgryXlZ69H1U2gXh/eQk3I5K 7uqS45O9poVMrVk3jmNlr/flI2x76L85rdQ1ERZwkz0XGBcgOOClHg3i11OhNEdHUilyuGNrpkjbY Cc/hiDMutq8QM9WQh077GQwUb0BheQX62DyHrEk2wqsBLDQ40JHQT4oJD9GWQxBIVPjRyJjCfiyPa jh0p1JjZm9EBRKTtK0fQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKec-000732-Pe; Tue, 16 Apr 2019 09:45:26 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKdX-0004CA-55 for linux-mediatek@bombadil.infradead.org; Tue, 16 Apr 2019 09:44:19 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=0gPtp+gJZKIkqYek8K7UdudTtS67Vg+0T4GNPtowu8A=; b=nHfqRluZHQAVQC1Xwn/HfFtdH 2lyTw7BxhB+tQEXY544bjJ8X9KSXpqWjMijcgU2weILyVww3RjBzpjkV0qU3pjSnTNwGyIAl4aTWH MM0RXfy3mbg4mKgXhxg1NkajZuxbCQKHua1qfoaG817ydKmEGsMgB9/p9mSTabbRlw/tuIzqz95eO OG5FCbhTk/46kxLz/QUv2yiR7Klw7ybddAeEqjsAEazEgVO7U6moEVpGkVU3nmxs+WZiT0SmU66W/ grf+byFyRFv1Zfg0T/3PS8rk4J8lHXXHzRhzhRoXU2atxxY5dPg2IgFZGri3lQoiIeNZqvL8CplHI vEXmcGYxQ==; Received: from mailgw02.mediatek.com ([216.200.240.185]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQJ-0002lZ-Te for linux-mediatek@lists.infradead.org; Tue, 16 Apr 2019 09:30:42 +0000 X-UUID: 381496c786034226b1f375b8f302d469-20190416 X-UUID: 381496c786034226b1f375b8f302d469-20190416 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 30651575; Tue, 16 Apr 2019 01:30:20 -0800 Received: from MTKMBS01N1.mediatek.inc (172.21.101.68) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:30:19 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 17:30:17 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 17:30:17 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v2 05/15] [media] mtk-mipicsi: get the w/h/bytepwerline for mtk_mipicsi Date: Tue, 16 Apr 2019 17:30:05 +0800 Message-ID: <1555407015-18130-6-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> References: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_103040_263843_D09DAE9E X-CRM114-Status: GOOD ( 15.66 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch get the w/h/bytepwerline to save in mtk_mipicsi. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 16f6bc480f4e..10782fccca79 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -99,6 +99,9 @@ struct mtk_mipicsi_dev { u32 id; int clk_num; struct clk *clk[MIPICSI_CLK]; + u32 width; + u32 height; + u32 bytesperline; }; #define MTK_MIPICSI_BUS_PARAM (V4L2_MBUS_MASTER | \ @@ -110,13 +113,36 @@ struct mtk_mipicsi_dev { V4L2_MBUS_PCLK_SAMPLE_FALLING | \ V4L2_MBUS_DATA_ACTIVE_HIGH) +static u32 get_bytesperline(const u32 fmt, const u32 width) +{ + u32 bytesperline = 0; + + switch (fmt) { + case MEDIA_BUS_FMT_UYVY8_2X8: + case MEDIA_BUS_FMT_VYUY8_2X8: + case MEDIA_BUS_FMT_YUYV8_2X8: + case MEDIA_BUS_FMT_YVYU8_2X8: + bytesperline = width * 2U; + break; + default: + break; + } + + return bytesperline; +} + static int mtk_mipicsi_add_device(struct soc_camera_device *icd) { + struct soc_camera_host *ici = to_soc_camera_host(icd->parent); + struct mtk_mipicsi_dev *mipicsi = ici->priv; struct v4l2_subdev *sd = soc_camera_to_subdev(icd); struct v4l2_subdev_format format = { .which = V4L2_SUBDEV_FORMAT_ACTIVE, }; int ret; + u32 width; + u32 height; + u32 fmt; /* Get width/height info from subdev. Then use them to set register */ ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &format); @@ -125,6 +151,19 @@ static int mtk_mipicsi_add_device(struct soc_camera_device *icd) return ret; } + width = format.format.width; + height = format.format.height; + fmt = format.format.code; + mipicsi->bytesperline = get_bytesperline(fmt, width); + if ((width == 0U) || (height == 0U) || (mipicsi->bytesperline == 0U)) { + dev_err(icd->parent, "invalid sub device width/height/bytesperline %d/%d/%d\n", + width, height, mipicsi->bytesperline); + return -EINVAL; + } + + mipicsi->width = width; + mipicsi->height = height; + /* * If power domain was closed before, it will be open. * Then clock will be open and register will be set From patchwork Tue Apr 16 09:30:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902515 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3D33D18FD for ; Tue, 16 Apr 2019 09:44:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2884A285E2 for ; Tue, 16 Apr 2019 09:44:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C4EF28673; Tue, 16 Apr 2019 09:44:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 98BB1285E2 for ; Tue, 16 Apr 2019 09:44:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pJ/JhwbTl8jgoNURXb7wO4jzMq02J4KuuC9yJKyp9mY=; b=SqKNP3FBz/WlKJ RshdagpMBA2olg8D5CLyozyF+zUEg+779BlMlXZb9DhT/XpzFugFtMAU5N5hO2rThKbduUTLPfKi3 mEh1ooMPOQNy9r4Vysz9NJk6GRhwZtJJVQ/alG39JsBE5stzSRDwfQRBPNBJRs9sUptSAp3oeAV/Y zig+pa5JW9fV97lt1gf+lkPvOvHGwQNeQRru7PBrfYe4YNkxTbPXC6QwkDuqt63b+pyoSfnfANIRp 0DwA7tQw6sz9VAHWC+aNe+nRURIKGeK1Y2ZWgD9BXgPcjYmzuJrh/QqwsrzD6EPxIFUVCYXbS3Qih zUmd6bXRd1bMqmFMYK3w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKe4-0005LI-4O; Tue, 16 Apr 2019 09:44:52 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQ5-00051p-H5; Tue, 16 Apr 2019 09:30:54 +0000 X-UUID: 5e7829d40f9e4746ab13ef3ae99983fe-20190416 X-UUID: 5e7829d40f9e4746ab13ef3ae99983fe-20190416 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1235340760; Tue, 16 Apr 2019 01:30:21 -0800 Received: from MTKMBS01N1.mediatek.inc (172.21.101.68) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:30:19 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 17:30:18 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 17:30:18 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v2 06/15] [media] mtk-mipicsi: add function to support SerDes for link number Date: Tue, 16 Apr 2019 17:30:06 +0800 Message-ID: <1555407015-18130-7-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> References: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_023026_048847_7223DDE1 X-CRM114-Status: GOOD ( 14.43 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add function to support SerDes for link number. Mt2712 can server at most four camera link for each mipicsi port. Therefore, driver need to know how many camera link in SerDes and set the mipicsi HW to serve. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 10782fccca79..ec05f3b38cc9 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -56,12 +56,16 @@ #define MIPICSI_COMMON_CLK 2 #define MTK_CAMDMA_MAX_NUM 4U #define MIPICSI_CLK (MIPICSI_COMMON_CLK + MTK_CAMDMA_MAX_NUM) +#define MAX_DES_LINK 4U +#define SUBDEV_LINK_REG 0x49 #define MTK_DATAWIDTH_8 (0x01U << 7U) #define MAX_SUPPORT_WIDTH 4096U #define MAX_SUPPORT_HEIGHT 4096U #define MAX_BUFFER_NUM 32U #define VID_LIMIT_BYTES (100U * 1024U * 1024U) +#define SerDes_support 1 + /* buffer for one video frame */ struct mtk_mipicsi_buf { struct list_head queue; @@ -92,6 +96,7 @@ struct mtk_mipicsi_dev { bool streamon; unsigned long frame_cnt[MTK_CAMDMA_MAX_NUM]; unsigned int link; + u8 link_reg_val; unsigned long enqueue_cnt; unsigned long dequeue_cnt; struct v4l2_ctrl_handler ctrl_hdl; @@ -113,6 +118,64 @@ struct mtk_mipicsi_dev { V4L2_MBUS_PCLK_SAMPLE_FALLING | \ V4L2_MBUS_DATA_ACTIVE_HIGH) +static int get_subdev_register(const struct soc_camera_device *icd, + struct v4l2_dbg_register *reg) +{ + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + int ret = 0; + + reg->match.type = V4L2_CHIP_MATCH_SUBDEV; + reg->match.addr = 0; + ret = v4l2_subdev_call(sd, core, g_register, reg); + if (ret != 2) { + dev_err(icd->parent, "mipicsi get des register 0x%llx fail, ret=%d\n", + reg->reg, ret); + return -EIO; + } + + dev_info(icd->parent, "read DES [reg/val/ret] is [0x%llx/0x%llx/%d]\n", + reg->reg, reg->val, ret); + return ret; +} + +static int get_subdev_link(const struct soc_camera_device *icd, + unsigned int *link, u8 *link_reg_val) +{ + struct v4l2_dbg_register reg; + int ret = 0; + unsigned int index = 0U; + *link_reg_val = 0x0U; + + if (SerDes_support == 0) { + *link = 1; + *link_reg_val = 0x1; + dev_info(icd->parent, "subdev not support SerDes\n"); + return 0; + } + + if (link == NULL) + return -EINVAL; + + memset(®, 0, sizeof(reg)); + /*get camera link number*/ + reg.reg = SUBDEV_LINK_REG; + ret = get_subdev_register(icd, ®); + if (ret < 0) + return ret; + + *link = 0U; + for (index = 0U; index < MAX_DES_LINK; ++index) { + if ((reg.val & 0x01U) == 0x01U) { + *link += 1U; + *link_reg_val |= (0x01U << index); + } + reg.val >>= 1U; + } + + dev_info(icd->parent, "%u camera linked to sub device\n", *link); + return 0; +} + static u32 get_bytesperline(const u32 fmt, const u32 width) { u32 bytesperline = 0; @@ -144,6 +207,7 @@ static int mtk_mipicsi_add_device(struct soc_camera_device *icd) u32 height; u32 fmt; + (void)get_subdev_link(icd, &mipicsi->link, &mipicsi->link_reg_val); /* Get width/height info from subdev. Then use them to set register */ ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &format); if (ret < 0) { From patchwork Tue Apr 16 09:30:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902411 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5000F1823 for ; Tue, 16 Apr 2019 09:32:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3349F2892B for ; Tue, 16 Apr 2019 09:32:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2721428931; Tue, 16 Apr 2019 09:32:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 997592892B for ; Tue, 16 Apr 2019 09:32:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=mF/QFspRcHey1KJl+zVE+7xGRX+87IakVGdebxnZslI=; b=Ua2nxQ9sRftVIt zIj/+S5x04HVJjO+xQc6wp2NmFZave3vc7MLgHZXqGOybZ7reIor6QiZUsayJWXTbXAHpWaUl42aJ JHNaVvtJJ3FFS0otaOo0f+XoKtgDI5Dd+pVy3OPtat3DEADFEPCH9U+qmwxRrxGbP4dREWetJDSTD UGXGZIsR0KbBdfsWYNMOm65I1Cvg8oLi0BXmeYIpFZqcZnB+jIxqDYzZ7OH272qci8HiGGcH8hfwp ZkBTx95Helm5I25OqELiXk3P+rBsbQ51R1jvS9QdUUfuzgr5kgmKCG7eUdb6UBvpgHy0S2iE+RYyH ps0B2j6ebn542OgvLnAQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKS3-0007Iy-5g; Tue, 16 Apr 2019 09:32:27 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQR-0005T5-HQ; Tue, 16 Apr 2019 09:30:47 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=+YhS+XBd4FLDWboCT5jmWUIrKrzHeOXWdIFTwLEhJgk=; b=2mdT9DZJkjJugMgBH/kIYeuyu 8E61nCW3B4vQpq33JONAnuy+E/tqeOd7IZIUPawOURu5Ysp6Keg/y1WwsetI0fqm2/FNXgHGcFHCh RF1qP91lKXkr/RYwXQ2lYH70Tz/eVrAJ5B6CUKPxmcV5gcXAjQ7RvJlhqQ9712U+MpTI3zh6Tpovs 0UUBfDtSEeriZKE8UfNSzmfBuiNnOE0loZapM7gQ5H7YqLrrJUr7TCJ5y/gi6kMunqWO11re3DI4y 55z52uWFxnRsojAGjD0yTDXzyqk23bADwEF1U0ulypRbm5bqK1YdLwW+gE5JO/uxYioLekbts7ZBD b9qfXtS8w==; Received: from mailgw01.mediatek.com ([216.200.240.184]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQO-0001GE-No; Tue, 16 Apr 2019 09:30:45 +0000 X-UUID: bdc8eb73e7fa4618902a46ff5f80a6e0-20190416 X-UUID: bdc8eb73e7fa4618902a46ff5f80a6e0-20190416 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 317271254; Tue, 16 Apr 2019 01:30:21 -0800 Received: from MTKMBS01N2.mediatek.inc (172.21.101.79) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:30:20 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 17:30:18 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 17:30:18 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v2 07/15] [media] mtk-mipicsi: add mipicsi reg setting for mt2712 Date: Tue, 16 Apr 2019 17:30:07 +0800 Message-ID: <1555407015-18130-8-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> References: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: E3B4B39F18F378CD8B058496A2FEF828A9B9924E9DF33ED88BBEEA59B4F244AF2000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_053045_006226_B048262B X-CRM114-Status: GOOD ( 16.43 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add mipicsi register setting to HW for mt2712 Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 189 ++++++++++++++++++ 1 file changed, 189 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index ec05f3b38cc9..c92ffe6684ef 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -64,6 +64,51 @@ #define MAX_BUFFER_NUM 32U #define VID_LIMIT_BYTES (100U * 1024U * 1024U) +#define MIPI_RX_ANA00_CSI 0x00 +#define MIPI_RX_ANA04_CSI 0x04 +#define MIPI_RX_ANA08_CSI 0x08 +#define MIPI_RX_ANA0C_CSI 0x0c +#define MIPI_RX_ANA10_CSI 0x10 +#define MIPI_RX_ANA20_CSI 0x20 +#define MIPI_RX_ANA24_CSI 0x24 +#define MIPI_RX_ANA4C_CSI 0x4c +#define MIPI_RX_ANA50_CSI 0x50 + +#define SENINF_CTRL 0x00 + +#define SENINF_NCSI2_CAL_24 0x24 +#define SENINF_NCSI2_CAL_38 0x38 +#define SENINF_NCSI2_CAL_3C 0x3C +#define SENINF_NCSI2_CTL 0xA0 +#define SENINF_NCSI2_LNRD_TIMING 0xA8 +#define SENINF_NCSI2_INT_EN 0xB0 +#define SENINF_NCSI2_INT_STATUS 0xB4 +#define SENINF_NCSI2_DBG_SEL 0xB8 +#define SENINF_NCSI2_HSRX_DBG 0xD8 +#define SENINF_NCSI2_DI 0xDC +#define SENINF_NCSI2_DI_CTRL 0xE4 + +#define SENINF_TOP_CTRL 0x00 +#define SENINF_TOP_CMODEL_PAR 0x04 +#define SENINF_TOP_MUX 0x08 + +#define SENINF_MUX_CTRL 0x00 + +#define CAMSV_MODULE_EN 0x10 +#define CAMSV_FMT_SEL 0x14 +#define CAMSV_INT_EN 0x18 +#define CAMSV_CLK_EN 0x30 + +#define CAMSV_TG_SEN_MODE 0x500 +#define CAMSV_TG_SEN_GRAB_PXL 0x508 +#define CAMSV_TG_SEN_GRAB_LIN 0x50C +#define CAMSV_TG_PATH_CFG 0x510 + +#define IMGO_XSIZE 0x230 +#define IMGO_YSIZE 0x234 +#define IMGO_STRIDE 0x238 +#define DMA_FRAME_HEADER_EN 0xE00 + #define SerDes_support 1 /* buffer for one video frame */ @@ -587,6 +632,149 @@ static struct soc_camera_host_ops mtk_soc_camera_host_ops = { .set_bus_param = mtk_mipicsi_set_bus_param, }; +static void mtk_mipicsi_ana_init(void __iomem *base) +{ + writel(0xFEFBEFBEU & readl(base + MIPI_RX_ANA4C_CSI), + base + MIPI_RX_ANA4C_CSI); + writel(0xFEFBEFBEU & readl(base + MIPI_RX_ANA50_CSI), + base + MIPI_RX_ANA50_CSI); + + /* clock lane and lane0-lane3 input select */ + writel(8UL | readl(base + MIPI_RX_ANA00_CSI), + base + MIPI_RX_ANA00_CSI); + writel(8UL | readl(base + MIPI_RX_ANA04_CSI), + base + MIPI_RX_ANA04_CSI); + writel(8UL | readl(base + MIPI_RX_ANA08_CSI), + base + MIPI_RX_ANA08_CSI); + writel(8UL | readl(base + MIPI_RX_ANA0C_CSI), + base + MIPI_RX_ANA0C_CSI); + writel(8UL | readl(base + MIPI_RX_ANA10_CSI), + base + MIPI_RX_ANA10_CSI); + + /* BG chopper clock and CSI BG enable */ + writel(11UL | readl(base + MIPI_RX_ANA24_CSI), + base + MIPI_RX_ANA24_CSI); + mdelay(1); + + /* LDO core bias enable */ + writel(0xFF030003U | readl(base + MIPI_RX_ANA20_CSI), + base + MIPI_RX_ANA20_CSI); + mdelay(1); +} + +static void mtk_mipicsi_seninf_ctrl_init(void __iomem *base) +{ + /*seninf enable. select NCSI2 as seninif input source */ + writel(0x8001U, base + SENINF_CTRL); +} + +static void mtk_mipicsi_seninf_init(void __iomem *base) +{ + writel(1U, base + SENINF_NCSI2_CAL_38); + writel(0x00051545U, base + SENINF_NCSI2_CAL_3C); + writel(5U, base + SENINF_NCSI2_CAL_38); + mdelay(1); + writel(4U, base + SENINF_NCSI2_CAL_38); + writel(0U, base + SENINF_NCSI2_CAL_3C); + writel(0x11U, base + SENINF_NCSI2_DBG_SEL); + writel(0x189617FU, base + SENINF_NCSI2_CTL); + writel(~(1UL << 27) & readl(base + SENINF_NCSI2_CTL), + base + SENINF_NCSI2_CTL); + writel((1UL << 27) | readl(base + SENINF_NCSI2_CTL), + base + SENINF_NCSI2_CTL); + writel(0x2800U, base + SENINF_NCSI2_LNRD_TIMING); + writel(0x7FFFU, base + SENINF_NCSI2_INT_STATUS); + writel(0x7FCFFFFEU, base + SENINF_NCSI2_INT_EN); + writel(0xE4000000U, base + SENINF_NCSI2_CAL_24); + writel(0xFFFFFF00U & readl(base + SENINF_NCSI2_DBG_SEL), + base + SENINF_NCSI2_DBG_SEL); + writel(0xFFFFFF45U | readl(base + SENINF_NCSI2_DBG_SEL), + base + SENINF_NCSI2_DBG_SEL); + writel(0xFFFFFFEFU & readl(base + SENINF_NCSI2_HSRX_DBG), + base + SENINF_NCSI2_HSRX_DBG); + writel(0x01010101U, base + SENINF_NCSI2_DI_CTRL); + writel(0x03020100U, base + SENINF_NCSI2_DI); + writel(0x10, base + SENINF_NCSI2_DBG_SEL); +} + +static void mtk_mipicsi_seninf_top_init(struct regmap *regmap) +{ + (void)regmap_write(regmap, SENINF_TOP_CTRL, 0x00010C00U); + (void)regmap_write(regmap, SENINF_TOP_CMODEL_PAR, 0x00079871); + (void)regmap_write(regmap, SENINF_TOP_MUX, 0x11110000); +} + +static void mtk_mipicsi_seninf_mux_init(void __iomem *base, unsigned int ch) +{ + unsigned int mux_ctrl_val = (((0x9EFF8U + ch) << 12U) | 0x180U); + + /* select seninf_mux1-4 as input for NCSI2 VC0-3*/ + writel(mux_ctrl_val, base + SENINF_MUX_CTRL); +} + +static void mtk_mipicsi_camsv_csr_init(void __iomem *base) +{ + /* double buffer enable. IMGO enable. PAK sel. TG enable */ + writel(0x40000019U, base + CAMSV_MODULE_EN); + /* IMGO DP, PAK DP and TG clk enable */ + writel(0x00008005U, base + CAMSV_CLK_EN); + /* 0: raw8, 1:raw10, 2:raw12, 3:YUV422, 4:raw14, 7:JPEG */ + writel(0x00000003U, base + CAMSV_FMT_SEL); + /* write clear enable. pass1 down interrupt enable */ + writel(0x80000400U, base + CAMSV_INT_EN); +} + +static void mtk_mipicsi_camsv_tg_init(void __iomem *base, u32 b, u32 h) +{ + /* bit[30:16] grab end pixel clock number. + * bit[14:0] grab start pixel clock number + */ + writel(b << 16U, base + CAMSV_TG_SEN_GRAB_PXL); + /* bit[29:16] end line number. bit[13:0] start line number */ + writel(h << 16U, base + CAMSV_TG_SEN_GRAB_LIN); + /* YUV sensor unsigned to signed enable */ + writel(0x1000U, base + CAMSV_TG_PATH_CFG); + /* cmos enable YUV422 mode */ + writel(3U, base + CAMSV_TG_SEN_MODE); +} + +static void mtk_mipicsi_camsv_dma_init(void __iomem *base, u32 b, u32 h) +{ + /* enable SW format setting. YUV format. 16bit */ + writel(0x01810000U | b, base + IMGO_STRIDE); + /* b -1 bytes per line to write */ + writel(b - 1U, base + IMGO_XSIZE); + /* w - 1 lines to write */ + writel(h - 1U, base + IMGO_YSIZE); + /* disable frame header function */ + writel(0U, base + DMA_FRAME_HEADER_EN); +} + +static void mtk_mipicsi_camsv_init(void __iomem *base, u32 b, u32 h) +{ + mtk_mipicsi_camsv_csr_init(base); + mtk_mipicsi_camsv_tg_init(base, b, h); + mtk_mipicsi_camsv_dma_init(base, b, h); +} + +static void mtk_mipicsi_reg_init(struct mtk_mipicsi_dev *mipicsi) +{ + unsigned int i; + + mtk_mipicsi_ana_init(mipicsi->ana); + mtk_mipicsi_seninf_ctrl_init(mipicsi->seninf_ctrl); + mtk_mipicsi_seninf_init(mipicsi->seninf); + mtk_mipicsi_seninf_top_init(mipicsi->seninf_top); + + for (i = 0U; i < mipicsi->camsv_num; ++i) { + u32 b = mipicsi->bytesperline; + u32 h = mipicsi->height; + + mtk_mipicsi_seninf_mux_init(mipicsi->seninf_mux[i], i); + mtk_mipicsi_camsv_init(mipicsi->camsv[i], b, h); + } +} + static int mtk_mipicsi_pm_suspend(struct device *dev) { struct soc_camera_host *ici = to_soc_camera_host(dev); @@ -649,6 +837,7 @@ static int mtk_mipicsi_pm_resume(struct device *dev) for (i = 0; i < mipicsi->clk_num; ++i) (void)clk_prepare_enable(mipicsi->clk[i]); + mtk_mipicsi_reg_init(mipicsi); return ret; } From patchwork Tue Apr 16 09:30:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902519 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A7335184E for ; Tue, 16 Apr 2019 09:44:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9013328591 for ; Tue, 16 Apr 2019 09:44:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8410D28671; Tue, 16 Apr 2019 09:44:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 342FB28614 for ; Tue, 16 Apr 2019 09:44:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pjGZKGTiJ1gVT1QU6LqUGwKnlIvw5kUpuHf/nG8mo1o=; b=iXcO2Ou/J0toSu bTJLq02ULnPSFnNVHElwSw6jkgTbiG2PdPF7jvOJBPDx7qeDuFI4MSXS+UYWzv7a9h799uyueCMPv +Cv5l4yX0+zSPAJ2lBxYlhHdwKItsoyAfBJawd19q8b39E3ABKeC7EnbfBs/jobjTXDKSRHsHQMWS 5F+Nnxnjb6hygSb3jQFmVbJHomO2ujRV59ugdNKZT0DB355bNgIQJgsD+q3h/GDt2C9aYNXOpxngA cXdlhifwlfQRbRxCewJjo0GdUnprXgI8EoxxcLaTbVd9pK+Aj0AOgHZ78Y6fV6IOApeOAOOU8Wbim peuf+8HACrZMXiVvlR3w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKe4-0005LQ-8r; Tue, 16 Apr 2019 09:44:52 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKdU-0004CA-U8; Tue, 16 Apr 2019 09:44:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Z2v9MuYSPHnNZsTyE/SibsZ+TjKtHsNecMy7IpGeN9Y=; b=hmXne8EVE2HdL6V+wVKEZP27Z cA3NTuESydpfJv57azs3GYlNqJVcBsid5qXOP7OtEi1kLRmSi5OePbgSMSZon5x7D4TylKbAP1Mde dHEYVYRMtcaN5D5/BClux2u9phVRpa6+iNTNuCs0wLQCVt9lSkJyArGVSNSX3tQOaYi2eY+80ISid JP7426s30dnkB6d+JSGN4V3WkjX/M12ur4AmIjseCTq4o3OKWuHqrRUbbDAkulO1h+v7c4zwUx8rj nJmRxmMlVosi1OkSSXVpK9bfZAEiF7aGfrokVDF09wsXrWs6Z/q5v38B4h7sPv7934eb2pOK4Lgpi HdkQlqQpQ==; Received: from mailgw02.mediatek.com ([216.200.240.185]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQQ-0002lY-SC; Tue, 16 Apr 2019 09:30:48 +0000 X-UUID: ebaf0d6952f74fe4a905f674a42bfcd3-20190416 X-UUID: ebaf0d6952f74fe4a905f674a42bfcd3-20190416 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 629456991; Tue, 16 Apr 2019 01:30:27 -0800 Received: from mtkmbs03n2.mediatek.inc (172.21.101.182) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:30:26 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs03n2.mediatek.inc (172.21.101.182) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 17:30:18 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 17:30:18 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v2 08/15] [media] mtk-mipicsi: enable/disable ana clk Date: Tue, 16 Apr 2019 17:30:08 +0800 Message-ID: <1555407015-18130-9-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> References: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: 8248653BC848B32118B6C6517FF036FC096F692F9EBA1E990BDAF7324736F1BC2000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_103047_204240_EF0CFEDA X-CRM114-Status: GOOD ( 14.01 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch enable/disable ana clk when power on/off Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index c92ffe6684ef..8a4079f0ed9b 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -163,6 +163,41 @@ struct mtk_mipicsi_dev { V4L2_MBUS_PCLK_SAMPLE_FALLING | \ V4L2_MBUS_DATA_ACTIVE_HIGH) +static void mtk_mipicsi_ana_clk_enable(void __iomem *base, bool enable) +{ + if (enable) { + writel(1UL | readl(base + MIPI_RX_ANA00_CSI), + base + MIPI_RX_ANA00_CSI); + writel(1UL | readl(base + MIPI_RX_ANA04_CSI), + base + MIPI_RX_ANA04_CSI); + writel(1UL | readl(base + MIPI_RX_ANA08_CSI), + base + MIPI_RX_ANA08_CSI); + writel(1UL | readl(base + MIPI_RX_ANA0C_CSI), + base + MIPI_RX_ANA0C_CSI); + writel(1UL | readl(base + MIPI_RX_ANA10_CSI), + base + MIPI_RX_ANA10_CSI); + writel(1UL | readl(base + MIPI_RX_ANA20_CSI), + base + MIPI_RX_ANA20_CSI); + writel(1UL | readl(base + MIPI_RX_ANA24_CSI), + base + MIPI_RX_ANA24_CSI); + } else { + writel(~1UL & readl(base + MIPI_RX_ANA00_CSI), + base + MIPI_RX_ANA00_CSI); + writel(~1UL & readl(base + MIPI_RX_ANA04_CSI), + base + MIPI_RX_ANA04_CSI); + writel(~1UL & readl(base + MIPI_RX_ANA08_CSI), + base + MIPI_RX_ANA08_CSI); + writel(~1UL & readl(base + MIPI_RX_ANA0C_CSI), + base + MIPI_RX_ANA0C_CSI); + writel(~1UL & readl(base + MIPI_RX_ANA10_CSI), + base + MIPI_RX_ANA10_CSI); + writel(~1UL & readl(base + MIPI_RX_ANA20_CSI), + base + MIPI_RX_ANA20_CSI); + writel(~1UL & readl(base + MIPI_RX_ANA24_CSI), + base + MIPI_RX_ANA24_CSI); + } +} + static int get_subdev_register(const struct soc_camera_device *icd, struct v4l2_dbg_register *reg) { @@ -796,6 +831,8 @@ static int mtk_mipicsi_pm_suspend(struct device *dev) for (i = 0; i < mipicsi->clk_num; ++i) clk_disable_unprepare(mipicsi->clk[i]); + mtk_mipicsi_ana_clk_enable(mipicsi->ana, false); + if (mipicsi->larb_pdev != NULL) mtk_smi_larb_put(mipicsi->larb_pdev); @@ -833,6 +870,8 @@ static int mtk_mipicsi_pm_resume(struct device *dev) return ret; } + mtk_mipicsi_ana_clk_enable(mipicsi->ana, true); + /* enable digtal clock */ for (i = 0; i < mipicsi->clk_num; ++i) (void)clk_prepare_enable(mipicsi->clk[i]); From patchwork Tue Apr 16 09:30:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902405 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EC984922 for ; Tue, 16 Apr 2019 09:32:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D4A932892A for ; Tue, 16 Apr 2019 09:32:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C82A42892C; Tue, 16 Apr 2019 09:32:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 725072892A for ; Tue, 16 Apr 2019 09:32:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=M76MFECw4RALDASQsSx97drWjOv3R8UurllyDfgbJdc=; b=piF3UZRseTQ4Ea ETdAv6d2iX/cmpz/13sj/7DpaHmApH1+7MNenpt8jHBR0slM8gxoNKF8BnG1f4FEPMiUdutD0B/hl gJOO2MhvsVRNWUeMCmchOltvspVtVjnGdjnH3nQD0OCWsqlQqE2ZCojv3V3aAcTteMoEHaVR/4CEE PMEZaJmfryW692T0usoyUQeOopVyE6/9AWTKMAHcfc6wqj4Ft9U/KRNCvWXl2REEW/+e1J1pmCuVh V2e96N32C2x2YQuL89qva0p0W+e8meN+aOgZA4144XGqEWYMrWMGrRVXPNP7z/E2ccK/3DxnQO82L jUAw2RDuGancCT/daxOg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKRz-0007CA-0d; Tue, 16 Apr 2019 09:32:23 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQN-0005JX-EN; Tue, 16 Apr 2019 09:30:43 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=PqmFurPrjVVMVdLIZjkErHyua4h57rzlJ7KLjQh6XfY=; b=FR7yadZpHZFsCE60pQcNyBJgm tpeBzehFrETtCXzLHHbkRNtQh7Vdu9UdEe7OaQXU0UwkFdWpGnl3eIR29HAKvlVOY0cAlgttJWzsk N1veE34uM9S4Nku+qu2f55bg2ovDUGC1s7+N3h/cwthX2ITtLPdYzrJgw0hwRn9Ik+pq6Wm+rhRMy NJ6qlBfwLQAy+kkOD9LLviGqpiL63F9hR2FdUEXvBNZ6kipSHLMPB5oI2tZjT8K87sdd9X2qQBtOI 6dbo49a7XyHNSQTtyOVA88c0I6q296c7+BultG4q0OEq6rRhNhu1qiDrrwBTXPKCB5s/H1MPafyiO c8nFrqHhA==; Received: from mailgw01.mediatek.com ([216.200.240.184]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQJ-0001GE-Je; Tue, 16 Apr 2019 09:30:40 +0000 X-UUID: aa1b423cc8624e4eb5cbfa238c420f60-20190416 X-UUID: aa1b423cc8624e4eb5cbfa238c420f60-20190416 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 854422484; Tue, 16 Apr 2019 01:30:20 -0800 Received: from mtkmbs03n1.mediatek.inc (172.21.101.181) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:30:20 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs03n1.mediatek.inc (172.21.101.181) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 17:30:18 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 17:30:18 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v2 09/15] [media] mtk-mipicsi: enable/disable cmos for mt2712 Date: Tue, 16 Apr 2019 17:30:09 +0800 Message-ID: <1555407015-18130-10-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> References: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_053039_816530_F15826CA X-CRM114-Status: GOOD ( 13.31 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch enable/disable cmos setting for mt2712 when vb2 start/stop streaming. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 8a4079f0ed9b..7331543d400a 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -97,9 +97,11 @@ #define CAMSV_MODULE_EN 0x10 #define CAMSV_FMT_SEL 0x14 #define CAMSV_INT_EN 0x18 +#define CAMSV_SW_CTL 0x20 #define CAMSV_CLK_EN 0x30 #define CAMSV_TG_SEN_MODE 0x500 +#define CAMSV_TG_VF_CON 0x504 #define CAMSV_TG_SEN_GRAB_PXL 0x508 #define CAMSV_TG_SEN_GRAB_LIN 0x50C #define CAMSV_TG_PATH_CFG 0x510 @@ -531,9 +533,25 @@ static int mtk_mipicsi_vb2_start_streaming(struct vb2_queue *vq, struct soc_camera_device *icd = soc_camera_from_vb2q(vq); struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct mtk_mipicsi_dev *mipicsi = ici->priv; + unsigned int index = 0; + void __iomem *base = NULL; icd->vdev->queue = vq; + for (index = 0U; index < MTK_CAMDMA_MAX_NUM; ++index) + if (((mipicsi->link_reg_val >> index) & 0x01U) == 0x01U && + !mipicsi->is_enable_irq[index]) { + enable_irq(mipicsi->irq[index]); + mipicsi->is_enable_irq[index] = true; + + /*enable cmos_en and vf_en*/ + base = mipicsi->camsv[index]; + writel(0x00000001U | readl(base + CAMSV_TG_SEN_MODE), + base + CAMSV_TG_SEN_MODE); + writel(0x00000001U | readl(base + CAMSV_TG_VF_CON), + base + CAMSV_TG_VF_CON); + } + mipicsi->streamon = true; return 0; } @@ -543,7 +561,29 @@ static void mtk_mipicsi_vb2_stop_streaming(struct vb2_queue *vq) struct mtk_mipicsi_dev *mipicsi = vb2_get_drv_priv(vq); struct mtk_mipicsi_buf *buf = NULL; struct mtk_mipicsi_buf *tmp = NULL; + unsigned int i = 0U; unsigned int index = 0; + void __iomem *base = NULL; + + for (i = 0U; i < MTK_CAMDMA_MAX_NUM; ++i) + if (((mipicsi->link_reg_val >> i) & 0x01U) == 0x01U) { + /*disable cmos_en and vf_en*/ + base = mipicsi->camsv[i]; + writel(readl(base + CAMSV_TG_SEN_MODE) & 0xFFFFFFFEU, + base + CAMSV_TG_SEN_MODE); + writel(readl(base + CAMSV_TG_VF_CON) & 0xFFFFFFFEU, + base + CAMSV_TG_VF_CON); + /*camsv reset*/ + base = mipicsi->camsv[i]; + writel(0x00000004U | readl(base + CAMSV_SW_CTL), + base + CAMSV_SW_CTL); + writel(readl(base + CAMSV_SW_CTL) & 0xFFFFFFFBU, + base + CAMSV_SW_CTL); + disable_irq(mipicsi->irq[i]); + mipicsi->is_enable_irq[i] = false; + mipicsi->frame_cnt[i] = 0UL; + mipicsi->irq_status[i] = false; + } spin_lock(&mipicsi->queue_lock); while (list_empty(&(mipicsi->fb_list)) == 0) { From patchwork Tue Apr 16 09:30:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902409 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 33DAE922 for ; Tue, 16 Apr 2019 09:32:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D0BC2892B for ; Tue, 16 Apr 2019 09:32:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10C2428931; Tue, 16 Apr 2019 09:32:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8D0A32892B for ; Tue, 16 Apr 2019 09:32:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pwY7gLSxj1diYbYKqQtuBKd+koVbYDBaUlW/APKVpko=; b=HdjdNKktqNPbvp ThIOO+Vl4Etd/S4AGBI8X3LS/WVazKcpLURVdW2Jz0URqHt/38FDcLitFxrUc2fGbB4ZX7+S+69dU N/vS84cM5vOI91+3K4Wnzt2o0vLRunzsnsO1OKpNf85ofO+tVqEzrFI+bEHnG1QTXN/VcVLaOXl2I XILTbQp6GRWPt6u1gz+7MmLZ6qUSB6+s9qtreNRXflGmj3jyomsT/QxlkQDijvaXWMz9e9K4qNiaR WtXXFEwQ8RdYjHfaPjvztvVCeQSIpqGLitCC50Vbrwx3ntvOM0z4/gNYxAxCZZ+UuBX1I3Vomv1OH b9zWSYTsoeqgsIQ0be+Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKS1-0007HL-UY; Tue, 16 Apr 2019 09:32:25 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQQ-0005RP-Au; Tue, 16 Apr 2019 09:30:46 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=UtZp8BbAUEkNcnroojf8RX7CmzqpCKcDeoKIcHk+MfY=; b=GOICr9MtP0gZzrgtfpHi9IZ2z DDBErLc5eqkA4vV3eyZOYEZZs+YNFLTyNentdRnLBTMSu1UuvO9kjKkMW0kQo04QFxbqzhEH0v2Bv eTx7tet22ghjCaeV6pxttfL6ZCZK+yATgtP0v4v5rEwm+GU+JLklldDBynbVujfIxT2E9qFwvbxKn R/Bc6vF2Rxz8f+OrmbDgvh/oOF042w2JSuU2tMzsEqP8M8DfdycCK4M+kVRCTYLSSZkiVfrF428KP Jhf91KCMDoe0AC91+zD2wKq1pw+i7YpRUixQ+x2qR0Efp2NfNG/hJXDG8TzRttSl0xqSwKCr0mTSG Q5gUi9eUA==; Received: from mailgw01.mediatek.com ([216.200.240.184]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQL-0001GE-UD; Tue, 16 Apr 2019 09:30:44 +0000 X-UUID: df0d2024f5dc4e7583e0019239045dc9-20190416 X-UUID: df0d2024f5dc4e7583e0019239045dc9-20190416 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1057318164; Tue, 16 Apr 2019 01:30:21 -0800 Received: from MTKMBS01N1.mediatek.inc (172.21.101.68) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:30:20 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 17:30:18 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 17:30:18 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v2 10/15] [media] mtk-mipicsi: add ISR for writing the data to buffer Date: Tue, 16 Apr 2019 17:30:10 +0800 Message-ID: <1555407015-18130-11-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> References: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_053042_292416_6B3B112A X-CRM114-Status: GOOD ( 21.54 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add ISR for writing the data to buffer When mipicsi HW complete to write the data in buffer, the interrupt woulb be trigger. So, the ISR need to clear interrupt status for next interrupt. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 7331543d400a..3624186206bd 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -97,6 +98,8 @@ #define CAMSV_MODULE_EN 0x10 #define CAMSV_FMT_SEL 0x14 #define CAMSV_INT_EN 0x18 +#define CAMSV_INT_STATUS 0x1C +#define PASS1_DONE_STATUS 10 #define CAMSV_SW_CTL 0x20 #define CAMSV_CLK_EN 0x30 @@ -127,6 +130,8 @@ struct mtk_mipicsi_dev { unsigned int camsv_num; struct v4l2_device v4l2_dev; struct device *larb_pdev; + unsigned int irq[MTK_CAMDMA_MAX_NUM]; + bool irq_status[MTK_CAMDMA_MAX_NUM]; void __iomem *ana; void __iomem *seninf_ctrl; void __iomem *seninf; @@ -140,6 +145,7 @@ struct mtk_mipicsi_dev { spinlock_t lock; spinlock_t queue_lock; struct mtk_mipicsi_buf cam_buf[MAX_BUFFER_NUM]; + bool is_enable_irq[MTK_CAMDMA_MAX_NUM]; bool streamon; unsigned long frame_cnt[MTK_CAMDMA_MAX_NUM]; unsigned int link; @@ -934,9 +940,98 @@ static const struct dev_pm_ops mtk_mipicsi_pm = { mtk_mipicsi_pm_resume, NULL) }; +static int get_irq_channel(struct mtk_mipicsi_dev *mipicsi) +{ + int ch; + u32 int_reg_val; + + for (ch = 0; ch < mipicsi->camsv_num; ++ch) { + int_reg_val = readl(mipicsi->camsv[ch] + CAMSV_INT_STATUS); + if ((int_reg_val & (1UL << PASS1_DONE_STATUS)) != 0UL) + return ch; + } + + return -1; +} + +static void mtk_mipicsi_irq_buf_process(struct mtk_mipicsi_dev *mipicsi) +{ + unsigned int i = 0U; + struct mtk_mipicsi_buf *new_cam_buf = NULL; + struct mtk_mipicsi_buf *tmp = NULL; + unsigned int index = 0U; + unsigned int next = 0U; + + for (i = 0U; i < MTK_CAMDMA_MAX_NUM; ++i) + mipicsi->irq_status[i] = false; + + i = 0; + + /* only one buffer left */ + if ((&(mipicsi->fb_list))->next->next == &(mipicsi->fb_list)) + return; + + /*for each fb_lst 2 times to get the top 2 buffer.*/ + list_for_each_entry_safe(new_cam_buf, tmp, + &(mipicsi->fb_list), queue) { + if (i == 0U) { + index = new_cam_buf->vb->index; + } else { + next = new_cam_buf->vb->index; + break; + } + ++i; + } + + /* + * fb_list has one more buffer. Free the first buffer to user + * and fill the second buffer to HW. + */ + vb2_buffer_done(mipicsi->cam_buf[index].vb, + VB2_BUF_STATE_DONE); + ++(mipicsi->dequeue_cnt); + + list_del_init(&(mipicsi->cam_buf[index].queue)); +} + +static irqreturn_t mtk_mipicsi_isr(int irq, void *data) +{ + + struct mtk_mipicsi_dev *mipicsi = data; + unsigned long flags = 0; + int isr_ch; + u8 irq_cnt = 0, i = 0; + + spin_lock_irqsave(&mipicsi->lock, flags); + + isr_ch = get_irq_channel(mipicsi); + if (isr_ch < 0) { + spin_unlock_irqrestore(&mipicsi->lock, flags); + return IRQ_HANDLED; + } + + /* clear interrupt */ + writel(1UL << PASS1_DONE_STATUS, + mipicsi->camsv[isr_ch] + CAMSV_INT_STATUS); + mipicsi->irq_status[isr_ch] = true; + ++(mipicsi->frame_cnt[isr_ch]); + for (i = 0U; i < MTK_CAMDMA_MAX_NUM; ++i) { + if (mipicsi->irq_status[i]) + ++irq_cnt; + } + + if (irq_cnt == mipicsi->link) + mtk_mipicsi_irq_buf_process(mipicsi); + spin_unlock_irqrestore(&mipicsi->lock, flags); + + return IRQ_HANDLED; +} + static int seninf_mux_camsv_node_parse(struct mtk_mipicsi_dev *mipicsi, int index) { + int ret; + int irq; struct clk *clk = NULL; struct device *dev = NULL; struct resource *res = NULL; @@ -974,6 +1069,23 @@ static int seninf_mux_camsv_node_parse(struct mtk_mipicsi_dev *mipicsi, } mipicsi->clk[index] = clk; + irq = of_irq_get(np, 0); + if (irq <= 0) { + dev_err(dev, "get irq fail in %s node\n", np->full_name); + return -ENODEV; + } + mipicsi->irq[index] = irq; + + ret = devm_request_irq(dev, irq, + mtk_mipicsi_isr, 0, + mipicsi->drv_name, mipicsi); + if (ret != 0) { + dev_err(dev, "%s irq register failed\n", np->full_name); + return -ENODEV; + } + disable_irq(mipicsi->irq[index]); + mipicsi->irq_status[index] = false; + res = platform_get_resource(camdma_pdev, IORESOURCE_MEM, 0); if (res == NULL) { dev_err(dev, "get seninf_mux memory failed in %s node\n", From patchwork Tue Apr 16 09:30:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902525 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2E0C148C0 for ; Tue, 16 Apr 2019 09:44:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0FE7328591 for ; Tue, 16 Apr 2019 09:44:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0441028614; Tue, 16 Apr 2019 09:44:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 160D9285E2 for ; Tue, 16 Apr 2019 09:44:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IbFQuSRaH1fMGtoYmGFOjvSVXQuJHWCTErFMeQm5R3E=; b=I2NK1TV8WMBBdW wQCMnKFJMRRdpUJOWojWgYst2T30BnGLfmZF4AywmmWrtawdm79PdSfpdW6NeAh8fHNYzx8I7lVWg WsJ9ur+g5NzkuhiNazeEoK4BPmyBoeDq9Tr6NQF0y09z9eXkXi627xDEh/SaFrnlsIXEPfB3BLXwj WJoEBqqfhzlOPzMs3RvNthxgvGrucGwZYC5SxfP5BFTXNT3vEE+zULMpa4WBkWP7ryXWllAXilfsg KpOzIDlJoQSHKJ3ebbsXV1SXcq4a0w87w9yHZGewdqMInjAR6YLyQjDOdPidnG0bcjvgNOhG/Qo1S BJYuWBBf9hMbn10Pz6fg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKe5-0005NO-Fi; Tue, 16 Apr 2019 09:44:53 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKdV-0004By-Mo; Tue, 16 Apr 2019 09:44:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=BGgqvNFUj39xyUdLthDJSP3NxoTgUtjMbjVsJLp/cZg=; b=t2/ydJaYhoe2oyAobjp509aD/ A3sEHvHwA746qLFJG1WvIVuFZKk3A1G7zn5lhJ9S6I8VDFYQrFWKC3Y8V0Hf3+Z2N1Xlh9Six4Cjd pvahsdgtn/JwGLieVsE3ZhihhmY8MgQH9sE39XLirkEc/ognqQu7o+T4tSC7uIJz9UzRGlxCDAgdG K1TSO+V1txaD3AsdBbEHs9xpUDt9lJwcUzC4lxfpBm6hNf8WVb+4DvYUI7K6gCDZnpvT/CCi5Tcib 3lxqoViGb7WPBsi9BYZ4iVmlBfU9/dOOrMFRKFpmarY1KVjnLLRIMxhL9FCurc2Ns6fzTnTdgFwfr Hl/gLEOCA==; Received: from mailgw02.mediatek.com ([216.200.240.185]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQQ-0002lZ-6E; Tue, 16 Apr 2019 09:30:48 +0000 X-UUID: f153cfac70dd456ca7213cfafd9fdb65-20190416 X-UUID: f153cfac70dd456ca7213cfafd9fdb65-20190416 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1525674835; Tue, 16 Apr 2019 01:30:27 -0800 Received: from mtkmbs03n2.mediatek.inc (172.21.101.182) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:30:26 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs03n2.mediatek.inc (172.21.101.182) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 17:30:18 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 17:30:18 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v2 11/15] [media] mtk-mipicsi: set the output address in HW reg Date: Tue, 16 Apr 2019 17:30:11 +0800 Message-ID: <1555407015-18130-12-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> References: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: B2F60F66B73EE2CE18219833A5C4F7802105801D11014A8D1BDCB0956293656A2000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_103046_575289_E5834289 X-CRM114-Status: GOOD ( 16.84 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch set the output address in HW reg when buffer queue and ISR. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 3624186206bd..4027ed9c94f3 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -109,6 +109,7 @@ #define CAMSV_TG_SEN_GRAB_LIN 0x50C #define CAMSV_TG_PATH_CFG 0x510 +#define IMGO_BASE_ADDR 0x220 #define IMGO_XSIZE 0x230 #define IMGO_YSIZE 0x234 #define IMGO_STRIDE 0x238 @@ -516,12 +517,22 @@ static int mtk_mipicsi_vb2_prepare(struct vb2_buffer *vb) return 0; } +static void mtk_mipicsi_fill_buffer(void __iomem *base, dma_addr_t dma_handle) +{ + writel(dma_handle, base + IMGO_BASE_ADDR); +} + static void mtk_mipicsi_vb2_queue(struct vb2_buffer *vb) { struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue); struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct mtk_mipicsi_dev *mipicsi = ici->priv; + unsigned int i = 0; + u64 offset = 0; + u8 link_index = 0U; char *va = NULL; + u32 bytesperline = mipicsi->bytesperline; + u32 height = mipicsi->height; spin_lock(&mipicsi->queue_lock); list_add_tail(&(mipicsi->cam_buf[vb->index].queue), @@ -530,6 +541,20 @@ static void mtk_mipicsi_vb2_queue(struct vb2_buffer *vb) va = vb2_plane_vaddr(vb, 0); + for (i = 0U; (mipicsi->enqueue_cnt == 0UL) && (i < MTK_CAMDMA_MAX_NUM); + ++i) + if (((mipicsi->link_reg_val >> i) & 0x01U) == 0x01U) { + offset = (u64)link_index * bytesperline * height; + + spin_lock(&mipicsi->lock); + mtk_mipicsi_fill_buffer(mipicsi->camsv[i], + mipicsi->cam_buf[vb->index].vb_dma_addr_phy + + offset); + spin_unlock(&mipicsi->lock); + + link_index++; + } + ++(mipicsi->enqueue_cnt); } @@ -961,6 +986,10 @@ static void mtk_mipicsi_irq_buf_process(struct mtk_mipicsi_dev *mipicsi) struct mtk_mipicsi_buf *tmp = NULL; unsigned int index = 0U; unsigned int next = 0U; + u64 offset = 0ULL; + u8 link_index = 0U; + void __iomem *base = NULL; + dma_addr_t pa; for (i = 0U; i < MTK_CAMDMA_MAX_NUM; ++i) mipicsi->irq_status[i] = false; @@ -983,6 +1012,16 @@ static void mtk_mipicsi_irq_buf_process(struct mtk_mipicsi_dev *mipicsi) ++i; } + for (i = 0U; i < MTK_CAMDMA_MAX_NUM; ++i) { + if (((mipicsi->link_reg_val >> i) & 0x01U) == 0x01U) { + offset = (u64)link_index * + mipicsi->bytesperline * mipicsi->height; + base = mipicsi->camsv[i]; + pa = mipicsi->cam_buf[next].vb_dma_addr_phy; + mtk_mipicsi_fill_buffer(base, pa + offset); + link_index++; + } + } /* * fb_list has one more buffer. Free the first buffer to user * and fill the second buffer to HW. From patchwork Tue Apr 16 09:30:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902561 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ECB7F1669 for ; Tue, 16 Apr 2019 09:59:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D9BDC2882E for ; Tue, 16 Apr 2019 09:59:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CDD8F28989; Tue, 16 Apr 2019 09:59:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3D50C2882E for ; Tue, 16 Apr 2019 09:59:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pqjmcKTL4eNhNuOtMFyOkkxQNfcehAib5HWkGwIuNfc=; b=gi1oXK2f8skBGp HKbGaec0d3psYcLigkszkr23ZGiWPdCts7GloHnB1Ldp7SVi/NDPnbwmA1TvmT8wu4rvD4+LMvhyY Y1jVWAxNrUGSqvssVVsJQ6xhUdpBYBQjZVjRU32v6j/pB2SNV/Raa3rNjjklx03wWRbW4xBDBe4c6 2rLcHpUbOEeD2wetqsb6uBRheTxFoua2+OrRum8/DsjewDiDE8WnzKYEmGlKlPbcccqG5vpUxnRd9 mOvqvtFSqV9u1+ODU6SvFE6x5I1iQpuQRg6OjwBSgaAhz23eSbaBGUZbpnKF6TnatJeIhtIKJxIhO BAnEp2OaJ87xs500UA+w==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKs9-0003eQ-Dp; Tue, 16 Apr 2019 09:59:25 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKdV-0004C5-Os; Tue, 16 Apr 2019 09:44:17 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=MyLDZxfWTrdFs4QuhJ7zU/j0cmGzcpTqIte/Ez6Kujw=; b=hnO0IQTxyYBamD2OnWCm3Xjo9 yTyvZpKx0PZetDykqhhTD8hN7paEeVbmeKyD3lq5ncanG048iEf6su52OA7i24+9EBxSZpecOKJN9 3N0UfOxx6KrlgiNbtHAsspuS+6KQCPCBbBtfxYK8+kL7jFEyII7mnGVh3ZiAMWGMfJmPyLDGWzPKA D7AvjAyV4EMadGZBpAv7W20o9cQovk3kDm4GMnbqU673vSniCtE0RBEAzbwXcxwiohKmrTGQTRjYm 194bApS7WlT7PDIIkZDGyGXDH2HFnm0Vj2GeIfr6Br4LRPCxyvTpZDBuB817Ah66RkWMpGWBg6HSK 7Cbn0cUwA==; Received: from mailgw02.mediatek.com ([216.200.240.185]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQN-0002lY-WB; Tue, 16 Apr 2019 09:30:46 +0000 X-UUID: 4baf8a5b595c465fb4b46889c0c761ec-20190416 X-UUID: 4baf8a5b595c465fb4b46889c0c761ec-20190416 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1618035411; Tue, 16 Apr 2019 01:30:23 -0800 Received: from MTKMBS01N1.mediatek.inc (172.21.101.68) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:30:21 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 17:30:19 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 17:30:18 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v2 12/15] [media] mtk-mipicsi: add function to get the format Date: Tue, 16 Apr 2019 17:30:12 +0800 Message-ID: <1555407015-18130-13-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> References: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_103044_329970_2E8AD1A3 X-CRM114-Status: GOOD ( 22.43 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add function to get the format This function can get the subdev format and host format. Calculate the number of format which intersection of subdev and host. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 4027ed9c94f3..5e4028d0d5e1 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -163,6 +163,50 @@ struct mtk_mipicsi_dev { u32 bytesperline; }; +static const struct soc_mbus_lookup mtk_mipicsi_formats[] = { +{ + .code = MEDIA_BUS_FMT_YUYV8_2X8, + .fmt = { + .fourcc = V4L2_PIX_FMT_YUYV, + .name = "YUYV", + .bits_per_sample = 8, + .packing = SOC_MBUS_PACKING_2X8_PADHI, + .order = SOC_MBUS_ORDER_LE, + .layout = SOC_MBUS_LAYOUT_PACKED, + }, +}, { + .code = MEDIA_BUS_FMT_YVYU8_2X8, + .fmt = { + .fourcc = V4L2_PIX_FMT_YVYU, + .name = "YVYU", + .bits_per_sample = 8, + .packing = SOC_MBUS_PACKING_2X8_PADHI, + .order = SOC_MBUS_ORDER_LE, + .layout = SOC_MBUS_LAYOUT_PACKED, + }, +}, { + .code = MEDIA_BUS_FMT_UYVY8_2X8, + .fmt = { + .fourcc = V4L2_PIX_FMT_UYVY, + .name = "UYVY", + .bits_per_sample = 8, + .packing = SOC_MBUS_PACKING_2X8_PADHI, + .order = SOC_MBUS_ORDER_LE, + .layout = SOC_MBUS_LAYOUT_PACKED, + }, +}, { + .code = MEDIA_BUS_FMT_VYUY8_2X8, + .fmt = { + .fourcc = V4L2_PIX_FMT_VYUY, + .name = "VYUY", + .bits_per_sample = 8, + .packing = SOC_MBUS_PACKING_2X8_PADHI, + .order = SOC_MBUS_ORDER_LE, + .layout = SOC_MBUS_LAYOUT_PACKED, + }, +}, +}; + #define MTK_MIPICSI_BUS_PARAM (V4L2_MBUS_MASTER | \ V4L2_MBUS_HSYNC_ACTIVE_HIGH | \ V4L2_MBUS_HSYNC_ACTIVE_LOW | \ @@ -207,6 +251,43 @@ static void mtk_mipicsi_ana_clk_enable(void __iomem *base, bool enable) } } +static int mtk_mipicsi_try_bus_param(struct soc_camera_device *icd, + unsigned char buswidth) +{ + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + struct soc_camera_host *ici = to_soc_camera_host(icd->parent); + struct mtk_mipicsi_dev *mipicsi = ici->priv; + struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_CSI2_DPHY,}; + unsigned long common_flags = 0; + int ret = 0; + + ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg); + if (ret == 0) { + common_flags = soc_mbus_config_compatible(&cfg, + MTK_MIPICSI_BUS_PARAM); + if (common_flags == 0U) { + dev_warn(icd->parent, "Flags incompatible: camera 0x%x\n", + cfg.flags); + return -EINVAL; + } + } else { + if (ret != -ENOIOCTLCMD) + return ret; + } + + if ((((u16)1U << (buswidth - 1U)) & mipicsi->width_flags) != 0U) + return 0; + + return -EINVAL; +} + +static bool mtk_mipicsi_packing_supported(const struct soc_mbus_pixelfmt *fmt) +{ + return fmt->packing == SOC_MBUS_PACKING_NONE || + (fmt->bits_per_sample == 8U && + fmt->packing == SOC_MBUS_PACKING_2X8_PADHI); +} + static int get_subdev_register(const struct soc_camera_device *icd, struct v4l2_dbg_register *reg) { @@ -330,6 +411,72 @@ static void mtk_mipicsi_remove_device(struct soc_camera_device *icd) (void)pm_runtime_put_sync(icd->parent); } +static int mtk_mipicsi_get_formats(struct soc_camera_device *icd, + unsigned int idx, struct soc_camera_format_xlate *xlate) +{ + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + int formats = 0, ret, i; + int n = ARRAY_SIZE(mtk_mipicsi_formats); + + struct v4l2_subdev_mbus_code_enum mbus_code = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + .index = idx, + }; + /* subdev format */ + const struct soc_mbus_pixelfmt *fmt; + + ret = v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &mbus_code); + if (ret < 0) + /* No more formats */ + return 0; + + /* get subdev support format */ + fmt = soc_mbus_get_fmtdesc(mbus_code.code); + if (fmt == NULL) { + dev_err(icd->parent, "Invalid format code #%u: %d", + idx, mbus_code.code); + return 0; + } + + /* This also checks support for the requested bits-per-sample */ + ret = mtk_mipicsi_try_bus_param(icd, fmt->bits_per_sample); + if (ret < 0) { + dev_err(icd->parent, "Fail to try the bus parameters.\n"); + return 0; + } + + switch (mbus_code.code) { + case MEDIA_BUS_FMT_UYVY8_2X8: + case MEDIA_BUS_FMT_VYUY8_2X8: + case MEDIA_BUS_FMT_YUYV8_2X8: + case MEDIA_BUS_FMT_YVYU8_2X8: + dev_dbg(icd->parent, "Providing format %s using code %d\n", + fmt->name, mbus_code.code); + break; + default: + if (!mtk_mipicsi_packing_supported(fmt)) + return 0; + if (xlate != NULL) + dev_dbg(icd->parent, + "Providing format %s in pass-through mode\n", + fmt->name); + break; + } + + /* get camera host and subdev format intersection */ + for (i = 0; i < n; ++i) + if (mtk_mipicsi_formats[i].fmt.fourcc == fmt->fourcc) { + ++formats; + if (xlate != NULL) { + xlate->host_fmt = &mtk_mipicsi_formats[i].fmt; + xlate->code = mbus_code.code; + xlate++; + } + } + + return formats; +} + static bool is_supported(const u32 pixformat) { switch (pixformat) { @@ -730,6 +877,7 @@ static struct soc_camera_host_ops mtk_soc_camera_host_ops = { .owner = THIS_MODULE, .add = mtk_mipicsi_add_device, .remove = mtk_mipicsi_remove_device, + .get_formats = mtk_mipicsi_get_formats, .set_fmt = mtk_mipicsi_set_fmt, .try_fmt = mtk_mipicsi_try_fmt, .init_videobuf2 = mtk_mipicsi_init_videobuf2, From patchwork Tue Apr 16 09:30:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902511 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 445CC1823 for ; Tue, 16 Apr 2019 09:44:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2CEDE28591 for ; Tue, 16 Apr 2019 09:44:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 207DA28614; Tue, 16 Apr 2019 09:44:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CDEF928591 for ; Tue, 16 Apr 2019 09:44:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Z0ySz4MNkWbHOZONvprNKEL+pvBa6A7/QPCjWM9vys4=; b=DQTiyXvjXL7Ko+ fYdqHpOMmAbcnMhFhG1Twkm7Ewo5DBS2hWbi64xzbTOP8Lcl5Fp1d6RhQCjKfHygeY7KtHI2U2pf7 KZ2DMrw4OF1xE9I5+2eLMWL+sirT2M3Uo0l130DvKwQa0vrLylfOTGhwu8nBPWW4zUtXGq1F8tzld PZnGYc+NnorCnjhisdYpHlJSFmLSr18BpHwbIcU+oFvYLQrXhorOlzYHVEOr9Ob0kkF+sQXlSN3a1 rgQS7eJ22PT+zInGlBwUTP4M106IN6xc5xtt9IEaL8+cLsvt7aSp0DC+q/Xl3/yeKAlllxRYL58jG pXpCtOlLTT+osoDJBMCw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKe1-0005Hm-Pq; Tue, 16 Apr 2019 09:44:49 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQL-0005JX-Ox; Tue, 16 Apr 2019 09:30:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=MWQT/OPTNvox4W4vuGPV7pFxm2FXKlLbh9dY4HND3vo=; b=w8Nv14owZDaKCLBfo+EPrYO// wQIVwX4HDJx9yoFmuF54JgnccM5WS1KDh1aCHXDRcAczzcEEBXaF6BFb3JuWz7hsb9BjWUJ2d9bMi Am1XMq00RTd7+X0LhYkPT1oUNpXS1uimosd3dcROC1aX2WPasPNT7OAM/DP2exksE7TVVKQTVZjB4 9z1yZi1F+3VCpKxJWOUCL7DXDhJRorU9tZRdRBTecC+XdU3myinrfjl/koi9Sap+jEKfygLqIDijh avTJZPFj0dsnNTyllgG7PIL2h4/CANTFkQiBVjdNEeTb8s12b4Dm2MK6FuwYnwhT2OpYe36snB6gO 9bC1Y4YRg==; Received: from mailgw01.mediatek.com ([216.200.240.184]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQI-0001GE-G5; Tue, 16 Apr 2019 09:30:39 +0000 X-UUID: 29fc0c275c7f426ca2c7b29bcdf6962f-20190416 X-UUID: 29fc0c275c7f426ca2c7b29bcdf6962f-20190416 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1722002158; Tue, 16 Apr 2019 01:30:21 -0800 Received: from MTKMBS01N2.mediatek.inc (172.21.101.79) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:30:20 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 17:30:19 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 17:30:19 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v2 13/15] [media] mtk-mipicsi: add the function for Get/Set PARM for application Date: Tue, 16 Apr 2019 17:30:13 +0800 Message-ID: <1555407015-18130-14-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> References: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: D3D17C0B5B6345A5E3A2FDB6C7E409950C893A37DD617AB509BB866F30FD6C992000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_053038_710586_070485DD X-CRM114-Status: GOOD ( 13.52 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add the function for Get/Set PARM for application. Application can get the information about number of link. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 5e4028d0d5e1..5db9c68b0da9 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -346,6 +346,38 @@ static int get_subdev_link(const struct soc_camera_device *icd, return 0; } +static int mtk_mipicsi_get_parm(struct soc_camera_device *icd, + struct v4l2_streamparm *a) +{ + unsigned int link = 0U; + u8 link_reg_val = 0x0U; + int ret = 0; + + /*get camera link number*/ + ret = get_subdev_link(icd, &link, &link_reg_val); + if (ret < 0) + return ret; + + a->parm.capture.timeperframe.numerator = 1; + a->parm.capture.timeperframe.denominator = 30; + a->parm.capture.reserved[0] = link_reg_val; + a->parm.capture.reserved[1] = (u32)(icd->use_count); + dev_info(icd->parent, "use count %d\n", icd->use_count); + + return 0; +} + +static int mtk_mipicsi_set_param(struct soc_camera_device *icd, + struct v4l2_streamparm *a) +{ + struct soc_camera_host *ici = to_soc_camera_host(icd->parent); + + if (ici->ops->get_parm == NULL) + return ici->ops->get_parm(icd, a); + + return 0; +} + static u32 get_bytesperline(const u32 fmt, const u32 width) { u32 bytesperline = 0; @@ -884,6 +916,8 @@ static struct soc_camera_host_ops mtk_soc_camera_host_ops = { .poll = vb2_fop_poll, .querycap = mtk_mipicsi_querycap, .set_bus_param = mtk_mipicsi_set_bus_param, + .get_parm = mtk_mipicsi_get_parm, + .set_parm = mtk_mipicsi_set_param, }; static void mtk_mipicsi_ana_init(void __iomem *base) From patchwork Tue Apr 16 09:30:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902557 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E78AB1390 for ; Tue, 16 Apr 2019 09:45:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D1F7828591 for ; Tue, 16 Apr 2019 09:45:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C5F6F2893A; Tue, 16 Apr 2019 09:45:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 544FC28591 for ; Tue, 16 Apr 2019 09:45:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=dp8yegWxbuR0v2DY3t6Zz0G6OW4L6gmbh1pUZkCYn6A=; b=NFua6bry+6J/D8 L9sGIpzMwV6xxnVEXKibNmqTm0JHAVU2vxpdYXwjI7j4QpRDErrCmpqN1G0cyABllQY6QxWbx895p udYm+J94D6ZfnAxtnMhTL4hPPxrn21cEHV9Lj64hHNTsG6+D2Jho/TH0D7dtHpJZuNx0iEGJwEapj EhEntXDIt4Lz3wRZfh5F4W4BfU2VClhjH0F7xNFZ5jzqf7TAqU1rlqSA3ZG0DrOt56VJe7ehbkHA1 3HhGfmILrBrUNBuqQ4oHfmdtGofQ/pdKXgFD/bXtzC5maVPVL6AZye+dM27TgseWgRsKGaL1yGbAB 8w+4E4yzl3ydQXfOSxsQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKf7-0007fR-9V; Tue, 16 Apr 2019 09:45:57 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKdV-0004CA-VE; Tue, 16 Apr 2019 09:44:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=g86r7TMg00BPPEw8QiTMIpJpmhf/A27ItQu+fI6Oq+Q=; b=ttVFaYWW8bQStOimiaP9CR31o +P9TayAFkTSmHT9hbmrtyAD/MJKr23wC61CPJesXN+M3euQ1xt0VlYGQp5gJGz5YVnEeP0OeiJ/o9 HNsfETNCoOhM66Mb1RkUonJHHGiK1qGqWi3Du3H1KufNZELc4Ukzdb0Dl85iF893boKXtcAH9/fUg tQM3F7sJqPkUS3hgL8QlzrwK3owl7fcWgi2qnWkQ4zrLLgpaE7EMy+F4zmc/OJdWf9e8R4HFNlSqx eGzJ2K6zoCX8BGJ8LgBvLr3nL8+/7YoBNfOWTMe1XCU99BplBJVZYz/wMPUl5KZfxtnTvnwL7HwwQ AoY7lZXwg==; Received: from mailgw02.mediatek.com ([216.200.240.185]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQM-0002lZ-Tu; Tue, 16 Apr 2019 09:30:45 +0000 X-UUID: 2f7b6b4f53c948b3bc44cbc5f5686712-20190416 X-UUID: 2f7b6b4f53c948b3bc44cbc5f5686712-20190416 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1617810553; Tue, 16 Apr 2019 01:30:23 -0800 Received: from MTKMBS01N1.mediatek.inc (172.21.101.68) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:30:22 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 17:30:19 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 17:30:19 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v2 14/15] [media] mtk-mipicsi: add debug message for mipicsi driver Date: Tue, 16 Apr 2019 17:30:14 +0800 Message-ID: <1555407015-18130-15-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> References: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_103043_472177_BC801602 X-CRM114-Status: GOOD ( 24.25 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add debug message for mipicsi driver. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 54 ++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 5db9c68b0da9..321bb4c88027 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -117,6 +118,15 @@ #define SerDes_support 1 +static int mtk_mipicsi_dbg_level; +#define mtk_mipicsi_dbg(level, fmt, args...) \ + do { \ + if (mtk_mipicsi_dbg_level >= level) \ + pr_info("[MTK_MIPICSI%d] L%d %s %d: " fmt "\n", \ + mipicsi->id, level, __func__, __LINE__, \ + ##args); \ + } while (0) + /* buffer for one video frame */ struct mtk_mipicsi_buf { struct list_head queue; @@ -154,6 +164,8 @@ struct mtk_mipicsi_dev { unsigned long enqueue_cnt; unsigned long dequeue_cnt; struct v4l2_ctrl_handler ctrl_hdl; + struct timespec64 fps_time_cur; + struct timespec64 fps_time_pre; char drv_name[16]; u32 id; int clk_num; @@ -429,6 +441,8 @@ static int mtk_mipicsi_add_device(struct soc_camera_device *icd) mipicsi->width = width; mipicsi->height = height; + mtk_mipicsi_dbg(1, "sub device width/height/bytesperline %d/%d/%d", + width, height, mipicsi->bytesperline); /* * If power domain was closed before, it will be open. @@ -565,6 +579,9 @@ static int mtk_mipicsi_set_fmt(struct soc_camera_device *icd, if (pix->pixelformat == V4L2_PIX_FMT_YUYV) pix->sizeimage = pix->width * pix->height * 2U; + mtk_mipicsi_dbg(0, "width/height/sizeimage %u/%u/%u", + pix->width, pix->height, pix->sizeimage); + if (mf->code != xlate->code) return -EINVAL; @@ -690,6 +707,9 @@ static int mtk_mipicsi_vb2_prepare(struct vb2_buffer *vb) vb2_dma_contig_plane_dma_addr(vb, 0); #endif va = vb2_plane_vaddr(vb, 0); + mtk_mipicsi_dbg(1, "va=%p vb_dma_addr_phy=%lx size=%d", + va, (unsigned long)buf->vb_dma_addr_phy, + vb->planes[0].bytesused); buf->vb = vb; } @@ -735,6 +755,8 @@ static void mtk_mipicsi_vb2_queue(struct vb2_buffer *vb) } ++(mipicsi->enqueue_cnt); + mtk_mipicsi_dbg(2, "enqueue NO.%d buffer(%p). Total %lu buffer", + vb->index, vb, mipicsi->enqueue_cnt); } static int mtk_mipicsi_vb2_start_streaming(struct vb2_queue *vq, @@ -1119,8 +1141,10 @@ static int mtk_mipicsi_pm_resume(struct device *dev) if (mipicsi->larb_pdev != NULL) { ret = mtk_smi_larb_get(mipicsi->larb_pdev); - if (ret != 0) + if (ret != 0) { + mtk_mipicsi_dbg(0, "failed to get larb, err %d", ret); return ret; + } } mtk_mipicsi_ana_clk_enable(mipicsi->ana, true); @@ -1170,6 +1194,7 @@ static void mtk_mipicsi_irq_buf_process(struct mtk_mipicsi_dev *mipicsi) unsigned int next = 0U; u64 offset = 0ULL; u8 link_index = 0U; + long time_interval; void __iomem *base = NULL; dma_addr_t pa; @@ -1179,8 +1204,10 @@ static void mtk_mipicsi_irq_buf_process(struct mtk_mipicsi_dev *mipicsi) i = 0; /* only one buffer left */ - if ((&(mipicsi->fb_list))->next->next == &(mipicsi->fb_list)) + if ((&(mipicsi->fb_list))->next->next == &(mipicsi->fb_list)) { + mtk_mipicsi_dbg(1, "only 1 buffer left, drop frame"); return; + } /*for each fb_lst 2 times to get the top 2 buffer.*/ list_for_each_entry_safe(new_cam_buf, tmp, @@ -1213,6 +1240,27 @@ static void mtk_mipicsi_irq_buf_process(struct mtk_mipicsi_dev *mipicsi) ++(mipicsi->dequeue_cnt); list_del_init(&(mipicsi->cam_buf[index].queue)); + + if (mtk_mipicsi_dbg_level >= 2) { + ktime_get_real_ts64(&(mipicsi->fps_time_cur)); + if (mipicsi->dequeue_cnt == 1) { + mipicsi->fps_time_pre.tv_sec = + mipicsi->fps_time_cur.tv_sec; + mipicsi->fps_time_pre.tv_nsec = + mipicsi->fps_time_cur.tv_nsec; + } else { + time_interval = (mipicsi->fps_time_cur.tv_sec + - mipicsi->fps_time_pre.tv_sec) * 1000000000 + + (mipicsi->fps_time_cur.tv_nsec + - mipicsi->fps_time_pre.tv_nsec); + mtk_mipicsi_dbg(0, "time interval is %ld\n", + time_interval); + mipicsi->fps_time_pre.tv_sec = + mipicsi->fps_time_cur.tv_sec; + mipicsi->fps_time_pre.tv_nsec = + mipicsi->fps_time_cur.tv_nsec; + } + } } static irqreturn_t mtk_mipicsi_isr(int irq, void *data) @@ -1227,6 +1275,7 @@ static irqreturn_t mtk_mipicsi_isr(int irq, void *data) isr_ch = get_irq_channel(mipicsi); if (isr_ch < 0) { + mtk_mipicsi_dbg(0, "no interrupt occur"); spin_unlock_irqrestore(&mipicsi->lock, flags); return IRQ_HANDLED; } @@ -1567,5 +1616,6 @@ static struct platform_driver mtk_mipicsi_driver = { }; module_platform_driver(mtk_mipicsi_driver); +module_param(mtk_mipicsi_dbg_level, int, 0644); MODULE_DESCRIPTION("MediaTek SoC Camera Host driver"); MODULE_LICENSE("GPL v2"); From patchwork Tue Apr 16 09:30:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902413 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 54491922 for ; Tue, 16 Apr 2019 09:32:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 298952892A for ; Tue, 16 Apr 2019 09:32:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1E2042892C; Tue, 16 Apr 2019 09:32:30 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B52782892A for ; Tue, 16 Apr 2019 09:32:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=UuB6z6/XrAiYyZHbV9wF5wNitdxIyWDs5G/uzeX0bh8=; b=ExuLcPXI6hBtJT xTTkBc0wzFOC58Ca5FJAfotktnlB9mXELRE+gCYsvPWv1nhL5/3fiQiBOHoWtOS4j67o8vEINTLIF p796HNSHTZlHqTa/lelILCkBUPV1q+7UZN71151FgbXMqgHW/gNMQm7zFn95Dg1+rVfM0zkmDvOVt h6pJh6tFLW3dDqY17HPBMMr/HdnSw5sbHYHwoG2gPo1eYeBWxtO+7XTrdM7epk7O8BfFIrO/4/5aT UnOWrJvcNqi/N6I3UYg0ZqzECBCsMrWVTR/L/Cp7YZOsnHNdj0Kpg4oscDer6CJL2/nImggwW8pqZ M6WZYdwqvfewXmTpppzA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKS4-0007LF-Cg; Tue, 16 Apr 2019 09:32:28 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQT-0005T5-6G; Tue, 16 Apr 2019 09:30:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=7eQcen/ebCPdTzOg259613WI0ISOx9tNglSxLu4Dn/A=; b=FMP1VUJX2d5G6An175dxMNAYe 8R4zTnxIgjRjOqsef2DXbxhxuI8kIJh7lu5vtwmSG7DMdobsZVtFmxtYBjmVXZWz+XeYUvbrfwdJ7 rBHizmgHPvpUC0J5guI8WBvsFwzKJ1dI6X+pVTfZsyjGksHZFTe5eEReoH93ywNWXnmG8lpknCpuB 9d5NKzQpqdWGCt5XqZ2qPhzqyAPeDK7eXtW5wqxnKG3qIeEI1HprB/yMbFdPclt2UqO/oolE3+PGq iuUmu8wofpyBR1+4F3SmJT4an7rSC4nR1Gb00Vnm55FAM/wC0MoQz/B1yYwr6Rba8vkxJGceX5fd6 6rWmi4UKg==; Received: from mailgw01.mediatek.com ([216.200.240.184]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQQ-0001GE-17; Tue, 16 Apr 2019 09:30:46 +0000 X-UUID: 94da1ee89d6f4c8ea5c4b67eaa0497c8-20190416 X-UUID: 94da1ee89d6f4c8ea5c4b67eaa0497c8-20190416 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1895901469; Tue, 16 Apr 2019 01:30:28 -0800 Received: from mtkmbs03n2.mediatek.inc (172.21.101.182) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:30:27 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs03n2.mediatek.inc (172.21.101.182) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 17:30:19 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 17:30:19 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v2 15/15] [media] mtk-mipicsi: add debugfs for mipicsi driver Date: Tue, 16 Apr 2019 17:30:15 +0800 Message-ID: <1555407015-18130-16-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> References: <1555407015-18130-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: 5CE6797DC67B7321741F066CA3F942012B7659004294C2843050662374AF8BB52000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_053046_251529_644BE646 X-CRM114-Status: GOOD ( 16.62 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add debugfs for mipicsi driver. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 321bb4c88027..484fc9147b69 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -48,6 +48,7 @@ #include #include #include +#include #ifdef CONFIG_VB2_MEDIATEK_DMA_SG #include "mtkbuf-dma-cache-sg.h" @@ -86,6 +87,7 @@ #define SENINF_NCSI2_INT_EN 0xB0 #define SENINF_NCSI2_INT_STATUS 0xB4 #define SENINF_NCSI2_DBG_SEL 0xB8 +#define SENINF_NCSI2_DBG_PORT 0xBC #define SENINF_NCSI2_HSRX_DBG 0xD8 #define SENINF_NCSI2_DI 0xDC #define SENINF_NCSI2_DI_CTRL 0xE4 @@ -95,6 +97,7 @@ #define SENINF_TOP_MUX 0x08 #define SENINF_MUX_CTRL 0x00 +#define SENINF_MUX_DEBUG_2 0x14 #define CAMSV_MODULE_EN 0x10 #define CAMSV_FMT_SEL 0x14 @@ -117,6 +120,7 @@ #define DMA_FRAME_HEADER_EN 0xE00 #define SerDes_support 1 +#define CONFIG_DEBUG_FS 1 static int mtk_mipicsi_dbg_level; #define mtk_mipicsi_dbg(level, fmt, args...) \ @@ -173,6 +177,9 @@ struct mtk_mipicsi_dev { u32 width; u32 height; u32 bytesperline; +#ifdef CONFIG_DEBUG_FS + struct dentry *mtk_mipicsi_debugfs; +#endif }; static const struct soc_mbus_lookup mtk_mipicsi_formats[] = { @@ -228,6 +235,49 @@ static const struct soc_mbus_lookup mtk_mipicsi_formats[] = { V4L2_MBUS_PCLK_SAMPLE_FALLING | \ V4L2_MBUS_DATA_ACTIVE_HIGH) +#ifdef CONFIG_DEBUG_FS +static ssize_t mtk_mipicsi_debug_read(struct file *file, char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct device *dev = file->private_data; + struct soc_camera_host *soc_host = to_soc_camera_host(dev); + struct mtk_mipicsi_dev *mipicsi = soc_host->priv; + u32 int_val; + u32 dbg_port; + u32 cnt_val; + u32 hcnt; + u32 vcnt; + char buf[256]; + char cnt_info[150]; + int i; + + int_val = readl(mipicsi->seninf + SENINF_NCSI2_INT_STATUS); + dbg_port = readl(mipicsi->seninf + SENINF_NCSI2_DBG_PORT); + memset(buf, 0, sizeof(buf)); + snprintf(buf, sizeof(buf), "%s\nSENINF_NCSI2_INT_STATUS: 0x%X\n" + "SENINF_NCSI2_DBG_PORT: 0x%X\n", + dev_name(dev), int_val, dbg_port); + + for (i = 0; i < mipicsi->camsv_num; ++i) { + cnt_val = readl(mipicsi->seninf_mux[i] + SENINF_MUX_DEBUG_2); + hcnt = (cnt_val >> 16) & 0xFFFF; + vcnt = cnt_val & 0xFFFF; + memset(cnt_info, 0, sizeof(cnt_info)); + snprintf(cnt_info, sizeof(cnt_info), + "HCNT[%d]: 0x%X\n" + "VCNT[%d]: 0x%X\n", + i, hcnt, i, vcnt); + strcat(buf, cnt_info); + } + + return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); +} +static const struct file_operations mtk_mipicsi_debug_fops = { + .open = simple_open, + .read = mtk_mipicsi_debug_read, +}; +#endif /* CONFIG_DEBUG_FS */ + static void mtk_mipicsi_ana_clk_enable(void __iomem *base, bool enable) { if (enable) { @@ -1582,6 +1632,16 @@ static int mtk_mipicsi_probe(struct platform_device *pdev) goto clean; } +#ifdef CONFIG_DEBUG_FS + mipicsi->mtk_mipicsi_debugfs = + debugfs_create_file(mipicsi->drv_name, 0444, NULL, + (void *)(&pdev->dev), &mtk_mipicsi_debug_fops); + if (mipicsi->mtk_mipicsi_debugfs == NULL) { + dev_err(&pdev->dev, "debugfs_create_file fail\n"); + goto clean; + } +#endif + dev_info(&pdev->dev, "probe done\n"); return ret; clean: @@ -1594,6 +1654,11 @@ static int mtk_mipicsi_remove(struct platform_device *pdev) { struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev); +#ifdef CONFIG_DEBUG_FS + struct mtk_mipicsi_dev *mipicsi = soc_host->priv; + + debugfs_remove(mipicsi->mtk_mipicsi_debugfs); +#endif soc_camera_host_unregister(soc_host); pm_runtime_disable(&pdev->dev);