From patchwork Tue Dec 27 09:51:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marvin Lin X-Patchwork-Id: 36799 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1311597wrt; Tue, 27 Dec 2022 01:54:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXten43Nw0xxkcnj4T5QFJK+OuslJx6+85CwD80fgYqr0h+PAsjPMpmunwfwjn5zigsgaFcm X-Received: by 2002:a17:907:7676:b0:7c1:7183:2d32 with SMTP id kk22-20020a170907767600b007c171832d32mr19330950ejc.56.1672134839929; Tue, 27 Dec 2022 01:53:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672134839; cv=none; d=google.com; s=arc-20160816; b=mM2BtxTmVRi5DhkGGhk4YI+baZF0kJyaxrMcaEcWMWE9XYBZw8XUtqAxA6arUIsGxJ c4KZMQqY1VVJmfx1aEj2Or1yE/9oQBrD3OIMurR2pe3hZf/QN06DyV25pSfoeUib2EVP 7p15gTh/CIAhFS6tLiI4A8d9+ibyPW+zMjUCI7VwV9qgCQkBKisduW//XhkQQ9FWamdN LGXhoGqVfJuKwUfP7LOVPFUuTQU7WmmATmouOebm61Ly7rLLzd+rHctpjVAhUk8SV/RD /s2SR4BJygbQXzGt1olAJbxMAqVnPY8YY6Xd+S1CpHIuwSOHnjL08rqn6pvoFJbFG6tG 0X6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=fuPzabFK+ItSAS4Njr3Xe+weyJyvM5VjKuGON2TO41E=; b=urz/CH9W9PjdsIw/BEZW1Rcf+0iv/5XswEBajLYCeWtRqo7wPrY1UMJZfjzsOp4+0Y G64UNYotlRH4LCEdBPTG6nzImZHMndXTE3T4FwIrCoFfeXIQUDTy9Ak5XEgYAeo581M5 KA46DdQMe27QwVdySxLmHtSx5yBN4TsJEb1x1z5c6dIzDl8muK02jPdC2E/JStniB28S 0ZFKClUAAZjNk0XNhj/djrALdF6+Tf6moMqlXV4cQAVLAzK5bCMSojcFb8bpmhDRyXDk o3TD1oQ6qtovAX9cblM2NnCoqoHaEYOhgwZWk6Y7DPOMjkO81kXic+2ae4TFoXqr7Kg0 xzTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=F8J7oA8L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne28-20020a1709077b9c00b0081a9c3ca4c3si11712135ejc.374.2022.12.27.01.53.36; Tue, 27 Dec 2022 01:53:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=F8J7oA8L; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230429AbiL0Jv6 (ORCPT + 99 others); Tue, 27 Dec 2022 04:51:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230342AbiL0Jvz (ORCPT ); Tue, 27 Dec 2022 04:51:55 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B69472673; Tue, 27 Dec 2022 01:51:53 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id o8-20020a17090a9f8800b00223de0364beso16788091pjp.4; Tue, 27 Dec 2022 01:51:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fuPzabFK+ItSAS4Njr3Xe+weyJyvM5VjKuGON2TO41E=; b=F8J7oA8Lbv5Z2/cnu9xN69NUs+tjMghmpHUg/HEH+z3nW1b92eQxsf6wyxipVyfbew mgquQUvtjdNkUS9xw146qyzkFCdFHmihwEY0Mmlzm4EH/Rfs6QeIJiAy2ieyUhHKqMgk WzHLQBSNyfP3qKqunXY7ibSCYg1VpudEyBXqZp5TZgQ+eEeJpt0Pv66a4HmgkfixbHb6 rpMBLhzIS4fpu28Jl005zYlPatbB2BDaeBwy2owSG/9ZK0cBRqV42jwTfNuoI2g4QJE8 CXANHt0k6smMBur0Jl3nYMgz51IVxej5E3OlM+Byohf0OB7oa+lE7qHCnMFpT/ZJ6A+B z0Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fuPzabFK+ItSAS4Njr3Xe+weyJyvM5VjKuGON2TO41E=; b=d0TQNuYpTM8/OMrYsgNm+jvk0NZnXZAZ4Dc1J5WCjGW1K7N1eDMYskA4E6NFWdNdR7 vsuB20hf3ShsIYcJY9j07PQ7psdFSe36RbTrYWHnAQaGUQcxwJxqDwsco+mPDoOD3AiW L89AUPsz5OOAMGeDSOHoNSy6EYDHs0kNh/M+uL839i0pgnFtVHzXI6Mety24/+C2+wyH vHwc0Zfys6O8EhR+xsb3xmc/6JtLhhpbb/oEA6wBteLvPEoYIxbfQxihxsLppFNe7V0P ojMr33rz/Y7CkpFKIn+3lOpNqkqc+9d0EuzrXLC5PeiNoKLi3V+pRQT2JkrW0nC8kSba B3Wg== X-Gm-Message-State: AFqh2krB6dmT+VeSNW7Z1NpthZD3yhbQrc/8965Nq0VYi+x71GlGZJDQ pxZJ1k/2RiuZ1TcLhKnzotM= X-Received: by 2002:a05:6a20:3c93:b0:b0:30d8:d53 with SMTP id b19-20020a056a203c9300b000b030d80d53mr32892588pzj.19.1672134713154; Tue, 27 Dec 2022 01:51:53 -0800 (PST) Received: from hcdev-d520mt2.. (60-250-192-107.hinet-ip.hinet.net. [60.250.192.107]) by smtp.gmail.com with ESMTPSA id 21-20020a621515000000b005813aec74bdsm2619052pfv.139.2022.12.27.01.51.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Dec 2022 01:51:52 -0800 (PST) From: Marvin Lin To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl, avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, andrzej.p@collabora.com Cc: devicetree@vger.kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, kwliu@nuvoton.com, kflin@nuvoton.com, Marvin Lin Subject: [PATCH v10 1/7] ARM: dts: nuvoton: Add node for NPCM VCD and ECE engine Date: Tue, 27 Dec 2022 17:51:17 +0800 Message-Id: <20221227095123.2447948-2-milkfafa@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221227095123.2447948-1-milkfafa@gmail.com> References: <20221227095123.2447948-1-milkfafa@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753360462058500546?= X-GMAIL-MSGID: =?utf-8?q?1753360462058500546?= Add node for Video Capture/Differentiation Engine (VCD) and Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs. Tested with Nuvoton NPCM750 evaluation board. Signed-off-by: Marvin Lin --- arch/arm/boot/dts/nuvoton-common-npcm7xx.dtsi | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/arch/arm/boot/dts/nuvoton-common-npcm7xx.dtsi b/arch/arm/boot/dts/nuvoton-common-npcm7xx.dtsi index c7b5ef15b716..13a76689e14a 100644 --- a/arch/arm/boot/dts/nuvoton-common-npcm7xx.dtsi +++ b/arch/arm/boot/dts/nuvoton-common-npcm7xx.dtsi @@ -179,6 +179,24 @@ fiux: spi@fb001000 { status = "disabled"; }; + vcd: vcd@f0810000 { + compatible = "nuvoton,npcm750-vcd"; + reg = <0xf0810000 0x10000>; + interrupts = ; + resets = <&rstc NPCM7XX_RESET_IPSRST2 NPCM7XX_RESET_VCD>; + nuvoton,sysgcr = <&gcr>; + nuvoton,sysgfxi = <&gfxi>; + nuvoton,ece = <&ece>; + status = "disabled"; + }; + + ece: video-codec@f0820000 { + compatible = "nuvoton,npcm750-ece"; + reg = <0xf0820000 0x2000>; + resets = <&rstc NPCM7XX_RESET_IPSRST2 NPCM7XX_RESET_ECE>; + status = "disabled"; + }; + apb { #address-cells = <1>; #size-cells = <1>; @@ -554,6 +572,11 @@ i2c15: i2c@8f000 { pinctrl-0 = <&smb15_pins>; status = "disabled"; }; + + gfxi: gfxi@e000 { + compatible = "nuvoton,npcm750-gfxi", "syscon"; + reg = <0xe000 0x100>; + }; }; }; From patchwork Tue Dec 27 09:51:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marvin Lin X-Patchwork-Id: 36805 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1312064wrt; Tue, 27 Dec 2022 01:55:36 -0800 (PST) X-Google-Smtp-Source: AMrXdXuDOyBVHNnmeAT/SyoZK+z0tUD1+USNrgkS5v4fkSnF1VaMj/wDBfeex/wqu0rdtforLNrR X-Received: by 2002:a05:6a00:3491:b0:581:5017:f960 with SMTP id cp17-20020a056a00349100b005815017f960mr4141620pfb.29.1672134936594; Tue, 27 Dec 2022 01:55:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672134936; cv=none; d=google.com; s=arc-20160816; b=fn/Vd/Ckq1weDCvtP27hGqp+/xsqvTFWIuIQ4p5LokDe9h+fDn7mgXwl4tLzhjntzi SrkPLuOhIwqXsBIshVvCns4li2H0Dbs7KfNBIIHriv28IOIDwiwB1ingw5oVG/o9/Wr1 ci7u6x/VHpWEN0QAiVazUz5r5ST7Fpamjsxa1IFcRXowiNSgVTQJPSXkxh0Ec53o0czv Wq7Iwcnv4jsVGZJX2OgzDZhqpG5E4Wh6uUBw+ZRb63WvianlVSYCgge0h295uyw52tiL LaSr5N5eA3/FAyK3ycN98Y65mgBker2tF045Tz1Abf7a+/TOVVfuueNNMpf3FKBoJnyy U8YA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3OFIOC5oKZ0F+p/C6qXyoQWPtbp1a9uFnXmP1cOo5xc=; b=AYcnRLML+sctqtWEAx6RcMFnk7e5L3AfBPFz6nBrqmAzOXHTRt/9pAr7gIQUFdMG76 oJTQUxjsuBI7KK+0XYUWqnUIUunDV4AlB7TvR/t/v7InIYjMFpTlMBIGTf9km9eYqZyi XxPP7rLpEgUhbrlZm/VbE9XdFNMrPXDQNOpMpo1vP9QO3BikEH2Gs3tfZO5F9Wd7Yw9p NDRB0NATuT235f/vegG3Yxa3ZfRBDF7qwHH+1H9htT0SDUZ8MVm6fyIdfu7R/y2SjDny bMBUJmN6lbCr4FBxcFbG7ynbSLlWcMEzQtwdVgNOKxS9Ku68Ty35P1uHmeWGTRIX0PWk JM2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="MaGNbWq/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x66-20020a626345000000b00580c796d690si10380783pfb.304.2022.12.27.01.55.24; Tue, 27 Dec 2022 01:55:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="MaGNbWq/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231191AbiL0JwH (ORCPT + 99 others); Tue, 27 Dec 2022 04:52:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230506AbiL0Jv5 (ORCPT ); Tue, 27 Dec 2022 04:51:57 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E75D895B4; Tue, 27 Dec 2022 01:51:56 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id y21so6380619pfo.7; Tue, 27 Dec 2022 01:51:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=3OFIOC5oKZ0F+p/C6qXyoQWPtbp1a9uFnXmP1cOo5xc=; b=MaGNbWq//LCbCCBqpSLiUzVeKCmDrbpADMQkIPK4FpujBFGk1sWzxckXT6Jz5DCuzL fcn5xGe/9lRQ48yNCM+Y4iMolWxCi0wCdkOz/OqrIhlOxEFKJvBz9k86aRFiwcUDSI78 celDoh+RJOIjdtZqMkGRbKUUxSYhgYKQBphJQ69tzRhY98AcDPkWZb6TZWTN0jQ+qfJh w1t8he/p2YaJM64uKqiDZ2wtdyE0QIrbkAH3iZFYuyQUv8/ZcZNZoox2MvKLuiw78X5D ZWM5qfLW5RKz81FgPxPN+3O1vvQm5QvxnAQ54CqF3thV3EIChyCPzZ59I7JXU/iqdpnI 2kEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3OFIOC5oKZ0F+p/C6qXyoQWPtbp1a9uFnXmP1cOo5xc=; b=g7QJtPGp1AJq1nbFWJnYjizqnnlMSJ+6AWSvWbrv2RlYXwT6UVZjVn1COv7woURNjz jy6m3KzM5cAIC3u9l5hm/6dlqnkAP6RfQx0zka3PAvkMcOQoYPAQ+yJedfPfE/UqWFrt bOrjVZ3VcANpBuNPhQhN4ltAJLmwj/8I8gnzuBSQAm5pSoSYO6hWiGywNSadWE6pRGkn o1QPfeqWJgWUtsgqvqWYw1DhR+vQbfgeu8zT37KoUb+zySqQJT4MgaHLO5IUxtes+I5V mIXO726UiPlxruC3Lu8cn4l/tBaJPGWwYaILK+om3StbebhCxrqqp3Ypa4erVuyYOpV4 oocw== X-Gm-Message-State: AFqh2krhZsl0LoMsaz8yuXPM/UmCDZxnsnBByMlgbcbT2zlfaAP2wavU rT56SeHtxXWns8E/g6eo2WSOpzIOTBJLyQ== X-Received: by 2002:a62:36c4:0:b0:578:7e9d:97b2 with SMTP id d187-20020a6236c4000000b005787e9d97b2mr25223491pfa.3.1672134716421; Tue, 27 Dec 2022 01:51:56 -0800 (PST) Received: from hcdev-d520mt2.. (60-250-192-107.hinet-ip.hinet.net. [60.250.192.107]) by smtp.gmail.com with ESMTPSA id 21-20020a621515000000b005813aec74bdsm2619052pfv.139.2022.12.27.01.51.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Dec 2022 01:51:56 -0800 (PST) From: Marvin Lin To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl, avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, andrzej.p@collabora.com Cc: devicetree@vger.kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, kwliu@nuvoton.com, kflin@nuvoton.com, Marvin Lin , Krzysztof Kozlowski Subject: [PATCH v10 2/7] media: dt-binding: nuvoton: Add NPCM VCD and ECE engine Date: Tue, 27 Dec 2022 17:51:18 +0800 Message-Id: <20221227095123.2447948-3-milkfafa@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221227095123.2447948-1-milkfafa@gmail.com> References: <20221227095123.2447948-1-milkfafa@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753360563170578888?= X-GMAIL-MSGID: =?utf-8?q?1753360563170578888?= Add dt-binding document for Video Capture/Differentiation Engine (VCD) and Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs. Signed-off-by: Marvin Lin Reviewed-by: Krzysztof Kozlowski --- .../bindings/media/nuvoton,npcm-ece.yaml | 43 +++++++++++ .../bindings/media/nuvoton,npcm-vcd.yaml | 72 +++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/nuvoton,npcm-ece.yaml create mode 100644 Documentation/devicetree/bindings/media/nuvoton,npcm-vcd.yaml diff --git a/Documentation/devicetree/bindings/media/nuvoton,npcm-ece.yaml b/Documentation/devicetree/bindings/media/nuvoton,npcm-ece.yaml new file mode 100644 index 000000000000..b47468e54504 --- /dev/null +++ b/Documentation/devicetree/bindings/media/nuvoton,npcm-ece.yaml @@ -0,0 +1,43 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/nuvoton,npcm-ece.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton NPCM Encoding Compression Engine + +maintainers: + - Joseph Liu + - Marvin Lin + +description: | + Video Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs. + +properties: + compatible: + enum: + - nuvoton,npcm750-ece + - nuvoton,npcm845-ece + + reg: + maxItems: 1 + + resets: + maxItems: 1 + +required: + - compatible + - reg + - resets + +additionalProperties: false + +examples: + - | + #include + + ece: video-codec@f0820000 { + compatible = "nuvoton,npcm750-ece"; + reg = <0xf0820000 0x2000>; + resets = <&rstc NPCM7XX_RESET_IPSRST2 NPCM7XX_RESET_ECE>; + }; diff --git a/Documentation/devicetree/bindings/media/nuvoton,npcm-vcd.yaml b/Documentation/devicetree/bindings/media/nuvoton,npcm-vcd.yaml new file mode 100644 index 000000000000..c885f559d2e5 --- /dev/null +++ b/Documentation/devicetree/bindings/media/nuvoton,npcm-vcd.yaml @@ -0,0 +1,72 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/nuvoton,npcm-vcd.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton NPCM Video Capture/Differentiation Engine + +maintainers: + - Joseph Liu + - Marvin Lin + +description: | + Video Capture/Differentiation Engine (VCD) present on Nuvoton NPCM SoCs. + +properties: + compatible: + enum: + - nuvoton,npcm750-vcd + - nuvoton,npcm845-vcd + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + resets: + maxItems: 1 + + nuvoton,sysgcr: + $ref: /schemas/types.yaml#/definitions/phandle + description: phandle to access GCR (Global Control Register) registers. + + nuvoton,sysgfxi: + $ref: /schemas/types.yaml#/definitions/phandle + description: phandle to access GFXI (Graphics Core Information) registers. + + nuvoton,ece: + $ref: /schemas/types.yaml#/definitions/phandle + description: phandle to access ECE (Encoding Compression Engine) registers. + + memory-region: + maxItems: 1 + description: + CMA pool to use for buffers allocation instead of the default CMA pool. + +required: + - compatible + - reg + - interrupts + - resets + - nuvoton,sysgcr + - nuvoton,sysgfxi + - nuvoton,ece + +additionalProperties: false + +examples: + - | + #include + #include + + vcd: vcd@f0810000 { + compatible = "nuvoton,npcm750-vcd"; + reg = <0xf0810000 0x10000>; + interrupts = ; + resets = <&rstc NPCM7XX_RESET_IPSRST2 NPCM7XX_RESET_VCD>; + nuvoton,sysgcr = <&gcr>; + nuvoton,sysgfxi = <&gfxi>; + nuvoton,ece = <&ece>; + }; From patchwork Tue Dec 27 09:51:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marvin Lin X-Patchwork-Id: 36800 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1311661wrt; Tue, 27 Dec 2022 01:54:11 -0800 (PST) X-Google-Smtp-Source: AMrXdXvDrQ0UkKmjYcGjx2rhICAyWc0PIiAvsrAkVuVGL7ZOGJAsFJ2p+JTL2EDNqGQgin2zRcak X-Received: by 2002:a05:6402:40c5:b0:473:ae62:40d0 with SMTP id z5-20020a05640240c500b00473ae6240d0mr26611775edb.7.1672134851740; Tue, 27 Dec 2022 01:54:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672134851; cv=none; d=google.com; s=arc-20160816; b=uokuzrdvbNotDJXZnQWtemjQWJ7L4Hgsj2i94V4Gw4mqurltccu2M/jF22P7MWeuDb NkprlWtv9ovSnAgnlw938pAJLnqRLgAe7NGjVseC+yw6fnX8dipWw7d7uauDmu0jzR2N XoyVJ0bZp+rQ7dJzKkxlxvse+/3f0OsRmE3GyVSS7y26LK5eSGfEvB+xgxrQxJ6BcvuJ 8RNlkwBxcDoREGl5w9b5AAzGwlckeAj1pTLCQO4EPA+sX8378h+ZrqHF8mmVI3XR2UB8 CNoPfOPERqM3sPHKdehGEIEpQzMbjRn2O9miqd5IZ/44cuZT/Sx2JM9kDAxW5RxOA2JT yxXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nxkElKmgrqtTP5be0jVrJHJmBiDppX9Zdl7lKzzovCQ=; b=mflvrB+leCYxz0MnUSTFF/sBKxcwu4IAaruzufujsD1K+nHYoOMYsb6CHTSec3Gmc8 ixBwEg4LdzTTZlI7FgsL83hNPJpEix3I3UqfQtQSYBA4yl86S3fa9MzHUeNFuK3Nb7Lc T8X8Kr+CP+5qU0T23kgltlf9AZEtChi9ZOaJxvwQ6HyFOw6ZZjATSzZcAJxm2i0Q5MCo vgIImUH6iDe1qpsefy1p7Wxn4YndmhlC/3NRb2819xQtPC1oL1iPLHE1MWsRw+DMGR03 +2QegZ2d89IRWE9z+2Ei7N7jHh0PpF4aZAYGUzDVP89j9jbiXT3Cm7wJKeHfJldJk0GI RBbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pn9bWV2m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n9-20020a05640205c900b0045d27c0ba90si11596397edx.577.2022.12.27.01.53.47; Tue, 27 Dec 2022 01:54:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=pn9bWV2m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231263AbiL0JwQ (ORCPT + 99 others); Tue, 27 Dec 2022 04:52:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231215AbiL0JwE (ORCPT ); Tue, 27 Dec 2022 04:52:04 -0500 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C41E9FED; Tue, 27 Dec 2022 01:52:00 -0800 (PST) Received: by mail-pj1-x102a.google.com with SMTP id h7-20020a17090aa88700b00225f3e4c992so4163201pjq.1; Tue, 27 Dec 2022 01:52:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=nxkElKmgrqtTP5be0jVrJHJmBiDppX9Zdl7lKzzovCQ=; b=pn9bWV2mFXImcDnXT/ZYc6mZuqBpqqHEMG2I8uDVhburANDTQ6g3gqHSk60xuAbOxN YbgJFlGmUFRLXXWtexwTRev0H2jrHYcC6sHRyaIvbK7Pc3hVg5bhiM/aE71tKR7/RzFt 3KkvMRJ8el/7lhHHxDpi24IL5q3Zudz/JdbHKxbS5+753Sa3AEVBB2ScCm6N+GiwzOLO zRwW0TKEsv7tY9J+QCJUfrTxDYIwlweZn2xuPqMMjCxXsFqO4OMkaghE3g+ZPY+yIujK /zWnfCU91J168dDEgBz4wAyZmli9BvIcpY38jIYKMmw93dDQKGL3zs88T9oBVNMyfh9a 1/gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=nxkElKmgrqtTP5be0jVrJHJmBiDppX9Zdl7lKzzovCQ=; b=70Eky/z8znv7B6vMLlEna48jAoeBRKZcqg17I5k9N6q5Ns/5LwgB/NDIrAftHhH+8g Xtl/yo/4hCOHjvpV7WJClYsjYj5mmH/SDzTIW8O6eT6qoUdhKarpoD4OYKb//LkFk8J1 04QqpxOHKVDtrHuAB+6iy6OVhLj1hF0KyxzT0EksYH537EEq/M947taYDQNRNExEgzrK mbPJufiHSdJHJoZQV2UzdpuJjzgTuKcBbBdi6RvDHH8h4Z85Nbj+kzVsh+ArmvyQcWj3 9MqHeXMD0FoZa7pVxCtE+MID4fpHF3fHwWEpwB7OO8rd8leHDBmtPV8NloLT4Du0NTDF nSwg== X-Gm-Message-State: AFqh2ko0Ih5J1ZbvT1m+YHJsXoDcryBp3Y/NXzq0xqzFf8ccxZOp7KlA vSiJ0HicyLIOvXYDlkte3gbTryzlajkTYA== X-Received: by 2002:a05:6a21:1507:b0:9d:efbe:529a with SMTP id nq7-20020a056a21150700b0009defbe529amr25598732pzb.10.1672134719625; Tue, 27 Dec 2022 01:51:59 -0800 (PST) Received: from hcdev-d520mt2.. (60-250-192-107.hinet-ip.hinet.net. [60.250.192.107]) by smtp.gmail.com with ESMTPSA id 21-20020a621515000000b005813aec74bdsm2619052pfv.139.2022.12.27.01.51.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Dec 2022 01:51:59 -0800 (PST) From: Marvin Lin To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl, avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, andrzej.p@collabora.com Cc: devicetree@vger.kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, kwliu@nuvoton.com, kflin@nuvoton.com, Marvin Lin , Krzysztof Kozlowski Subject: [PATCH v10 3/7] dt-bindings: arm: nuvoton: Add bindings for NPCM GFXI Date: Tue, 27 Dec 2022 17:51:19 +0800 Message-Id: <20221227095123.2447948-4-milkfafa@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221227095123.2447948-1-milkfafa@gmail.com> References: <20221227095123.2447948-1-milkfafa@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753360474669865464?= X-GMAIL-MSGID: =?utf-8?q?1753360474669865464?= Add dt-bindings document for Graphics Core Information (GFXI) node. It is used by NPCM video driver to retrieve Graphics core information. Signed-off-by: Marvin Lin Reviewed-by: Krzysztof Kozlowski --- .../bindings/arm/npcm/nuvoton,gfxi.yaml | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Documentation/devicetree/bindings/arm/npcm/nuvoton,gfxi.yaml diff --git a/Documentation/devicetree/bindings/arm/npcm/nuvoton,gfxi.yaml b/Documentation/devicetree/bindings/arm/npcm/nuvoton,gfxi.yaml new file mode 100644 index 000000000000..c033128e567a --- /dev/null +++ b/Documentation/devicetree/bindings/arm/npcm/nuvoton,gfxi.yaml @@ -0,0 +1,39 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/arm/npcm/nuvoton,gfxi.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Graphics Core Information block in Nuvoton SoCs + +maintainers: + - Joseph Liu + - Marvin Lin + +description: + The Graphics Core Information (GFXI) are a block of registers in Nuvoton SoCs + that analyzes Graphics core behavior and provides information in registers. + +properties: + compatible: + items: + - enum: + - nuvoton,npcm750-gfxi + - nuvoton,npcm845-gfxi + - const: syscon + + reg: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + gfxi: gfxi@e000 { + compatible = "nuvoton,npcm750-gfxi", "syscon"; + reg = <0xe000 0x100>; + }; From patchwork Tue Dec 27 09:51:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marvin Lin X-Patchwork-Id: 36801 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1311675wrt; Tue, 27 Dec 2022 01:54:12 -0800 (PST) X-Google-Smtp-Source: AMrXdXuEjHZ9WANJJbWgBz97kWhZDUuAhRe8erbF7dgzZ1J92n57MQlDRqHEu8fkqlJwo1bxbJct X-Received: by 2002:a17:906:9f28:b0:7c1:5b5e:4d85 with SMTP id fy40-20020a1709069f2800b007c15b5e4d85mr17253210ejc.51.1672134852658; Tue, 27 Dec 2022 01:54:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672134852; cv=none; d=google.com; s=arc-20160816; b=eXThF1vwUlh8jbGWJVX7TFFLfOKQ1n+C9uMEXFduzyISKiBTNZl/QGHeKrVoBPiRdo dbkdXuOaWoCG6MbssL6oYBbYVINZ6Ksg3Zef980F6T9cxnerj9JeuVNQHX59eufPhhvw 59SSe1pGJPM3AfqsGre+81ucQvRv0MbNiXG+vnKB+qcyAVmbJXuilaeayfCzhArXbZ2W umAEokCS5n7Chc6y6zJm/5ocsGExsnZX0XfcORA5RhoQozYndaWVQyB4rYSx5MNIj9or 94faLietrmewgfYL78kw15+AvWx5dtPCWJ8Voe4Q3NTxU85Fgc2JuKX8q5+vll+c2FjD 3uAw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=g/uLvTJmmBzuds9Az0fvihrnUknv2MS6FQWlRinADjY=; b=jfeEidzLjMYs7PynL0GRSC0NbUcD7BrDz0aHdlgSttGhwijCAWM4zZE4PsuunrIVjD RIbC0281xRTXN73lVip1NgmCfAplZDrUGZoCtFBw5PIBNAbOAjiW0TbzDzFUj4yHZNYK e84+UHE5r56jcn2UNiEJA/cNwCtfYttjTBxubME6wp3Kwtrjyw8o1+HMFWlEX/VlxaGK Frf7EsXp7o1w2GG2VpSDIpRtF92dy5nNaiEDrHTSS88PShB+2d0jOVnm8ZtFUd+MtKZJ UfF/MjdJtLVofNppJapm+W26v/aveWzx8MXnKr/7tNbol94sHFsO1a3oEM9BGYoZSh2W tyxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=nN0K55Cw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wu2-20020a170906eec200b00840f80a0b03si9405591ejb.118.2022.12.27.01.53.49; Tue, 27 Dec 2022 01:54:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=nN0K55Cw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231332AbiL0JwU (ORCPT + 99 others); Tue, 27 Dec 2022 04:52:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231374AbiL0JwJ (ORCPT ); Tue, 27 Dec 2022 04:52:09 -0500 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [IPv6:2607:f8b0:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A89B4A19F; Tue, 27 Dec 2022 01:52:03 -0800 (PST) Received: by mail-pf1-x42e.google.com with SMTP id z7so2888189pfq.13; Tue, 27 Dec 2022 01:52:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=g/uLvTJmmBzuds9Az0fvihrnUknv2MS6FQWlRinADjY=; b=nN0K55Cwt0ZufGIqodSrPZyy1QnTmi5nmzDp7pVA8UtSvdu9HCMs4UXQjciAQpP2sN LQDvOFv4Vb570I0VdTl+W6MO1Ok5Eh+402oKKV08jpEVQydwlI+DApXCNqagXhUKzRaY clcwfEEwZ6ciLKgqK4p8TR1mHIGIahoMZ7u2ERP8ANyNe4hZF4/7Tk3pUSnoI2fOHKV0 QqCBvRgCR/8B40O1gIEaJleiTs3FE/HYM9EtJ67fLSIu9tj1tk6nuR/Eitf9a6flCU+d 8t3XTtdy4kvrF72mF6CaQJ53sfk2fOh6HDfVq3vgHLh5Qjyvv6LIH6TyZg/9iswmzrGl gliw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=g/uLvTJmmBzuds9Az0fvihrnUknv2MS6FQWlRinADjY=; b=ASKMhqwIM/BRgCEC4+bkUPFeXtvo0jJTpWMaK5MyGoXoo796EbQb7xkWevWTEEfFus MoRB/vHc+mE8Ydoph7LXo2tCg816g+v5F6mmMmuyIjKAYmf3wWXsnJmyRR6XmJ6P8IYT ZQPF3fa28FNJsSPUmyeybuB6CYIJb5d5mtlQ/4HElgX6TghVRwk1E1Wjc14/xXXSPEKK UdN7DIHiyvubY02lxBFzZgDFIm4p8hTCy/32j4RAGM+4T2pCEJLr2QeWE2S1jQzm+Jp1 JXJV13iPRwio8aZeCqL067Hs6DAxeHy8isSG6pFNsy2pWCkROqtDvd92J18RUji0gwo9 V1Jw== X-Gm-Message-State: AFqh2kqW3Kft5tkzjVDwSGOPmapK1bSY/CTc6iCg7aAslPQBWZ4+CjxU XrbhsbC5nA0gLb82kobH0dU= X-Received: by 2002:a62:184c:0:b0:581:1e00:beeb with SMTP id 73-20020a62184c000000b005811e00beebmr8322309pfy.15.1672134722984; Tue, 27 Dec 2022 01:52:02 -0800 (PST) Received: from hcdev-d520mt2.. (60-250-192-107.hinet-ip.hinet.net. [60.250.192.107]) by smtp.gmail.com with ESMTPSA id 21-20020a621515000000b005813aec74bdsm2619052pfv.139.2022.12.27.01.51.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Dec 2022 01:52:02 -0800 (PST) From: Marvin Lin To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl, avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, andrzej.p@collabora.com Cc: devicetree@vger.kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, kwliu@nuvoton.com, kflin@nuvoton.com, Marvin Lin , Nicolas Dufresne Subject: [PATCH v10 4/7] media: v4l: Add HEXTILE compressed format Date: Tue, 27 Dec 2022 17:51:20 +0800 Message-Id: <20221227095123.2447948-5-milkfafa@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221227095123.2447948-1-milkfafa@gmail.com> References: <20221227095123.2447948-1-milkfafa@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753360475571211512?= X-GMAIL-MSGID: =?utf-8?q?1753360475571211512?= Add HEXTILE compressed format which is defined in Remote Framebuffer Protocol (RFC 6143, chapter 7.7.4 Hextile Encoding) and is used by Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs. Signed-off-by: Marvin Lin Reviewed-by: Nicolas Dufresne --- Documentation/userspace-api/media/v4l/pixfmt-reserved.rst | 7 +++++++ drivers/media/v4l2-core/v4l2-ioctl.c | 1 + include/uapi/linux/videodev2.h | 1 + 3 files changed, 9 insertions(+) diff --git a/Documentation/userspace-api/media/v4l/pixfmt-reserved.rst b/Documentation/userspace-api/media/v4l/pixfmt-reserved.rst index 73cd99828010..e6ee0eebe691 100644 --- a/Documentation/userspace-api/media/v4l/pixfmt-reserved.rst +++ b/Documentation/userspace-api/media/v4l/pixfmt-reserved.rst @@ -275,6 +275,13 @@ please make a proposal on the linux-media mailing list. Decoder's implementation can be found here, `aspeed_codec `__ + * .. _V4L2-PIX-FMT-HEXTILE: + + - ``V4L2_PIX_FMT_HEXTILE`` + - 'HXTL' + - Compressed format used by Nuvoton NPCM video driver. This format is + defined in Remote Framebuffer Protocol (RFC 6143, chapter 7.7.4 Hextile + Encoding). .. raw:: latex \normalsize diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c index 8e0a0ff62a70..a0e387335139 100644 --- a/drivers/media/v4l2-core/v4l2-ioctl.c +++ b/drivers/media/v4l2-core/v4l2-ioctl.c @@ -1494,6 +1494,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt) case V4L2_PIX_FMT_QC08C: descr = "QCOM Compressed 8-bit Format"; break; case V4L2_PIX_FMT_QC10C: descr = "QCOM Compressed 10-bit Format"; break; case V4L2_PIX_FMT_AJPG: descr = "Aspeed JPEG"; break; + case V4L2_PIX_FMT_HEXTILE: descr = "Hextile Compressed Format"; break; default: if (fmt->description[0]) return; diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h index 1befd181a4cc..1ce21cc4fbf1 100644 --- a/include/uapi/linux/videodev2.h +++ b/include/uapi/linux/videodev2.h @@ -778,6 +778,7 @@ struct v4l2_pix_format { #define V4L2_PIX_FMT_QC08C v4l2_fourcc('Q', '0', '8', 'C') /* Qualcomm 8-bit compressed */ #define V4L2_PIX_FMT_QC10C v4l2_fourcc('Q', '1', '0', 'C') /* Qualcomm 10-bit compressed */ #define V4L2_PIX_FMT_AJPG v4l2_fourcc('A', 'J', 'P', 'G') /* Aspeed JPEG */ +#define V4L2_PIX_FMT_HEXTILE v4l2_fourcc('H', 'X', 'T', 'L') /* Hextile compressed */ /* 10bit raw packed, 32 bytes for every 25 pixels, last LSB 6 bits unused */ #define V4L2_PIX_FMT_IPU3_SBGGR10 v4l2_fourcc('i', 'p', '3', 'b') /* IPU3 packed 10-bit BGGR bayer */ From patchwork Tue Dec 27 09:51:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marvin Lin X-Patchwork-Id: 36802 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1311677wrt; Tue, 27 Dec 2022 01:54:13 -0800 (PST) X-Google-Smtp-Source: AMrXdXuJDpR1INkZJpTISmo+oJ5dVnfvlEVIyauu95CnDEJqZRDh4eYrQRt9dq0vsqiOHVdHBIeA X-Received: by 2002:a05:6402:48c:b0:483:d49f:e26c with SMTP id k12-20020a056402048c00b00483d49fe26cmr7796896edv.15.1672134853099; Tue, 27 Dec 2022 01:54:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672134853; cv=none; d=google.com; s=arc-20160816; b=l8Z/UKbchSUXAQgmx9/8p3gl/f0WWbFIrm3qvYnPCPv+TpiqbfNuaDDmoHyqIwnLXn vkzwMjESYrzJ6GzQIaT2YAw0TiPgJjIzClCiLvTAolhOH5dc6F5MCil6MJTer1+zBv5k 4nF1VStcKQtXllnDG44gv9REzUtRyZ8z2dhffJgrw4MgmNtRjmDyyp4TPxmrbHdCANgE JHr2JJHnppCvxQ65sJlhhMNAaUyABaZ7uANoM/Yyso3Ro+zdTFYdJ2/iR//xXurU12uj SPfHxb7+Y4kKiFILNZ55BbH6ED/UKVxg/S/6kcNRD9PbKSw6F2bqfEOzOVNj6srv70FS mI6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=xLpWFlG8mxCCWcewzRCKKTz15AMme8ZuJhE5IEg3io0=; b=SVUo6p5QhEoY2qIn80SsT/lmcoMdi0UtOCHH/0GzCIX+hIgc4+qNTldZmwMMWYFxl3 Xeif7jKjBjjVtevOUZbpLPQpY6aTmNzXlcB2VgHQusDK4YfJc2CnNJrpUcS43CvJDnQz 8WjcsDsg5f/symLU2b7XDpRTRy6nxuPbuhKp8EpKdPDSYo9NP01AAQsiThAOK/TUA0Y5 LgzBbRjVvgM43uR0E180V3sM3BnBuag/KGp06uwtvq+MdhVKC+23tg/7gJ6yJr8Y1Wpg x2bf24OBdZNh3y/W0fCrAePboY+648+G0UvLUzvxhJVXVwmkdvODbJQwwtJiOTCJXIL3 032Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TkuNIbW4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q13-20020a170906770d00b007ade20fc40csi8611305ejm.810.2022.12.27.01.53.49; Tue, 27 Dec 2022 01:54:13 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=TkuNIbW4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231312AbiL0Jwu (ORCPT + 99 others); Tue, 27 Dec 2022 04:52:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231455AbiL0JwM (ORCPT ); Tue, 27 Dec 2022 04:52:12 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9A1FCA1BA; Tue, 27 Dec 2022 01:52:06 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id k137so3779150pfd.8; Tue, 27 Dec 2022 01:52:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=xLpWFlG8mxCCWcewzRCKKTz15AMme8ZuJhE5IEg3io0=; b=TkuNIbW419DCqnsMr8eROaVQRmpRqJUmz8qFDChR3AkvRG2XJwiv9WqKS3cZkR06pM m7kx4XFi3Zxf5mM7a76yH8bJsn+EXflGk8c+dFvTjSt35Ap8UegvtHW9JhCzwyEmoFZx dU4yrPuiKyI0uFiZpqWjXbdyL7b7LMRjcBWUkympMUPTpT22Or0BLRCoP1nNvFLVNM77 I8Eh7sj67inMzq/UU3vak5c4+UAKFKuKCpD0DxFwIlgywrW5AmXJAH9DFutP/5nYo/NJ U8bhgmhW/YpRvbA19PyUNJjoa5Yf0WPmL932dZzcKZh+yCnxmUpDQnUGGWM1KtjpjHuu +SPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=xLpWFlG8mxCCWcewzRCKKTz15AMme8ZuJhE5IEg3io0=; b=QXpGLekwp9uTTafHSbIgb4fOEl81wqxKO4Rtivo6I9wjn+GTyJzrP8WcB789Ftt8dG /JAoJI+uHpm4DToYT4Q461/a8zgT3CTfvFlsHq/iKiJViI7T1KYh1tmmar3b7VBvisLP W4Q7DHUKKdNL6Rr/riZRXRLsz2UY4AEUAoAagijkm6742fO69SUAktxQRmFAO/BPegPp EhAF3I4UNVhTeBUj5QXl9brD8/8BlHgUobstpVCTOXaSMK9CHfWXJtiVrNvbo8447cjz g/jNJh/4W5+NrR5eD+UYZz7T26oBeLCLIjMCVPrhyzGA0obzsoGKulL7dnDoYJnrOvMJ YjUw== X-Gm-Message-State: AFqh2kq+IsCVYKbe3z6WlUSKvMV5LhjaWAkeOBiFwrc3Z3KhwoHjvlP4 3Vg7cfIZtCjmb7OkbPHpE0+65ezw0aEClg== X-Received: by 2002:a62:bd19:0:b0:566:900d:a1de with SMTP id a25-20020a62bd19000000b00566900da1demr23770765pff.26.1672134726050; Tue, 27 Dec 2022 01:52:06 -0800 (PST) Received: from hcdev-d520mt2.. (60-250-192-107.hinet-ip.hinet.net. [60.250.192.107]) by smtp.gmail.com with ESMTPSA id 21-20020a621515000000b005813aec74bdsm2619052pfv.139.2022.12.27.01.52.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Dec 2022 01:52:05 -0800 (PST) From: Marvin Lin To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl, avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, andrzej.p@collabora.com Cc: devicetree@vger.kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, kwliu@nuvoton.com, kflin@nuvoton.com, Marvin Lin Subject: [PATCH v10 5/7] media: v4l2-ctrls: Reserve user control base for NPCM video controls Date: Tue, 27 Dec 2022 17:51:21 +0800 Message-Id: <20221227095123.2447948-6-milkfafa@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221227095123.2447948-1-milkfafa@gmail.com> References: <20221227095123.2447948-1-milkfafa@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753360475549678177?= X-GMAIL-MSGID: =?utf-8?q?1753360475549678177?= Add a control base and reserve 16 controls for Nuvoton NPCM video controls. Signed-off-by: Marvin Lin --- include/uapi/linux/v4l2-controls.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/uapi/linux/v4l2-controls.h b/include/uapi/linux/v4l2-controls.h index b73a8ba7df6c..aa5c9f64f1d6 100644 --- a/include/uapi/linux/v4l2-controls.h +++ b/include/uapi/linux/v4l2-controls.h @@ -199,6 +199,12 @@ enum v4l2_colorfx { */ #define V4L2_CID_USER_ASPEED_BASE (V4L2_CID_USER_BASE + 0x11a0) +/* + * The base for Nuvoton NPCM driver controls. + * We reserve 16 controls for this driver. + */ +#define V4L2_CID_USER_NPCM_BASE (V4L2_CID_USER_BASE + 0x11b0) + /* MPEG-class control IDs */ /* The MPEG controls are applicable to all codec controls * and the 'MPEG' part of the define is historical */ From patchwork Tue Dec 27 09:51:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marvin Lin X-Patchwork-Id: 36804 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1311843wrt; Tue, 27 Dec 2022 01:54:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXt9htVXIk5J4vV8DZRhYHc3iu4LDmAlSC923ujYP5ULXwxPhaCEPr3zwCjTXg2fvfl6JEen X-Received: by 2002:a17:903:3111:b0:192:5c3e:894e with SMTP id w17-20020a170903311100b001925c3e894emr13370252plc.16.1672134893517; Tue, 27 Dec 2022 01:54:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672134893; cv=none; d=google.com; s=arc-20160816; b=YoZhfnO3Tu20XKBqfapEvDrs/Neo4EDuzkVPZICiBsR1HxkIk3bDSnt0j92vv6mblX uv66xmR2sRwR3jIfJR84xRchC3os3oLExjMsOHpnmKciy2whR6LfUe3PWwJA2tgDc+rn cgElTIaOT96S0/Z/RNGFupzdGVEkcxbkXks/mapsrnSoJMPIybgm5jx8i9gObyk+xXSq GOySB9lsEmTfAHcu2GuZeY2FdyzzCHywUMwCQPw6nt+8NWD7pi0ghW3EmIvY19Z3BR0o lEe0L4zgHCfTjd0ZDbzWCd8/sRkj5OVPIfyflFGQM8SyM4gOPVvw5rsppHUeQd2pggYH SLCQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=i3swy6qz7DvZvAluAP+tU7pAgPPOXXX+hPPdHMPIYTg=; b=mSgnIB/XSxyolP8Yk+Xby3SAkO+Vq9jkI4W/+UpZMm1JwUR/t5NjLt+ds79HRQUfH9 3uExvx3C5aSmH9N0lGLETyBrx9Xs2xSJxQh41fYC8142zdvqqcmAl4yHq4FOGfXFrbbZ rRH3aPP8P5voik44smLIu1Kd3v9DOzLacktQFUDXdAwxNOaJLG7pDosbBJMArIeIPZUt AtYcYXxxQ18CVd0coA2GYw8q5fVP6hAlEn+aawr6HXEtH4VAKV5DW2FRGLxJwO694cjw RoGODTEzcQM0XlFLJiFNoTifYAK+pPOk9GCVDWnWkQs4EKTa1Ru2e3mcqECHWUfOAivb lyxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=aErG3oRj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p9-20020a1709026b8900b001898ecbeef8si12942796plk.9.2022.12.27.01.54.41; Tue, 27 Dec 2022 01:54:53 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=aErG3oRj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231394AbiL0Jwx (ORCPT + 99 others); Tue, 27 Dec 2022 04:52:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231379AbiL0JwV (ORCPT ); Tue, 27 Dec 2022 04:52:21 -0500 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F11009FE4; Tue, 27 Dec 2022 01:52:09 -0800 (PST) Received: by mail-pj1-x1036.google.com with SMTP id v13-20020a17090a6b0d00b00219c3be9830so12750212pjj.4; Tue, 27 Dec 2022 01:52:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i3swy6qz7DvZvAluAP+tU7pAgPPOXXX+hPPdHMPIYTg=; b=aErG3oRj5SOjAyxRD7qJEBvDmQmn5AduZi0hquXRdjZUkBSY+3fQ3YIjpQ0KOZLVX4 nEDFnRuZfisOyvzMoiuzRECUUmBR3vp2i4R2S58ToC5Tke81T15KnatG8sK1EKYLqWQ4 MB057VrMRSgdBUvxLtYdTMWFDpGis9y2h79A8TyG/LX69GUNV8bbY0Tr0XSn0hHjdO8R oA5XNuRDiUQkgmPiKtrBhPGoxc0eqehD6tup+/zAbWYe1KeDjGoRbJLUp1XPhyFGxgiZ PHxxB/0A9QeFtmm5uHigetzcYtpij1XLju28ddkHXE8uUlIKbn/6NHOdJr+Is9Yti9hN oLJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i3swy6qz7DvZvAluAP+tU7pAgPPOXXX+hPPdHMPIYTg=; b=p6IDTqzi+ekPdiQz03UjpnxkuiyWRuguw9H6UPCyvvlUVvavwEzQZudV+IaXBrXcp1 pqIrou69VXfJrXQqnWeXRCDYIPi4httwOMQn5GHsvdb8tvYAa8CowJUt4w2r27cDjyny bYTQOCJLBhkcP75vw9VCNRtHPj7+D/u3lq+AInrVtCFl0/CZE+nSb9m9R82Y2BOvh2fF ZQzVLTrCVtdS3kqwYdVmIokqBOFxQ8pGuvMkmHvURRWgXLXttumQPfInlaZbXUXMxPI0 VVUxSJV2babOaICw3EEAJ2o1Ln4qAHprLE346ciAEHa4aT9ssbQYbQZuH0gOuxEBebRT uUYA== X-Gm-Message-State: AFqh2kq4KGma4QRwNdC9d02QbhbIdZ3KXRT7ClVKOu7L2ktO2noTO6AW /UPxkEYLxM09+VTlyrVbrCM= X-Received: by 2002:a05:6a20:e616:b0:a6:7529:7c99 with SMTP id my22-20020a056a20e61600b000a675297c99mr25819590pzb.5.1672134729168; Tue, 27 Dec 2022 01:52:09 -0800 (PST) Received: from hcdev-d520mt2.. (60-250-192-107.hinet-ip.hinet.net. [60.250.192.107]) by smtp.gmail.com with ESMTPSA id 21-20020a621515000000b005813aec74bdsm2619052pfv.139.2022.12.27.01.52.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Dec 2022 01:52:08 -0800 (PST) From: Marvin Lin To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl, avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, andrzej.p@collabora.com Cc: devicetree@vger.kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, kwliu@nuvoton.com, kflin@nuvoton.com, Marvin Lin Subject: [PATCH v10 6/7] media: uapi: Add controls for NPCM video driver Date: Tue, 27 Dec 2022 17:51:22 +0800 Message-Id: <20221227095123.2447948-7-milkfafa@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221227095123.2447948-1-milkfafa@gmail.com> References: <20221227095123.2447948-1-milkfafa@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753360517956010483?= X-GMAIL-MSGID: =?utf-8?q?1753360517956010483?= Create controls for Nuvoton NPCM video driver to support setting capture mode of Video Capture/Differentiation (VCD) engine and getting the count of HEXTILE rectangles that is compressed by Encoding Compression Engine (ECE). Signed-off-by: Marvin Lin --- .../userspace-api/media/drivers/index.rst | 1 + .../media/drivers/npcm-video.rst | 67 +++++++++++++++++++ include/uapi/linux/npcm-video.h | 41 ++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 Documentation/userspace-api/media/drivers/npcm-video.rst create mode 100644 include/uapi/linux/npcm-video.h diff --git a/Documentation/userspace-api/media/drivers/index.rst b/Documentation/userspace-api/media/drivers/index.rst index 915dbf0f4db5..97d2ce8da6b3 100644 --- a/Documentation/userspace-api/media/drivers/index.rst +++ b/Documentation/userspace-api/media/drivers/index.rst @@ -38,6 +38,7 @@ For more details see the file COPYING in the source distribution of Linux. imx-uapi max2175 meye-uapi + npcm-video omap3isp-uapi st-vgxy61 uvcvideo diff --git a/Documentation/userspace-api/media/drivers/npcm-video.rst b/Documentation/userspace-api/media/drivers/npcm-video.rst new file mode 100644 index 000000000000..abe9aac8fd34 --- /dev/null +++ b/Documentation/userspace-api/media/drivers/npcm-video.rst @@ -0,0 +1,67 @@ +.. SPDX-License-Identifier: GPL-2.0 + +.. include:: + +NPCM video driver +================= + +This driver is used to control the Video Capture/Differentiation (VCD) engine +and Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs. The VCD can +capture and differentiate video data from digital or analog sources, then the +ECE will compress the data into HEXTILE format. + +Driver-specific Controls +------------------------ + +V4L2_CID_NPCM_CAPTURE_MODE +~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The VCD engine supports two modes: + +- COMPLETE mode: + + Capture the next complete frame into memory. + +- DIFF mode: + + Compare the incoming frame with the frame stored in memory, and updates the + differentiated frame in memory. + +Application can use ``V4L2_CID_NPCM_CAPTURE_MODE`` control to set the VCD mode +with different control values (enum v4l2_npcm_capture_mode): + +- ``V4L2_NPCM_CAPTURE_MODE_COMPLETE``: will set VCD to COMPLETE mode. +- ``V4L2_NPCM_CAPTURE_MODE_DIFF``: will set VCD to DIFF mode. + +V4L2_CID_NPCM_RECT_COUNT +~~~~~~~~~~~~~~~~~~~~~~~~ + +After frame data is captured, the ECE will compress the data into HEXTILE format +and store these HEXTILE rectangles data in V4L2 video buffer with the layout +defined in Remote Framebuffer Protocol: +:: + + (RFC 6143, https://www.rfc-editor.org/rfc/rfc6143.html#section-7.6.1) + + +--------------+--------------+-------------------+ + | No. of bytes | Type [Value] | Description | + +--------------+--------------+-------------------+ + | 2 | U16 | x-position | + | 2 | U16 | y-position | + | 2 | U16 | width | + | 2 | U16 | height | + | 4 | S32 | encoding-type (5) | + +--------------+--------------+-------------------+ + | HEXTILE rectangle data | + +-------------------------------------------------+ + +Application can get these video buffers through V4L2 interfaces and use +``V4L2_CID_NPCM_RECT_COUNT`` control to get the count of compressed HEXTILE +rectangles that can be put in the field number-of-rectangles of +FramebufferUpdate header. + +References +---------- +include/uapi/linux/npcm-video.h + +**Copyright** |copy| 2022 Nuvoton Technologies diff --git a/include/uapi/linux/npcm-video.h b/include/uapi/linux/npcm-video.h new file mode 100644 index 000000000000..1d39f6f38c96 --- /dev/null +++ b/include/uapi/linux/npcm-video.h @@ -0,0 +1,41 @@ +/* SPDX-License-Identifier: GPL-2.0+ WITH Linux-syscall-note */ +/* + * Controls header for NPCM video driver + * + * Copyright (C) 2022 Nuvoton Technologies + */ + +#ifndef _UAPI_LINUX_NPCM_VIDEO_H +#define _UAPI_LINUX_NPCM_VIDEO_H + +#include + +/* + * Check Documentation/userspace-api/media/drivers/npcm-video.rst for control + * details. + */ + +/* + * This control is meant to set the mode of NPCM Video Capture/Differentiation + * (VCD) engine. + * + * The VCD engine supports two modes: + * COMPLETE - Capture the next complete frame into memory. + * DIFF - Compare the incoming frame with the frame stored in memory, and + * updates the differentiated frame in memory. + */ +#define V4L2_CID_NPCM_CAPTURE_MODE (V4L2_CID_USER_NPCM_BASE + 0) + +enum v4l2_npcm_capture_mode { + V4L2_NPCM_CAPTURE_MODE_COMPLETE = 0, /* COMPLETE mode */ + V4L2_NPCM_CAPTURE_MODE_DIFF = 1, /* DIFF mode */ +}; + +/* + * This control is meant to get the count of compressed HEXTILE rectangles which + * is relevant to the number of differentiated frames if VCD is in DIFF mode. + * And the count will always be 1 if VCD is in COMPLETE mode. + */ +#define V4L2_CID_NPCM_RECT_COUNT (V4L2_CID_USER_NPCM_BASE + 1) + +#endif /* _UAPI_LINUX_NPCM_VIDEO_H */ From patchwork Tue Dec 27 09:51:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Marvin Lin X-Patchwork-Id: 36803 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp1311780wrt; Tue, 27 Dec 2022 01:54:40 -0800 (PST) X-Google-Smtp-Source: AMrXdXszqlq/dipxiRZ/NAiVyWpsi9lX7COho1lOQbJM8kd69HdfphpB37tyiZ/jpr/el79sxdk+ X-Received: by 2002:a05:6402:d4e:b0:46c:ab70:c009 with SMTP id ec14-20020a0564020d4e00b0046cab70c009mr16348170edb.27.1672134880456; Tue, 27 Dec 2022 01:54:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672134880; cv=none; d=google.com; s=arc-20160816; b=wR/zrqC08on8eU2UxoA8DuZJ+qVANROfFwDAI1pqFOd6p7Rw0kZrBszqoOohFPLOnQ HaHb7j3C8wXOqimSawyuklw8HHCwvYlZzK+QiUyJgiKPavLvDSrEJBnvAu79/XMVuKR8 WQgCaLt4xnhhAhqebzVztmA1XCvmMBo2euSmUgQjzQjBgplhDS3PHH6NXISsrI7Qtjln B7Jy+pNRmuvzMDuJPFPL4lOwhvmlK91hG4L4IMorIBXTLw8hVQmpkHHgeGv0SreDqoS0 oynPcUPw2Luj0KznKmNp/E59vP+/Nh06rO/JIUx6O9OkpOgtR3MN4DQ5OBaC7E1GzoZe JASg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EHzKu+7VE8wEb4Z4VGHH6BIHV+oKqYpQ6EroJaygCfE=; b=BgDyi97TsMaSsC+xWu9mIqZbRLFgT9xvhvlBcQikIi5q+GxBftMFHQScDyz+jIz8CB bfgrS4n9882M0y0iAPohI6L9rX0u9dRPUM3AdvQnKe+M9XFVyyhmhQ/QvMYoV5DuX62p 7ZNV7PFBrfJdlRQpoWCliw6FsqWGFk3lW4YdHXbKxCq5rnclHz2a29GztSkX5Wxvxg1t BvSc6onClsBFlSdSN1dxFO8A1FX5Uwd5huEzY2xhd3KOOfxreWN//LjilCE9shEL25AY Ak3uwaxih40pXkNkOSPpTSVRp0wIhN3hFoNRydFbS0E//kAmvVyxSsqzuaxty4Hrb/HN FCrg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AgXY+MnD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d5-20020a056402516500b0047ad7c7578fsi9663327ede.137.2022.12.27.01.54.16; Tue, 27 Dec 2022 01:54:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=AgXY+MnD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231580AbiL0JxT (ORCPT + 99 others); Tue, 27 Dec 2022 04:53:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231563AbiL0Jw1 (ORCPT ); Tue, 27 Dec 2022 04:52:27 -0500 Received: from mail-pj1-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53CE9A18C; Tue, 27 Dec 2022 01:52:13 -0800 (PST) Received: by mail-pj1-x1033.google.com with SMTP id p4so12784784pjk.2; Tue, 27 Dec 2022 01:52:13 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=EHzKu+7VE8wEb4Z4VGHH6BIHV+oKqYpQ6EroJaygCfE=; b=AgXY+MnD9qvg/L8rzVaGQsLmmlyosMTR7LZNPTQa0sZ6V31ZrER6KsvKZ6Z5UOFkrj dacOM8qv57LA8BuZevaQFItbLtrpvUOcXdzShPTDlC2oLPYqEspFNJo0+khhNgzKoi7k iqnhM7WrOyDCqGVc47oWF1pHGKLsas817Vi5+26xS95mVgNkkV7NXtVfH8Oys2hfF0T0 5xuFp14rlKAlGKeM5HMGiW45+aVtXQgfkR1bcGXB9rltgRIu0ZVEQOJMLDTA/26SlhVv 5F0uAPyyALJQ5kVGNdwO6TUk4OTqq1lNpDWE+bCQWCBaRBWNaNswCyS38xVHlqq+tccD 6B5Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=EHzKu+7VE8wEb4Z4VGHH6BIHV+oKqYpQ6EroJaygCfE=; b=YuHvg92qx7iaeS4gKbq7+xhX5dLK3a2S99uLi55C3Qh5eGzI2dGSDBfvXOnnoaheKj J2XaMa5H3dRnrb1XmLQoImSp1WVQ4lAkDiF6hOzRme7Cx08dCtxtkRLkWoS7UZ3yq/nv m4y5SXxfDlqyqIqpR1bseYmjg1iwTMjSfnXrjMtOnqn7uV8LNxDe32RXNhG7ZgYhfYPm t3mevfU7Vc+aiSnoMy8mLNu7aHEWZRxbKNhMo5ROjFkFg35S7V4+QwlplpwaNKwHaW87 8TUYlumYqURVQZJGm6Tkz60LoGKcqGcmwAgf93TCV4YlIgIERQTzPPUJ1l2VC4yXrg/1 ZlRw== X-Gm-Message-State: AFqh2kqWqAtzXHduggA962rMP7sUIncENj0hTz2idKZuc8AMS6jT+tIQ VutpJOkx0Iu/Qe2sB81e/gA= X-Received: by 2002:a05:6a20:6a83:b0:ab:fe5a:df95 with SMTP id bi3-20020a056a206a8300b000abfe5adf95mr22573619pzb.15.1672134732520; Tue, 27 Dec 2022 01:52:12 -0800 (PST) Received: from hcdev-d520mt2.. (60-250-192-107.hinet-ip.hinet.net. [60.250.192.107]) by smtp.gmail.com with ESMTPSA id 21-20020a621515000000b005813aec74bdsm2619052pfv.139.2022.12.27.01.52.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Dec 2022 01:52:12 -0800 (PST) From: Marvin Lin To: mchehab@kernel.org, hverkuil-cisco@xs4all.nl, avifishman70@gmail.com, tmaimon77@gmail.com, tali.perry1@gmail.com, venture@google.com, yuenn@google.com, benjaminfair@google.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, andrzej.p@collabora.com Cc: devicetree@vger.kernel.org, linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, openbmc@lists.ozlabs.org, kwliu@nuvoton.com, kflin@nuvoton.com, Marvin Lin Subject: [PATCH v10 7/7] media: nuvoton: Add driver for NPCM video capture and encode engine Date: Tue, 27 Dec 2022 17:51:23 +0800 Message-Id: <20221227095123.2447948-8-milkfafa@gmail.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221227095123.2447948-1-milkfafa@gmail.com> References: <20221227095123.2447948-1-milkfafa@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1753360504727123642?= X-GMAIL-MSGID: =?utf-8?q?1753360504727123642?= Add driver for Video Capture/Differentiation Engine (VCD) and Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs. The VCD can capture and differentiate video data from digital or analog sources, then the ECE will compress the data into HEXTILE format. This driver implements V4L2 interfaces and provides user controls to support KVM feature, also tested with VNC Viewer and openbmc/obmc-ikvm. Signed-off-by: Marvin Lin --- MAINTAINERS | 12 + drivers/media/platform/Kconfig | 1 + drivers/media/platform/Makefile | 1 + drivers/media/platform/nuvoton/Kconfig | 15 + drivers/media/platform/nuvoton/Makefile | 2 + drivers/media/platform/nuvoton/npcm-regs.h | 171 ++ drivers/media/platform/nuvoton/npcm-video.c | 1814 +++++++++++++++++++ 7 files changed, 2016 insertions(+) create mode 100644 drivers/media/platform/nuvoton/Kconfig create mode 100644 drivers/media/platform/nuvoton/Makefile create mode 100644 drivers/media/platform/nuvoton/npcm-regs.h create mode 100644 drivers/media/platform/nuvoton/npcm-video.c diff --git a/MAINTAINERS b/MAINTAINERS index f61eb221415b..1b56042d1dc3 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -2603,6 +2603,18 @@ F: drivers/rtc/rtc-nct3018y.c F: include/dt-bindings/clock/nuvoton,npcm7xx-clock.h F: include/dt-bindings/clock/nuvoton,npcm845-clk.h +ARM/NUVOTON NPCM VIDEO ENGINE DRIVER +M: Joseph Liu +M: Marvin Lin +L: linux-media@vger.kernel.org +L: openbmc@lists.ozlabs.org (moderated for non-subscribers) +S: Maintained +F: Documentation/devicetree/bindings/media/nuvoton,npcm-ece.yaml +F: Documentation/devicetree/bindings/media/nuvoton,npcm-vcd.yaml +F: Documentation/userspace-api/media/drivers/npcm-video.rst +F: drivers/media/platform/nuvoton/ +F: include/uapi/linux/npcm-video.h + ARM/NUVOTON WPCM450 ARCHITECTURE M: Jonathan Neuschäfer L: openbmc@lists.ozlabs.org (moderated for non-subscribers) diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig index ee579916f874..91e54215de3a 100644 --- a/drivers/media/platform/Kconfig +++ b/drivers/media/platform/Kconfig @@ -73,6 +73,7 @@ source "drivers/media/platform/intel/Kconfig" source "drivers/media/platform/marvell/Kconfig" source "drivers/media/platform/mediatek/Kconfig" source "drivers/media/platform/microchip/Kconfig" +source "drivers/media/platform/nuvoton/Kconfig" source "drivers/media/platform/nvidia/Kconfig" source "drivers/media/platform/nxp/Kconfig" source "drivers/media/platform/qcom/Kconfig" diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile index 5453bb868e67..3296ec1ebe16 100644 --- a/drivers/media/platform/Makefile +++ b/drivers/media/platform/Makefile @@ -16,6 +16,7 @@ obj-y += intel/ obj-y += marvell/ obj-y += mediatek/ obj-y += microchip/ +obj-y += nuvoton/ obj-y += nvidia/ obj-y += nxp/ obj-y += qcom/ diff --git a/drivers/media/platform/nuvoton/Kconfig b/drivers/media/platform/nuvoton/Kconfig new file mode 100644 index 000000000000..5047d1ba3de5 --- /dev/null +++ b/drivers/media/platform/nuvoton/Kconfig @@ -0,0 +1,15 @@ +# SPDX-License-Identifier: GPL-2.0-only + +comment "Nuvoton media platform drivers" + +config VIDEO_NPCM_VCD_ECE + tristate "Nuvoton NPCM Video Capture/Encode Engine driver" + depends on V4L_PLATFORM_DRIVERS + depends on VIDEO_DEV + select VIDEOBUF2_DMA_CONTIG + help + Support for the Video Capture/Differentiation Engine (VCD) and + Encoding Compression Engine (ECE) present on Nuvoton NPCM SoCs. + The VCD can capture and differentiate video data from digital or + analog sources, then the ECE will compress the data into HEXTILE + format. diff --git a/drivers/media/platform/nuvoton/Makefile b/drivers/media/platform/nuvoton/Makefile new file mode 100644 index 000000000000..74a4e3fc8555 --- /dev/null +++ b/drivers/media/platform/nuvoton/Makefile @@ -0,0 +1,2 @@ +# SPDX-License-Identifier: GPL-2.0-only +obj-$(CONFIG_VIDEO_NPCM_VCD_ECE) += npcm-video.o diff --git a/drivers/media/platform/nuvoton/npcm-regs.h b/drivers/media/platform/nuvoton/npcm-regs.h new file mode 100644 index 000000000000..f528f5726307 --- /dev/null +++ b/drivers/media/platform/nuvoton/npcm-regs.h @@ -0,0 +1,171 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Register definition header for NPCM video driver + * + * Copyright (C) 2022 Nuvoton Technologies + */ + +#ifndef _NPCM_REGS_H +#define _NPCM_REGS_H + +/* VCD Registers */ +#define VCD_DIFF_TBL 0x0000 +#define VCD_FBA_ADR 0x8000 +#define VCD_FBB_ADR 0x8004 + +#define VCD_FB_LP 0x8008 +#define VCD_FBA_LP GENMASK(15, 0) +#define VCD_FBB_LP GENMASK(31, 16) + +#define VCD_CAP_RES 0x800c +#define VCD_CAP_RES_VERT_RES GENMASK(10, 0) +#define VCD_CAP_RES_HOR_RES GENMASK(26, 16) + +#define VCD_MODE 0x8014 +#define VCD_MODE_VCDE BIT(0) +#define VCD_MODE_CM565 BIT(1) +#define VCD_MODE_IDBC BIT(3) +#define VCD_MODE_COLOR_CNVRT GENMASK(5, 4) +#define VCD_MODE_COLOR_CNVRT_NO_CNVRT 0 +#define VCD_MODE_COLOR_CNVRT_RGB_222 1 +#define VCD_MODE_COLOR_CNVRT_666_MODE 2 +#define VCD_MODE_COLOR_CNVRT_RGB_888 3 +#define VCD_MODE_KVM_BW_SET BIT(16) + +#define VCD_CMD 0x8018 +#define VCD_CMD_GO BIT(0) +#define VCD_CMD_RST BIT(1) +#define VCD_CMD_OPERATION GENMASK(6, 4) +#define VCD_CMD_OPERATION_CAPTURE 0 +#define VCD_CMD_OPERATION_COMPARE 2 + +#define VCD_STAT 0x801c +#define VCD_STAT_DONE BIT(0) +#define VCD_STAT_IFOT BIT(2) +#define VCD_STAT_IFOR BIT(3) +#define VCD_STAT_BUSY BIT(30) +#define VCD_STAT_CLEAR 0x3fff + +#define VCD_INTE 0x8020 +#define VCD_INTE_DONE_IE BIT(0) +#define VCD_INTE_IFOT_IE BIT(2) +#define VCD_INTE_IFOR_IE BIT(3) + +#define VCD_RCHG 0x8028 +#define VCD_RCHG_TIM_PRSCL GENMASK(12, 9) + +#define VCD_FIFO 0x805c +#define VCD_FIFO_TH 0x100350ff + +#define VCD_MAX_SRC_BUFFER_SIZE 0x500000 /* 1920 x 1200 x 2 bpp */ +#define VCD_KVM_BW_PCLK 120000000UL +#define VCD_BUSY_TIMEOUT_US 300000 + +/* ECE Registers */ +#define ECE_DDA_CTRL 0x0000 +#define ECE_DDA_CTRL_ECEEN BIT(0) +#define ECE_DDA_CTRL_INTEN BIT(8) + +#define ECE_DDA_STS 0x0004 +#define ECE_DDA_STS_CDREADY BIT(8) +#define ECE_DDA_STS_ACDRDY BIT(10) + +#define ECE_FBR_BA 0x0008 +#define ECE_ED_BA 0x000c +#define ECE_RECT_XY 0x0010 + +#define ECE_RECT_DIMEN 0x0014 +#define ECE_RECT_DIMEN_WR GENMASK(10, 0) +#define ECE_RECT_DIMEN_WLTR GENMASK(14, 11) +#define ECE_RECT_DIMEN_HR GENMASK(26, 16) +#define ECE_RECT_DIMEN_HLTR GENMASK(30, 27) + +#define ECE_RESOL 0x001c +#define ECE_RESOL_FB_LP_512 0 +#define ECE_RESOL_FB_LP_1024 1 +#define ECE_RESOL_FB_LP_2048 2 +#define ECE_RESOL_FB_LP_2560 3 +#define ECE_RESOL_FB_LP_4096 4 + +#define ECE_HEX_CTRL 0x0040 +#define ECE_HEX_CTRL_ENCDIS BIT(0) +#define ECE_HEX_CTRL_ENC_GAP GENMASK(12, 8) + +#define ECE_HEX_RECT_OFFSET 0x0048 +#define ECE_HEX_RECT_OFFSET_MASK GENMASK(22, 0) + +#define ECE_TILE_W 16 +#define ECE_TILE_H 16 +#define ECE_POLL_TIMEOUT_US 300000 + +/* GCR Registers */ +#define INTCR 0x3c +#define INTCR_GFXIFDIS GENMASK(9, 8) +#define INTCR_DEHS BIT(27) + +#define INTCR2 0x60 +#define INTCR2_GIRST2 BIT(2) +#define INTCR2_GIHCRST BIT(5) +#define INTCR2_GIVCRST BIT(6) + +#define INTCR3 0x9c +#define INTCR3_GMMAP GENMASK(10, 8) +#define INTCR3_GMMAP_128MB 0 +#define INTCR3_GMMAP_256MB 1 +#define INTCR3_GMMAP_512MB 2 +#define INTCR3_GMMAP_1GB 3 +#define INTCR3_GMMAP_2GB 4 + +#define INTCR4 0xc0 +#define INTCR4_GMMAP GENMASK(22, 16) +#define INTCR4_GMMAP_512MB 0x1f +#define INTCR4_GMMAP_512MB_ECC 0x1b +#define INTCR4_GMMAP_1GB 0x3f +#define INTCR4_GMMAP_1GB_ECC 0x37 +#define INTCR4_GMMAP_2GB 0x7f +#define INTCR4_GMMAP_2GB_ECC 0x6f + +#define ADDR_GMMAP_128MB 0x07000000 +#define ADDR_GMMAP_256MB 0x0f000000 +#define ADDR_GMMAP_512MB 0x1f000000 +#define ADDR_GMMAP_512MB_ECC 0x1b000000 +#define ADDR_GMMAP_1GB 0x3f000000 +#define ADDR_GMMAP_1GB_ECC 0x37000000 +#define ADDR_GMMAP_2GB 0x7f000000 +#define ADDR_GMMAP_2GB_ECC 0x6f000000 + +#define GMMAP_LENGTH 0xc00000 /* 4MB preserved, total 16MB */ + +#define MFSEL1 0x0c +#define MFSEL1_DVH1SEL BIT(27) + +/* GFXI Register */ +#define DISPST 0x00 +#define DISPST_HSCROFF BIT(1) +#define DISPST_MGAMODE BIT(7) + +#define HVCNTL 0x10 +#define HVCNTL_MASK GENMASK(7, 0) + +#define HVCNTH 0x14 +#define HVCNTH_MASK GENMASK(2, 0) + +#define VVCNTL 0x20 +#define VVCNTL_MASK GENMASK(7, 0) + +#define VVCNTH 0x24 +#define VVCNTH_MASK GENMASK(2, 0) + +#define GPLLINDIV 0x40 +#define GPLLINDIV_MASK GENMASK(5, 0) +#define GPLLINDIV_GPLLFBDV8 BIT(7) + +#define GPLLFBDIV 0x44 +#define GPLLFBDIV_MASK GENMASK(7, 0) + +#define GPLLST 0x48 +#define GPLLST_PLLOTDIV1 GENMASK(2, 0) +#define GPLLST_PLLOTDIV2 GENMASK(5, 3) +#define GPLLST_GPLLFBDV109 GENMASK(7, 6) + +#endif /* _NPCM_REGS_H */ diff --git a/drivers/media/platform/nuvoton/npcm-video.c b/drivers/media/platform/nuvoton/npcm-video.c new file mode 100644 index 000000000000..9c3c9cb156b8 --- /dev/null +++ b/drivers/media/platform/nuvoton/npcm-video.c @@ -0,0 +1,1814 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Driver for Video Capture/Differentiation Engine (VCD) and Encoding + * Compression Engine (ECE) present on Nuvoton NPCM SoCs. + * + * Copyright (C) 2022 Nuvoton Technologies + */ + +#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 +#include +#include +#include +#include "npcm-regs.h" + +#define DEVICE_NAME "npcm-video" +#define MAX_FRAME_RATE 60 +#define MAX_WIDTH 1920 +#define MAX_HEIGHT 1200 +#define MIN_WIDTH 320 +#define MIN_HEIGHT 240 +#define MIN_LP 512 +#define MAX_LP 4096 +#define RECT_W 16 +#define RECT_H 16 +#define BITMAP_SIZE 32 + +struct npcm_video_addr { + size_t size; + dma_addr_t dma; + void *virt; +}; + +struct npcm_video_buffer { + struct vb2_v4l2_buffer vb; + struct list_head link; +}; + +#define to_npcm_video_buffer(x) \ + container_of((x), struct npcm_video_buffer, vb) + +enum { + VIDEO_STREAMING, + VIDEO_FRAME_INPRG, + VIDEO_STOPPED, +}; + +struct rect_list { + struct v4l2_clip clip; + struct list_head list; +}; + +struct rect_list_info { + struct rect_list *list; + struct rect_list *first; + struct list_head *head; + unsigned int index; + unsigned int tile_perline; + unsigned int tile_perrow; + unsigned int offset_perline; + unsigned int tile_size; + unsigned int tile_cnt; +}; + +struct npcm_ece { + struct regmap *regmap; + atomic_t clients; + struct reset_control *reset; +}; + +struct npcm_video { + struct regmap *gcr_regmap; + struct regmap *gfx_regmap; + struct regmap *vcd_regmap; + + struct device *dev; + struct v4l2_ctrl_handler ctrl_handler; + struct v4l2_device v4l2_dev; + struct v4l2_pix_format pix_fmt; + struct v4l2_bt_timings active_timings; + struct v4l2_bt_timings detected_timings; + u32 v4l2_input_status; + struct vb2_queue queue; + struct video_device vdev; + struct mutex video_lock; /* v4l2 and videobuf2 lock */ + + struct list_head buffers; + spinlock_t lock; /* buffer list lock */ + unsigned long flags; + unsigned int sequence; + + size_t max_buffer_size; + struct npcm_video_addr src; + struct reset_control *reset; + struct npcm_ece ece; + + unsigned int frame_rate; + unsigned int vb_index; + u32 bytesperline; + u8 bytesperpixel; + u32 rect_cnt; + u8 num_buffers; + struct list_head *list; + u32 *rect; + int ctrl_cmd; + int op_cmd; +}; + +#define to_npcm_video(x) container_of((x), struct npcm_video, v4l2_dev) + +static const struct v4l2_dv_timings_cap npcm_video_timings_cap = { + .type = V4L2_DV_BT_656_1120, + .bt = { + .min_width = MIN_WIDTH, + .max_width = MAX_WIDTH, + .min_height = MIN_HEIGHT, + .max_height = MAX_HEIGHT, + .min_pixelclock = 6574080, /* 640 x 480 x 24Hz */ + .max_pixelclock = 138240000, /* 1920 x 1200 x 60Hz */ + .standards = V4L2_DV_BT_STD_CEA861 | V4L2_DV_BT_STD_DMT | + V4L2_DV_BT_STD_CVT | V4L2_DV_BT_STD_GTF, + .capabilities = V4L2_DV_BT_CAP_PROGRESSIVE | + V4L2_DV_BT_CAP_REDUCED_BLANKING | + V4L2_DV_BT_CAP_CUSTOM, + }, +}; + +static DECLARE_BITMAP(bitmap, BITMAP_SIZE); + +static void npcm_video_ece_prepend_rect_header(u8 *addr, u16 x, u16 y, u16 w, u16 h) +{ + __be16 x_pos = cpu_to_be16(x); + __be16 y_pos = cpu_to_be16(y); + __be16 width = cpu_to_be16(w); + __be16 height = cpu_to_be16(h); + __be32 encoding = cpu_to_be32(5); /* Hextile encoding */ + + memcpy(addr, &x_pos, 2); + memcpy(addr + 2, &y_pos, 2); + memcpy(addr + 4, &width, 2); + memcpy(addr + 6, &height, 2); + memcpy(addr + 8, &encoding, 4); +} + +static unsigned int npcm_video_ece_get_ed_size(struct npcm_video *video, + u32 offset, u8 *addr) +{ + struct regmap *ece = video->ece.regmap; + u32 size, gap, val; + int ret; + + ret = regmap_read_poll_timeout(ece, ECE_DDA_STS, val, + (val & ECE_DDA_STS_CDREADY), 0, + ECE_POLL_TIMEOUT_US); + + if (ret) { + dev_warn(video->dev, "Wait for ECE_DDA_STS_CDREADY timeout\n"); + return 0; + } + + size = readl(addr + offset); + regmap_read(ece, ECE_HEX_CTRL, &val); + gap = FIELD_GET(ECE_HEX_CTRL_ENC_GAP, val); + + dev_dbg(video->dev, "offset = %u, ed_size = %u, gap = %u\n", offset, + size, gap); + + return size + gap; +} + +static void npcm_video_ece_enc_rect(struct npcm_video *video, u32 r_off_x, + u32 r_off_y, u32 r_w, u32 r_h) +{ + struct regmap *ece = video->ece.regmap; + u32 rect_offset = (r_off_y * video->bytesperline) + (r_off_x * 2); + u32 w_size = ECE_TILE_W, h_size = ECE_TILE_H, w_tile, h_tile, temp; + + regmap_update_bits(ece, ECE_DDA_CTRL, ECE_DDA_CTRL_ECEEN, 0); + regmap_update_bits(ece, ECE_DDA_CTRL, ECE_DDA_CTRL_ECEEN, ECE_DDA_CTRL_ECEEN); + regmap_write(ece, ECE_DDA_STS, ECE_DDA_STS_CDREADY | ECE_DDA_STS_ACDRDY); + regmap_write(ece, ECE_RECT_XY, rect_offset); + + w_tile = r_w / ECE_TILE_W; + h_tile = r_h / ECE_TILE_H; + + if (r_w % ECE_TILE_W) { + w_tile += 1; + w_size = r_w % ECE_TILE_W; + } + if (r_h % ECE_TILE_H || !h_tile) { + h_tile += 1; + h_size = r_h % ECE_TILE_H; + } + + temp = FIELD_PREP(ECE_RECT_DIMEN_WLTR, w_size - 1) | + FIELD_PREP(ECE_RECT_DIMEN_HLTR, h_size - 1) | + FIELD_PREP(ECE_RECT_DIMEN_WR, w_tile - 1) | + FIELD_PREP(ECE_RECT_DIMEN_HR, h_tile - 1); + + regmap_write(ece, ECE_RECT_DIMEN, temp); +} + +static u32 npcm_video_ece_read_rect_offset(struct npcm_video *video) +{ + struct regmap *ece = video->ece.regmap; + u32 offset; + + regmap_read(ece, ECE_HEX_RECT_OFFSET, &offset); + return FIELD_GET(ECE_HEX_RECT_OFFSET_MASK, offset); +} + +/* + * Set the line pitch (in bytes) for the frame buffers. + * Can be on of those values: 512, 1024, 2048, 2560 or 4096 bytes. + */ +static void npcm_video_ece_set_lp(struct npcm_video *video, u32 pitch) +{ + struct regmap *ece = video->ece.regmap; + u32 lp; + + switch (pitch) { + case 512: + lp = ECE_RESOL_FB_LP_512; + break; + case 1024: + lp = ECE_RESOL_FB_LP_1024; + break; + case 2048: + lp = ECE_RESOL_FB_LP_2048; + break; + case 2560: + lp = ECE_RESOL_FB_LP_2560; + break; + case 4096: + lp = ECE_RESOL_FB_LP_4096; + break; + default: + return; + } + + regmap_write(ece, ECE_RESOL, lp); +} + +static inline void npcm_video_ece_set_fb_addr(struct npcm_video *video, u32 buffer) +{ + struct regmap *ece = video->ece.regmap; + + regmap_write(ece, ECE_FBR_BA, buffer); +} + +static inline void npcm_video_ece_set_enc_dba(struct npcm_video *video, u32 addr) +{ + struct regmap *ece = video->ece.regmap; + + regmap_write(ece, ECE_ED_BA, addr); +} + +static inline void npcm_video_ece_clear_rect_offset(struct npcm_video *video) +{ + struct regmap *ece = video->ece.regmap; + + regmap_write(ece, ECE_HEX_RECT_OFFSET, 0); +} + +static void npcm_video_ece_ctrl_reset(struct npcm_video *video) +{ + struct regmap *ece = video->ece.regmap; + + regmap_update_bits(ece, ECE_DDA_CTRL, ECE_DDA_CTRL_ECEEN, 0); + regmap_update_bits(ece, ECE_HEX_CTRL, ECE_HEX_CTRL_ENCDIS, ECE_HEX_CTRL_ENCDIS); + regmap_update_bits(ece, ECE_DDA_CTRL, ECE_DDA_CTRL_ECEEN, ECE_DDA_CTRL_ECEEN); + regmap_update_bits(ece, ECE_HEX_CTRL, ECE_HEX_CTRL_ENCDIS, 0); + + npcm_video_ece_clear_rect_offset(video); +} + +static void npcm_video_ece_ip_reset(struct npcm_video *video) +{ + /* + * After resetting a module and clearing the reset bit, it should wait + * at least 10 us before accessing the module. + */ + reset_control_assert(video->ece.reset); + usleep_range(10, 20); + reset_control_deassert(video->ece.reset); + usleep_range(10, 20); +} + +static inline void npcm_video_ece_init(struct npcm_video *video) +{ + npcm_video_ece_ip_reset(video); + npcm_video_ece_ctrl_reset(video); +} + +static void npcm_video_ece_stop(struct npcm_video *video) +{ + struct regmap *ece = video->ece.regmap; + + regmap_update_bits(ece, ECE_DDA_CTRL, ECE_DDA_CTRL_ECEEN, 0); + regmap_update_bits(ece, ECE_DDA_CTRL, ECE_DDA_CTRL_INTEN, 0); + regmap_update_bits(ece, ECE_HEX_CTRL, ECE_HEX_CTRL_ENCDIS, ECE_HEX_CTRL_ENCDIS); + npcm_video_ece_clear_rect_offset(video); +} + +static bool npcm_video_alloc_buf(struct npcm_video *video, + struct npcm_video_addr *addr, size_t size) +{ + if (size > VCD_MAX_SRC_BUFFER_SIZE) + size = VCD_MAX_SRC_BUFFER_SIZE; + + addr->virt = dma_alloc_coherent(video->dev, size, &addr->dma, GFP_KERNEL); + if (!addr->virt) + return false; + + addr->size = size; + return true; +} + +static void npcm_video_free_buf(struct npcm_video *video, + struct npcm_video_addr *addr) +{ + dma_free_coherent(video->dev, addr->size, addr->virt, addr->dma); + addr->size = 0; + addr->dma = 0ULL; + addr->virt = NULL; +} + +static void npcm_video_free_diff_table(struct npcm_video *video) +{ + struct list_head *head, *pos, *nx; + struct rect_list *tmp; + unsigned int i; + + for (i = 0; i < video->num_buffers; i++) { + head = &video->list[i]; + list_for_each_safe(pos, nx, head) { + tmp = list_entry(pos, struct rect_list, list); + list_del(&tmp->list); + kfree(tmp); + } + } +} + +static int npcm_video_add_rect(struct npcm_video *video, unsigned int index, + u32 x, u32 y, u32 w, u32 h) +{ + struct list_head *head = &video->list[index]; + struct rect_list *list = NULL; + struct v4l2_rect *r; + + list = kzalloc(sizeof(*list), GFP_KERNEL); + if (!list) + return 0; + + r = &list->clip.c; + r->left = x; + r->top = y; + r->width = w; + r->height = h; + + list_add_tail(&list->list, head); + return 1; +} + +static void npcm_video_merge_rect(struct npcm_video *video, + struct rect_list_info *info) +{ + struct list_head *head = info->head; + struct rect_list *list = info->list, *first = info->first; + struct v4l2_rect *r = &list->clip.c, *f = &first->clip.c; + + if (!first) { + first = list; + info->first = first; + list_add_tail(&list->list, head); + video->rect_cnt++; + } else { + if ((r->left == (f->left + f->width)) && r->top == f->top) { + f->width += r->width; + kfree(list); + } else if ((r->top == (f->top + f->height)) && + (r->left == f->left)) { + f->height += r->height; + kfree(list); + } else if (((r->top > f->top) && + (r->top < (f->top + f->height))) && + ((r->left > f->left) && + (r->left < (f->left + f->width)))) { + kfree(list); + } else { + list_add_tail(&list->list, head); + video->rect_cnt++; + info->first = list; + } + } +} + +static struct rect_list *npcm_video_new_rect(struct npcm_video *video, + unsigned int offset, + unsigned int index) +{ + struct v4l2_bt_timings *act = &video->active_timings; + struct rect_list *list = NULL; + struct v4l2_rect *r; + + list = kzalloc(sizeof(*list), GFP_KERNEL); + if (!list) + return NULL; + + r = &list->clip.c; + + r->left = (offset << 4); + r->top = (index >> 2); + r->width = RECT_W; + r->height = RECT_H; + if ((r->left + RECT_W) > act->width) + r->width = act->width - r->left; + if ((r->top + RECT_H) > act->height) + r->height = act->height - r->top; + + return list; +} + +static int npcm_video_find_rect(struct npcm_video *video, + struct rect_list_info *info, unsigned int offset) +{ + if (offset < info->tile_perline) { + info->list = npcm_video_new_rect(video, offset, info->index); + if (!info->list) { + dev_err(video->dev, "Failed to allocate rect_list\n"); + return -ENOMEM; + } + + npcm_video_merge_rect(video, info); + } + return 0; +} + +static int npcm_video_build_table(struct npcm_video *video, + struct rect_list_info *info) +{ + struct regmap *vcd = video->vcd_regmap; + unsigned int j, bit; + u32 value; + int ret; + + for (j = 0; j < info->offset_perline; j += 4) { + regmap_read(vcd, VCD_DIFF_TBL + (j + info->index), &value); + + bitmap_from_arr32(bitmap, &value, BITMAP_SIZE); + + for_each_set_bit(bit, bitmap, BITMAP_SIZE) { + ret = npcm_video_find_rect(video, info, bit + (j << 3)); + if (ret) + return ret; + } + } + info->index += 64; + return info->tile_perline; +} + +static void npcm_video_get_rect_list(struct npcm_video *video, unsigned int index) +{ + struct v4l2_bt_timings *act = &video->active_timings; + struct rect_list_info info; + unsigned int tile_cnt = 0, mod; + int ret = 0; + + memset(&info, 0, sizeof(struct rect_list_info)); + info.head = &video->list[index]; + + info.tile_perline = act->width >> 4; + mod = act->width % RECT_W; + if (mod != 0) + info.tile_perline += 1; + + info.tile_perrow = act->height >> 4; + mod = act->height % RECT_H; + if (mod != 0) + info.tile_perrow += 1; + + info.tile_size = info.tile_perrow * info.tile_perline; + + info.offset_perline = info.tile_perline >> 5; + mod = info.tile_perline % 32; + if (mod != 0) + info.offset_perline += 1; + + info.offset_perline *= 4; + + do { + ret = npcm_video_build_table(video, &info); + if (ret < 0) + return; + + tile_cnt += ret; + } while (tile_cnt < info.tile_size); +} + +static u8 npcm_video_is_mga(struct npcm_video *video) +{ + struct regmap *gfxi = video->gfx_regmap; + u32 dispst; + + regmap_read(gfxi, DISPST, &dispst); + return ((dispst & DISPST_MGAMODE) == DISPST_MGAMODE); +} + +static u32 npcm_video_hres(struct npcm_video *video) +{ + struct regmap *gfxi = video->gfx_regmap; + u32 hvcnth, hvcntl, apb_hor_res; + + regmap_read(gfxi, HVCNTH, &hvcnth); + regmap_read(gfxi, HVCNTL, &hvcntl); + apb_hor_res = (((hvcnth & HVCNTH_MASK) << 8) + (hvcntl & HVCNTL_MASK) + 1); + + return apb_hor_res; +} + +static u32 npcm_video_vres(struct npcm_video *video) +{ + struct regmap *gfxi = video->gfx_regmap; + u32 vvcnth, vvcntl, apb_ver_res; + + regmap_read(gfxi, VVCNTH, &vvcnth); + regmap_read(gfxi, VVCNTL, &vvcntl); + + apb_ver_res = (((vvcnth & VVCNTH_MASK) << 8) + (vvcntl & VVCNTL_MASK)); + + return apb_ver_res; +} + +static int npcm_video_capres(struct npcm_video *video, u32 hor_res, u32 vert_res) +{ + struct regmap *vcd = video->vcd_regmap; + u32 res, cap_res; + + if (hor_res > MAX_WIDTH || vert_res > MAX_HEIGHT) + return -EINVAL; + + res = FIELD_PREP(VCD_CAP_RES_VERT_RES, vert_res) | + FIELD_PREP(VCD_CAP_RES_HOR_RES, hor_res); + + regmap_write(vcd, VCD_CAP_RES, res); + regmap_read(vcd, VCD_CAP_RES, &cap_res); + + if (cap_res != res) + return -EINVAL; + + return 0; +} + +static void npcm_video_vcd_ip_reset(struct npcm_video *video) +{ + /* + * After resetting a module and clearing the reset bit, it should wait + * at least 10 us before accessing the module. + */ + reset_control_assert(video->reset); + usleep_range(10, 20); + reset_control_deassert(video->reset); + usleep_range(10, 20); +} + +static void npcm_video_vcd_state_machine_reset(struct npcm_video *video) +{ + struct regmap *vcd = video->vcd_regmap; + u32 stat; + int ret; + + regmap_update_bits(vcd, VCD_MODE, VCD_MODE_VCDE, 0); + regmap_update_bits(vcd, VCD_MODE, VCD_MODE_IDBC, 0); + regmap_update_bits(vcd, VCD_CMD, VCD_CMD_RST, VCD_CMD_RST); + + ret = regmap_read_poll_timeout(vcd, VCD_STAT, stat, (stat & VCD_STAT_DONE), + 0, ECE_POLL_TIMEOUT_US); + if (ret) { + dev_warn(video->dev, "Wait for VCD_STAT_DONE timeout\n"); + return; + } + + regmap_write(vcd, VCD_STAT, VCD_STAT_CLEAR); + regmap_update_bits(vcd, VCD_MODE, VCD_MODE_VCDE, VCD_MODE_VCDE); + regmap_update_bits(vcd, VCD_MODE, VCD_MODE_IDBC, VCD_MODE_IDBC); +} + +static void npcm_video_gfx_reset(struct npcm_video *video) +{ + struct regmap *gcr = video->gcr_regmap; + + regmap_update_bits(gcr, INTCR2, INTCR2_GIRST2, INTCR2_GIRST2); + npcm_video_vcd_state_machine_reset(video); + regmap_update_bits(gcr, INTCR2, INTCR2_GIRST2, 0); +} + +static void npcm_video_kvm_bw(struct npcm_video *video, u8 bandwidth) +{ + struct regmap *vcd = video->vcd_regmap; + + if (!npcm_video_is_mga(video)) + bandwidth = 1; + + if (bandwidth) + regmap_update_bits(vcd, VCD_MODE, VCD_MODE_KVM_BW_SET, + VCD_MODE_KVM_BW_SET); + else + regmap_update_bits(vcd, VCD_MODE, VCD_MODE_KVM_BW_SET, 0); +} + +static u32 npcm_video_pclk(struct npcm_video *video) +{ + struct regmap *gfxi = video->gfx_regmap; + u32 tmp, pllfbdiv, pllinotdiv, gpllfbdiv; + u8 gpllfbdv109, gpllfbdv8, gpllindiv, gpllst_pllotdiv1, gpllst_pllotdiv2; + + regmap_read(gfxi, GPLLST, &tmp); + gpllfbdv109 = FIELD_GET(GPLLST_GPLLFBDV109, tmp); + gpllst_pllotdiv1 = FIELD_GET(GPLLST_PLLOTDIV1, tmp); + gpllst_pllotdiv2 = FIELD_GET(GPLLST_PLLOTDIV2, tmp); + + regmap_read(gfxi, GPLLINDIV, &tmp); + gpllfbdv8 = FIELD_GET(GPLLINDIV_GPLLFBDV8, tmp); + gpllindiv = FIELD_GET(GPLLINDIV_MASK, tmp); + + regmap_read(gfxi, GPLLFBDIV, &tmp); + gpllfbdiv = FIELD_GET(GPLLFBDIV_MASK, tmp); + + pllfbdiv = (512 * gpllfbdv109 + 256 * gpllfbdv8 + gpllfbdiv); + pllinotdiv = (gpllindiv * gpllst_pllotdiv1 * gpllst_pllotdiv2); + if (pllfbdiv == 0 || pllinotdiv == 0) + return 0; + + return ((pllfbdiv * 25000) / pllinotdiv) * 1000; +} + +static int npcm_video_get_bpp(struct npcm_video *video) +{ + struct regmap *vcd = video->vcd_regmap; + u32 mode, color_cnvr; + + regmap_read(vcd, VCD_MODE, &mode); + color_cnvr = FIELD_GET(VCD_MODE_COLOR_CNVRT, mode); + + switch (color_cnvr) { + case VCD_MODE_COLOR_CNVRT_NO_CNVRT: + return 2; + case VCD_MODE_COLOR_CNVRT_RGB_222: + case VCD_MODE_COLOR_CNVRT_666_MODE: + return 1; + case VCD_MODE_COLOR_CNVRT_RGB_888: + return 4; + } + return 0; +} + +/* + * Pitch must be a power of 2, >= linebytes, + * at least 512, and no more than 4096. + */ +static void npcm_video_set_linepitch(struct npcm_video *video, u32 linebytes) +{ + struct regmap *vcd = video->vcd_regmap; + u32 pitch = MIN_LP; + + while ((pitch < linebytes) && (pitch < MAX_LP)) + pitch *= 2; + + regmap_write(vcd, VCD_FB_LP, FIELD_PREP(VCD_FBA_LP, pitch) | + FIELD_PREP(VCD_FBB_LP, pitch)); +} + +static u32 npcm_video_get_linepitch(struct npcm_video *video) +{ + struct regmap *vcd = video->vcd_regmap; + u32 linepitch; + + regmap_read(vcd, VCD_FB_LP, &linepitch); + return FIELD_GET(VCD_FBA_LP, linepitch); +} + +static void npcm_video_command(struct npcm_video *video, u32 value) +{ + struct regmap *vcd = video->vcd_regmap; + u32 cmd; + + regmap_write(vcd, VCD_STAT, VCD_STAT_CLEAR); + regmap_read(vcd, VCD_CMD, &cmd); + cmd |= FIELD_PREP(VCD_CMD_OPERATION, value); + + regmap_write(vcd, VCD_CMD, cmd); + regmap_update_bits(vcd, VCD_CMD, VCD_CMD_GO, VCD_CMD_GO); + video->op_cmd = value; +} + +static void npcm_video_init_reg(struct npcm_video *video) +{ + struct regmap *gcr = video->gcr_regmap, *vcd = video->vcd_regmap; + + /* Selects Data Enable */ + regmap_update_bits(gcr, INTCR, INTCR_DEHS, 0); + + /* Enable display of KVM GFX and access to memory */ + regmap_update_bits(gcr, INTCR, INTCR_GFXIFDIS, 0); + + /* Active Vertical/Horizontal Counters Reset */ + regmap_update_bits(gcr, INTCR2, INTCR2_GIHCRST | INTCR2_GIVCRST, + INTCR2_GIHCRST | INTCR2_GIVCRST); + + /* Select KVM GFX input */ + regmap_update_bits(gcr, MFSEL1, MFSEL1_DVH1SEL, 0); + + /* Reset video modules */ + npcm_video_vcd_ip_reset(video); + npcm_video_gfx_reset(video); + + /* Set the FIFO thresholds */ + regmap_write(vcd, VCD_FIFO, VCD_FIFO_TH); + + /* Set video mode */ + regmap_update_bits(vcd, VCD_MODE, 0xffffffff, + VCD_MODE_VCDE | VCD_MODE_CM565 | + VCD_MODE_IDBC | VCD_MODE_KVM_BW_SET); + regmap_write(vcd, VCD_RCHG, FIELD_PREP(VCD_RCHG_TIM_PRSCL, 0xf)); +} + +static int npcm_video_start_frame(struct npcm_video *video) +{ + struct npcm_video_buffer *buf; + struct regmap *vcd = video->vcd_regmap; + unsigned long flags; + u32 val; + int ret; + + if (video->v4l2_input_status) { + dev_dbg(video->dev, "No video signal; skip capture frame\n"); + return 0; + } + + ret = regmap_read_poll_timeout(vcd, VCD_STAT, val, !(val & VCD_STAT_BUSY), + 1000, VCD_BUSY_TIMEOUT_US); + if (ret) { + dev_err(video->dev, "Wait for VCD_STAT_BUSY timeout\n"); + return -EBUSY; + } + + spin_lock_irqsave(&video->lock, flags); + buf = list_first_entry_or_null(&video->buffers, + struct npcm_video_buffer, link); + if (!buf) { + spin_unlock_irqrestore(&video->lock, flags); + dev_dbg(video->dev, "No empty buffers; skip capture frame\n"); + return 0; + } + + set_bit(VIDEO_FRAME_INPRG, &video->flags); + spin_unlock_irqrestore(&video->lock, flags); + + npcm_video_vcd_state_machine_reset(video); + regmap_update_bits(vcd, VCD_INTE, VCD_INTE_DONE_IE | VCD_INTE_IFOT_IE | + VCD_INTE_IFOR_IE, VCD_INTE_DONE_IE | + VCD_INTE_IFOT_IE | VCD_INTE_IFOR_IE); + npcm_video_command(video, video->ctrl_cmd); + + return 0; +} + +static void npcm_video_bufs_done(struct npcm_video *video, + enum vb2_buffer_state state) +{ + struct npcm_video_buffer *buf; + unsigned long flags; + + spin_lock_irqsave(&video->lock, flags); + list_for_each_entry(buf, &video->buffers, link) + vb2_buffer_done(&buf->vb.vb2_buf, state); + + INIT_LIST_HEAD(&video->buffers); + spin_unlock_irqrestore(&video->lock, flags); +} + +static void npcm_video_get_diff_rect(struct npcm_video *video, unsigned int index) +{ + u32 width = video->active_timings.width; + u32 height = video->active_timings.height; + + if (video->op_cmd != VCD_CMD_OPERATION_CAPTURE) { + video->rect_cnt = 0; + npcm_video_get_rect_list(video, index); + video->rect[index] = video->rect_cnt; + } else { + video->rect[index] = npcm_video_add_rect(video, index, 0, 0, + width, height); + } +} + +static void npcm_video_clear_gmmap(struct npcm_video *video) +{ + struct regmap *gcr = video->gcr_regmap; + u32 intcr, gmmap; + void __iomem *baseptr = NULL; + + if (of_device_is_compatible(video->dev->of_node, "nuvoton,npcm750-vcd")) { + regmap_read(gcr, INTCR3, &intcr); + gmmap = FIELD_GET(INTCR3_GMMAP, intcr); + + switch (gmmap) { + case INTCR3_GMMAP_128MB: + baseptr = ioremap_wc(ADDR_GMMAP_128MB, GMMAP_LENGTH); + break; + case INTCR3_GMMAP_256MB: + baseptr = ioremap_wc(ADDR_GMMAP_256MB, GMMAP_LENGTH); + break; + case INTCR3_GMMAP_512MB: + baseptr = ioremap_wc(ADDR_GMMAP_512MB, GMMAP_LENGTH); + break; + case INTCR3_GMMAP_1GB: + baseptr = ioremap_wc(ADDR_GMMAP_1GB, GMMAP_LENGTH); + break; + case INTCR3_GMMAP_2GB: + baseptr = ioremap_wc(ADDR_GMMAP_2GB, GMMAP_LENGTH); + break; + } + } else if (of_device_is_compatible(video->dev->of_node, "nuvoton,npcm845-vcd")) { + regmap_read(gcr, INTCR4, &intcr); + gmmap = FIELD_GET(INTCR4_GMMAP, intcr); + + switch (gmmap) { + case INTCR4_GMMAP_512MB: + baseptr = ioremap_wc(ADDR_GMMAP_512MB, GMMAP_LENGTH); + break; + case INTCR4_GMMAP_512MB_ECC: + baseptr = ioremap_wc(ADDR_GMMAP_512MB_ECC, GMMAP_LENGTH); + break; + case INTCR4_GMMAP_1GB: + baseptr = ioremap_wc(ADDR_GMMAP_1GB, GMMAP_LENGTH); + break; + case INTCR4_GMMAP_1GB_ECC: + baseptr = ioremap_wc(ADDR_GMMAP_1GB_ECC, GMMAP_LENGTH); + break; + case INTCR4_GMMAP_2GB: + baseptr = ioremap_wc(ADDR_GMMAP_2GB, GMMAP_LENGTH); + break; + case INTCR4_GMMAP_2GB_ECC: + baseptr = ioremap_wc(ADDR_GMMAP_2GB_ECC, GMMAP_LENGTH); + break; + } + } + + if (baseptr) { + memset(baseptr, 0, GMMAP_LENGTH); + iounmap(baseptr); + } +} + +static void npcm_video_get_resolution(struct npcm_video *video) +{ + struct v4l2_bt_timings *act = &video->active_timings; + struct v4l2_bt_timings *det = &video->detected_timings; + struct regmap *gfxi; + u32 dispst; + + video->v4l2_input_status = 0; + det->width = npcm_video_hres(video); + det->height = npcm_video_vres(video); + + if (act->width != det->width || act->height != det->height) { + dev_dbg(video->dev, "Resolution changed\n"); + npcm_video_bufs_done(video, VB2_BUF_STATE_ERROR); + + if (npcm_video_hres(video) > 0 && npcm_video_vres(video) > 0) { + gfxi = video->gfx_regmap; + + if (test_bit(VIDEO_STREAMING, &video->flags)) { + /* + * Wait for resolution is available, + * and it is also captured by host. + */ + do { + mdelay(100); + regmap_read(gfxi, DISPST, &dispst); + } while (npcm_video_vres(video) < 100 || + npcm_video_pclk(video) == 0 || + (dispst & DISPST_HSCROFF)); + } + + det->width = npcm_video_hres(video); + det->height = npcm_video_vres(video); + det->pixelclock = npcm_video_pclk(video); + } + } + + if (det->width == 0 || det->height == 0) { + det->width = MIN_WIDTH; + det->height = MIN_HEIGHT; + npcm_video_clear_gmmap(video); + video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; + } + + dev_dbg(video->dev, "Got resolution[%dx%d] -> [%dx%d], status %d\n", + act->width, act->height, det->width, det->height, + video->v4l2_input_status); +} + +static int npcm_video_set_resolution(struct npcm_video *video) +{ + struct v4l2_bt_timings *act = &video->active_timings; + struct regmap *vcd = video->vcd_regmap; + u32 mode; + + /* Set video frame physical address */ + regmap_write(vcd, VCD_FBA_ADR, video->src.dma); + regmap_write(vcd, VCD_FBB_ADR, video->src.dma); + + if (npcm_video_capres(video, act->width, act->height)) { + dev_err(video->dev, "Failed to set VCD_CAP_RES\n"); + return -EINVAL; + } + + video->bytesperpixel = npcm_video_get_bpp(video); + npcm_video_set_linepitch(video, act->width * video->bytesperpixel); + video->bytesperline = npcm_video_get_linepitch(video); + + npcm_video_kvm_bw(video, act->pixelclock > VCD_KVM_BW_PCLK); + npcm_video_gfx_reset(video); + regmap_read(vcd, VCD_MODE, &mode); + clear_bit(VIDEO_FRAME_INPRG, &video->flags); + + dev_dbg(video->dev, "VCD mode = 0x%x, %s mode\n", mode, + npcm_video_is_mga(video) ? "Hi Res" : "VGA"); + + dev_dbg(video->dev, + "Digital mode: %d x %d x %d, pixelclock %lld, bytesperline %d\n", + act->width, act->height, video->bytesperpixel, act->pixelclock, + video->bytesperline); + + return 0; +} + +static void npcm_video_start(struct npcm_video *video) +{ + npcm_video_init_reg(video); + npcm_video_get_resolution(video); + video->active_timings = video->detected_timings; + video->max_buffer_size = VCD_MAX_SRC_BUFFER_SIZE; + + if (!npcm_video_alloc_buf(video, &video->src, video->max_buffer_size)) { + dev_err(video->dev, "Failed to allocate VCD buffer\n"); + return; + } + + if (npcm_video_set_resolution(video)) { + dev_err(video->dev, "Failed to set resolution\n"); + return; + } + + video->pix_fmt.width = video->active_timings.width; + video->pix_fmt.height = video->active_timings.height; + video->pix_fmt.sizeimage = video->max_buffer_size; + video->pix_fmt.bytesperline = video->bytesperline; + + if (atomic_inc_return(&video->ece.clients) == 1) { + npcm_video_ece_init(video); + npcm_video_ece_set_fb_addr(video, video->src.dma); + npcm_video_ece_set_lp(video, video->bytesperline); + + dev_dbg(video->dev, "ECE open: client %d\n", + atomic_read(&video->ece.clients)); + } +} + +static void npcm_video_stop(struct npcm_video *video) +{ + struct regmap *vcd = video->vcd_regmap; + unsigned long flags; + + spin_lock_irqsave(&video->lock, flags); + set_bit(VIDEO_STOPPED, &video->flags); + spin_unlock_irqrestore(&video->lock, flags); + + regmap_write(vcd, VCD_INTE, 0); + regmap_write(vcd, VCD_MODE, 0); + regmap_write(vcd, VCD_RCHG, 0); + regmap_write(vcd, VCD_STAT, VCD_STAT_CLEAR); + + if (video->src.size) + npcm_video_free_buf(video, &video->src); + + if (video->list) + npcm_video_free_diff_table(video); + + kfree(video->list); + video->list = NULL; + kfree(video->rect); + video->rect = NULL; + + video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; + video->flags = 0; + video->ctrl_cmd = VCD_CMD_OPERATION_CAPTURE; + + if (atomic_dec_return(&video->ece.clients) == 0) { + npcm_video_ece_stop(video); + dev_dbg(video->dev, "ECE close: client %d\n", + atomic_read(&video->ece.clients)); + } +} + +static irqreturn_t npcm_video_irq(int irq, void *arg) +{ + struct npcm_video *video = arg; + struct regmap *vcd = video->vcd_regmap; + struct npcm_video_buffer *buf; + struct rect_list *rect_list; + struct v4l2_rect *rect; + unsigned int index, ed_size, total_size; + dma_addr_t vb_dma_addr; + u32 status, ed_offset; + void *addr; + + regmap_read(vcd, VCD_STAT, &status); + dev_dbg(video->dev, "VCD irq status 0x%x\n", status); + + regmap_write(vcd, VCD_INTE, 0); + regmap_write(vcd, VCD_STAT, VCD_STAT_CLEAR); + + if (test_bit(VIDEO_STOPPED, &video->flags) || + !test_bit(VIDEO_STREAMING, &video->flags)) { + clear_bit(VIDEO_FRAME_INPRG, &video->flags); + return IRQ_NONE; + } + + if (status & VCD_STAT_DONE) { + spin_lock(&video->lock); + buf = list_first_entry_or_null(&video->buffers, + struct npcm_video_buffer, link); + if (!buf) { + spin_unlock(&video->lock); + clear_bit(VIDEO_FRAME_INPRG, &video->flags); + return IRQ_NONE; + } + + addr = vb2_plane_vaddr(&buf->vb.vb2_buf, 0); + vb_dma_addr = vb2_dma_contig_plane_dma_addr(&buf->vb.vb2_buf, 0); + index = buf->vb.vb2_buf.index; + + npcm_video_ece_ctrl_reset(video); + npcm_video_ece_clear_rect_offset(video); + npcm_video_ece_set_fb_addr(video, video->src.dma); + + /* Set base address of encoded data to video buffer */ + npcm_video_ece_set_enc_dba(video, vb_dma_addr); + + npcm_video_ece_set_lp(video, video->bytesperline); + npcm_video_get_diff_rect(video, index); + + total_size = 0; + list_for_each_entry(rect_list, &video->list[index], list) { + rect = &rect_list->clip.c; + ed_offset = npcm_video_ece_read_rect_offset(video); + npcm_video_ece_enc_rect(video, rect->left, rect->top, + rect->width, rect->height); + + ed_size = npcm_video_ece_get_ed_size(video, ed_offset, addr); + npcm_video_ece_prepend_rect_header(addr + ed_offset, + rect->left, rect->top, + rect->width, rect->height); + total_size += ed_size; + } + + vb2_set_plane_payload(&buf->vb.vb2_buf, 0, total_size); + buf->vb.vb2_buf.timestamp = ktime_get_ns(); + buf->vb.sequence = video->sequence++; + buf->vb.field = V4L2_FIELD_NONE; + + vb2_buffer_done(&buf->vb.vb2_buf, VB2_BUF_STATE_DONE); + list_del(&buf->link); + spin_unlock(&video->lock); + clear_bit(VIDEO_FRAME_INPRG, &video->flags); + } + + if (status & VCD_STAT_IFOR || status & VCD_STAT_IFOT) { + dev_warn(video->dev, "VCD FIFO overrun or over thresholds\n"); + npcm_video_stop(video); + npcm_video_start(video); + if (npcm_video_start_frame(video)) + dev_warn(video->dev, "Failed to recover from FIFO overrun\n"); + } + + return IRQ_HANDLED; +} + +static int npcm_video_querycap(struct file *file, void *fh, + struct v4l2_capability *cap) +{ + strscpy(cap->driver, DEVICE_NAME, sizeof(cap->driver)); + strscpy(cap->card, "NPCM Video Engine", sizeof(cap->card)); + snprintf(cap->bus_info, sizeof(cap->bus_info), "platform:%s", DEVICE_NAME); + + return 0; +} + +static int npcm_video_enum_format(struct file *file, void *fh, + struct v4l2_fmtdesc *f) +{ + if (f->index) + return -EINVAL; + + f->pixelformat = V4L2_PIX_FMT_HEXTILE; + return 0; +} + +static int npcm_video_get_format(struct file *file, void *fh, + struct v4l2_format *f) +{ + struct npcm_video *video = video_drvdata(file); + + f->fmt.pix = video->pix_fmt; + return 0; +} + +static int npcm_video_enum_input(struct file *file, void *fh, + struct v4l2_input *inp) +{ + struct npcm_video *video = video_drvdata(file); + + if (inp->index) + return -EINVAL; + + strscpy(inp->name, "Host VGA capture", sizeof(inp->name)); + inp->type = V4L2_INPUT_TYPE_CAMERA; + inp->capabilities = V4L2_IN_CAP_DV_TIMINGS; + inp->status = video->v4l2_input_status; + + return 0; +} + +static int npcm_video_get_input(struct file *file, void *fh, unsigned int *i) +{ + *i = 0; + + return 0; +} + +static int npcm_video_set_input(struct file *file, void *fh, unsigned int i) +{ + if (i) + return -EINVAL; + + return 0; +} + +static int npcm_video_get_parm(struct file *file, void *fh, + struct v4l2_streamparm *a) +{ + struct npcm_video *video = video_drvdata(file); + + a->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; + a->parm.capture.readbuffers = 3; + a->parm.capture.timeperframe.numerator = 1; + if (!video->frame_rate) + a->parm.capture.timeperframe.denominator = MAX_FRAME_RATE; + else + a->parm.capture.timeperframe.denominator = video->frame_rate; + + return 0; +} + +static int npcm_video_set_parm(struct file *file, void *fh, + struct v4l2_streamparm *a) +{ + unsigned int frame_rate = 0; + + a->parm.capture.capability = V4L2_CAP_TIMEPERFRAME; + a->parm.capture.readbuffers = 3; + + if (a->parm.capture.timeperframe.numerator) + frame_rate = a->parm.capture.timeperframe.denominator / + a->parm.capture.timeperframe.numerator; + + if (!frame_rate || frame_rate > MAX_FRAME_RATE) { + frame_rate = 0; + a->parm.capture.timeperframe.denominator = MAX_FRAME_RATE; + a->parm.capture.timeperframe.numerator = 1; + } + + return 0; +} + +static int npcm_video_set_dv_timings(struct file *file, void *fh, + struct v4l2_dv_timings *timings) +{ + struct npcm_video *video = video_drvdata(file); + int rc; + + if (timings->bt.width == video->active_timings.width && + timings->bt.height == video->active_timings.height) + return 0; + + if (vb2_is_busy(&video->queue)) { + dev_err(video->dev, "%s device busy\n", __func__); + return -EBUSY; + } + + video->active_timings = timings->bt; + rc = npcm_video_set_resolution(video); + if (rc) + return rc; + + video->pix_fmt.width = timings->bt.width; + video->pix_fmt.height = timings->bt.height; + video->pix_fmt.sizeimage = video->max_buffer_size; + video->pix_fmt.bytesperline = video->bytesperline; + timings->type = V4L2_DV_BT_656_1120; + + return 0; +} + +static int npcm_video_get_dv_timings(struct file *file, void *fh, + struct v4l2_dv_timings *timings) +{ + struct npcm_video *video = video_drvdata(file); + + timings->type = V4L2_DV_BT_656_1120; + timings->bt = video->active_timings; + + return 0; +} + +static int npcm_video_query_dv_timings(struct file *file, void *fh, + struct v4l2_dv_timings *timings) +{ + struct npcm_video *video = video_drvdata(file); + + npcm_video_get_resolution(video); + timings->type = V4L2_DV_BT_656_1120; + timings->bt = video->detected_timings; + + return video->v4l2_input_status ? -ENOLINK : 0; +} + +static int npcm_video_enum_dv_timings(struct file *file, void *fh, + struct v4l2_enum_dv_timings *timings) +{ + return v4l2_enum_dv_timings_cap(timings, &npcm_video_timings_cap, + NULL, NULL); +} + +static int npcm_video_dv_timings_cap(struct file *file, void *fh, + struct v4l2_dv_timings_cap *cap) +{ + *cap = npcm_video_timings_cap; + + return 0; +} + +static int npcm_video_sub_event(struct v4l2_fh *fh, + const struct v4l2_event_subscription *sub) +{ + switch (sub->type) { + case V4L2_EVENT_SOURCE_CHANGE: + return v4l2_src_change_event_subscribe(fh, sub); + } + + return v4l2_ctrl_subscribe_event(fh, sub); +} + +static const struct v4l2_ioctl_ops npcm_video_ioctls = { + .vidioc_querycap = npcm_video_querycap, + + .vidioc_enum_fmt_vid_cap = npcm_video_enum_format, + .vidioc_g_fmt_vid_cap = npcm_video_get_format, + .vidioc_s_fmt_vid_cap = npcm_video_get_format, + .vidioc_try_fmt_vid_cap = npcm_video_get_format, + + .vidioc_reqbufs = vb2_ioctl_reqbufs, + .vidioc_querybuf = vb2_ioctl_querybuf, + .vidioc_qbuf = vb2_ioctl_qbuf, + .vidioc_expbuf = vb2_ioctl_expbuf, + .vidioc_dqbuf = vb2_ioctl_dqbuf, + .vidioc_create_bufs = vb2_ioctl_create_bufs, + .vidioc_prepare_buf = vb2_ioctl_prepare_buf, + .vidioc_streamon = vb2_ioctl_streamon, + .vidioc_streamoff = vb2_ioctl_streamoff, + + .vidioc_enum_input = npcm_video_enum_input, + .vidioc_g_input = npcm_video_get_input, + .vidioc_s_input = npcm_video_set_input, + + .vidioc_g_parm = npcm_video_get_parm, + .vidioc_s_parm = npcm_video_set_parm, + + .vidioc_s_dv_timings = npcm_video_set_dv_timings, + .vidioc_g_dv_timings = npcm_video_get_dv_timings, + .vidioc_query_dv_timings = npcm_video_query_dv_timings, + .vidioc_enum_dv_timings = npcm_video_enum_dv_timings, + .vidioc_dv_timings_cap = npcm_video_dv_timings_cap, + + .vidioc_subscribe_event = npcm_video_sub_event, + .vidioc_unsubscribe_event = v4l2_event_unsubscribe, +}; + +static int npcm_video_set_ctrl(struct v4l2_ctrl *ctrl) +{ + struct npcm_video *video = container_of(ctrl->handler, struct npcm_video, + ctrl_handler); + + switch (ctrl->id) { + case V4L2_CID_NPCM_CAPTURE_MODE: + if (ctrl->val == V4L2_NPCM_CAPTURE_MODE_COMPLETE) + video->ctrl_cmd = VCD_CMD_OPERATION_CAPTURE; + else if (ctrl->val == V4L2_NPCM_CAPTURE_MODE_DIFF) + video->ctrl_cmd = VCD_CMD_OPERATION_COMPARE; + break; + default: + return -EINVAL; + } + + return 0; +} + +static int npcm_video_get_volatile_ctrl(struct v4l2_ctrl *ctrl) +{ + struct npcm_video *video = container_of(ctrl->handler, struct npcm_video, + ctrl_handler); + + switch (ctrl->id) { + case V4L2_CID_NPCM_RECT_COUNT: + ctrl->val = video->rect[video->vb_index]; + break; + default: + return -EINVAL; + } + + return 0; +} + +static const struct v4l2_ctrl_ops npcm_video_ctrl_ops = { + .s_ctrl = npcm_video_set_ctrl, + .g_volatile_ctrl = npcm_video_get_volatile_ctrl, +}; + +static const struct v4l2_ctrl_config npcm_ctrl_capture_mode = { + .ops = &npcm_video_ctrl_ops, + .id = V4L2_CID_NPCM_CAPTURE_MODE, + .name = "NPCM Video Capture Mode", + .type = V4L2_CTRL_TYPE_INTEGER, + .min = 0, + .max = V4L2_NPCM_CAPTURE_MODE_DIFF, + .step = 1, + .def = 0, +}; + +static const struct v4l2_ctrl_config npcm_ctrl_rect_count = { + .ops = &npcm_video_ctrl_ops, + .id = V4L2_CID_NPCM_RECT_COUNT, + .name = "NPCM Compressed Hextile Rectangle Count", + .type = V4L2_CTRL_TYPE_INTEGER, + .flags = V4L2_CTRL_FLAG_VOLATILE, + .min = 0, + .max = (MAX_WIDTH / RECT_W) * (MAX_HEIGHT / RECT_H), + .step = 1, + .def = 0, +}; + +static int npcm_video_open(struct file *file) +{ + struct npcm_video *video = video_drvdata(file); + int rc; + + mutex_lock(&video->video_lock); + rc = v4l2_fh_open(file); + if (rc) { + mutex_unlock(&video->video_lock); + return rc; + } + + if (v4l2_fh_is_singular_file(file)) + npcm_video_start(video); + + mutex_unlock(&video->video_lock); + return 0; +} + +static int npcm_video_release(struct file *file) +{ + struct npcm_video *video = video_drvdata(file); + int rc; + + mutex_lock(&video->video_lock); + if (v4l2_fh_is_singular_file(file)) + npcm_video_stop(video); + + rc = _vb2_fop_release(file, NULL); + + mutex_unlock(&video->video_lock); + return rc; +} + +static const struct v4l2_file_operations npcm_video_v4l2_fops = { + .owner = THIS_MODULE, + .read = vb2_fop_read, + .poll = vb2_fop_poll, + .unlocked_ioctl = video_ioctl2, + .mmap = vb2_fop_mmap, + .open = npcm_video_open, + .release = npcm_video_release, +}; + +static int npcm_video_queue_setup(struct vb2_queue *q, unsigned int *num_buffers, + unsigned int *num_planes, unsigned int sizes[], + struct device *alloc_devs[]) +{ + struct npcm_video *video = vb2_get_drv_priv(q); + unsigned int i; + + if (*num_planes) { + if (sizes[0] < video->max_buffer_size) + return -EINVAL; + + return 0; + } + + *num_planes = 1; + sizes[0] = video->max_buffer_size; + + kfree(video->rect); + video->rect = NULL; + + video->rect = kcalloc(*num_buffers, sizeof(*video->rect), GFP_KERNEL); + if (!video->rect) + return -ENOMEM; + + if (video->list) { + npcm_video_free_diff_table(video); + kfree(video->list); + video->list = NULL; + } + + video->list = kzalloc(sizeof(*video->list) * *num_buffers, GFP_KERNEL); + if (!video->list) { + kfree(video->rect); + return -ENOMEM; + } + + for (i = 0; i < *num_buffers; i++) + INIT_LIST_HEAD(&video->list[i]); + + video->num_buffers = *num_buffers; + return 0; +} + +static int npcm_video_buf_prepare(struct vb2_buffer *vb) +{ + struct npcm_video *video = vb2_get_drv_priv(vb->vb2_queue); + + if (vb2_plane_size(vb, 0) < video->max_buffer_size) + return -EINVAL; + + return 0; +} + +static int npcm_video_start_streaming(struct vb2_queue *q, unsigned int count) +{ + struct npcm_video *video = vb2_get_drv_priv(q); + int rc; + + video->sequence = 0; + rc = npcm_video_start_frame(video); + if (rc) { + npcm_video_bufs_done(video, VB2_BUF_STATE_QUEUED); + return rc; + } + + set_bit(VIDEO_STREAMING, &video->flags); + return 0; +} + +static void npcm_video_stop_streaming(struct vb2_queue *q) +{ + struct npcm_video *video = vb2_get_drv_priv(q); + struct regmap *vcd = video->vcd_regmap; + + clear_bit(VIDEO_STREAMING, &video->flags); + regmap_write(vcd, VCD_INTE, 0); + regmap_write(vcd, VCD_STAT, VCD_STAT_CLEAR); + npcm_video_gfx_reset(video); + npcm_video_bufs_done(video, VB2_BUF_STATE_ERROR); + video->ctrl_cmd = VCD_CMD_OPERATION_CAPTURE; +} + +static void npcm_video_buf_queue(struct vb2_buffer *vb) +{ + struct npcm_video *video = vb2_get_drv_priv(vb->vb2_queue); + struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb); + struct npcm_video_buffer *nvb = to_npcm_video_buffer(vbuf); + unsigned long flags; + + spin_lock_irqsave(&video->lock, flags); + list_add_tail(&nvb->link, &video->buffers); + spin_unlock_irqrestore(&video->lock, flags); +} + +static void npcm_video_buf_finish(struct vb2_buffer *vb) +{ + struct npcm_video *video = vb2_get_drv_priv(vb->vb2_queue); + struct list_head *head, *pos, *nx; + struct rect_list *tmp; + + /* + * When a video buffer is dequeued, free associated rect_list and + * capture next frame. + */ + head = &video->list[video->vb_index]; + list_for_each_safe(pos, nx, head) { + tmp = list_entry(pos, struct rect_list, list); + list_del(&tmp->list); + kfree(tmp); + } + + if (npcm_video_start_frame(video)) { + dev_err(video->dev, "Failed to capture next frame\n"); + return; + } + + video->vb_index = vb->index; +} + +static const struct vb2_ops npcm_video_vb2_ops = { + .queue_setup = npcm_video_queue_setup, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, + .buf_prepare = npcm_video_buf_prepare, + .buf_finish = npcm_video_buf_finish, + .start_streaming = npcm_video_start_streaming, + .stop_streaming = npcm_video_stop_streaming, + .buf_queue = npcm_video_buf_queue, +}; + +static int npcm_video_setup_video(struct npcm_video *video) +{ + struct v4l2_device *v4l2_dev = &video->v4l2_dev; + struct video_device *vdev = &video->vdev; + struct vb2_queue *vbq = &video->queue; + int rc; + + video->pix_fmt.pixelformat = V4L2_PIX_FMT_HEXTILE; + video->pix_fmt.field = V4L2_FIELD_NONE; + video->pix_fmt.colorspace = V4L2_COLORSPACE_SRGB; + video->v4l2_input_status = V4L2_IN_ST_NO_SIGNAL; + + rc = v4l2_device_register(video->dev, v4l2_dev); + if (rc) { + dev_err(video->dev, "Failed to register v4l2 device\n"); + return rc; + } + + v4l2_ctrl_handler_init(&video->ctrl_handler, 2); + v4l2_ctrl_new_custom(&video->ctrl_handler, &npcm_ctrl_capture_mode, NULL); + v4l2_ctrl_new_custom(&video->ctrl_handler, &npcm_ctrl_rect_count, NULL); + if (video->ctrl_handler.error) { + dev_err(video->dev, "Failed to init controls: %d\n", + video->ctrl_handler.error); + + rc = video->ctrl_handler.error; + goto rel_ctrl_handler; + } + v4l2_dev->ctrl_handler = &video->ctrl_handler; + + vbq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + vbq->io_modes = VB2_MMAP | VB2_READ | VB2_DMABUF; + vbq->dev = v4l2_dev->dev; + vbq->lock = &video->video_lock; + vbq->ops = &npcm_video_vb2_ops; + vbq->mem_ops = &vb2_dma_contig_memops; + vbq->drv_priv = video; + vbq->buf_struct_size = sizeof(struct npcm_video_buffer); + vbq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; + vbq->min_buffers_needed = 3; + + rc = vb2_queue_init(vbq); + if (rc) { + dev_err(video->dev, "Failed to init vb2 queue\n"); + goto rel_ctrl_handler; + } + vdev->queue = vbq; + vdev->fops = &npcm_video_v4l2_fops; + vdev->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE | + V4L2_CAP_STREAMING; + vdev->v4l2_dev = v4l2_dev; + strscpy(vdev->name, DEVICE_NAME, sizeof(vdev->name)); + vdev->vfl_type = VFL_TYPE_VIDEO; + vdev->vfl_dir = VFL_DIR_RX; + vdev->release = video_device_release_empty; + vdev->ioctl_ops = &npcm_video_ioctls; + vdev->lock = &video->video_lock; + + video_set_drvdata(vdev, video); + rc = video_register_device(vdev, VFL_TYPE_VIDEO, 0); + if (rc) { + dev_err(video->dev, "Failed to register video device\n"); + goto rel_vb_queue; + } + + return 0; + +rel_vb_queue: + vb2_queue_release(vbq); +rel_ctrl_handler: + v4l2_ctrl_handler_free(&video->ctrl_handler); + v4l2_device_unregister(v4l2_dev); + + return rc; +} + +static int npcm_video_init(struct npcm_video *video) +{ + struct device *dev = video->dev; + int irq, rc; + + irq = irq_of_parse_and_map(dev->of_node, 0); + if (!irq) { + dev_err(dev, "Failed to find VCD IRQ\n"); + return -ENODEV; + } + + rc = devm_request_threaded_irq(dev, irq, NULL, npcm_video_irq, + IRQF_ONESHOT, DEVICE_NAME, video); + if (rc < 0) { + dev_err(dev, "Failed to request IRQ %d\n", irq); + return rc; + } + + of_reserved_mem_device_init(dev); + rc = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)); + if (rc) { + dev_err(dev, "Failed to set DMA mask\n"); + of_reserved_mem_device_release(dev); + } + + return rc; +} + +static const struct regmap_config npcm_video_regmap_cfg = { + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 32, + .max_register = VCD_FIFO, +}; + +static const struct regmap_config npcm_video_ece_regmap_cfg = { + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 32, + .max_register = ECE_HEX_RECT_OFFSET, +}; + +static int npcm_video_probe(struct platform_device *pdev) +{ + struct npcm_video *video = kzalloc(sizeof(*video), GFP_KERNEL); + struct device_node *ece_node; + struct platform_device *ece_pdev; + int rc; + void __iomem *regs; + + if (!video) + return -ENOMEM; + + video->frame_rate = MAX_FRAME_RATE; + video->dev = &pdev->dev; + spin_lock_init(&video->lock); + mutex_init(&video->video_lock); + INIT_LIST_HEAD(&video->buffers); + + regs = devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(regs)) { + dev_err(&pdev->dev, "Failed to parse VCD reg in DTS\n"); + return PTR_ERR(regs); + } + + video->vcd_regmap = devm_regmap_init_mmio(&pdev->dev, regs, + &npcm_video_regmap_cfg); + if (IS_ERR(video->vcd_regmap)) { + dev_err(&pdev->dev, "Failed to initialize VCD regmap\n"); + return PTR_ERR(video->vcd_regmap); + } + + ece_node = of_parse_phandle(video->dev->of_node, "nuvoton,ece", 0); + if (IS_ERR(ece_node)) { + dev_err(&pdev->dev, "Failed to get ECE phandle in DTS\n"); + return PTR_ERR(ece_node); + } + + ece_pdev = of_find_device_by_node(ece_node); + of_node_put(ece_node); + if (IS_ERR(ece_pdev)) { + dev_err(&pdev->dev, "Failed to find ECE device\n"); + return PTR_ERR(ece_pdev); + } + + regs = devm_platform_ioremap_resource(ece_pdev, 0); + if (IS_ERR(regs)) { + dev_err(&pdev->dev, "Failed to parse ECE reg in DTS\n"); + return PTR_ERR(regs); + } + + video->ece.regmap = devm_regmap_init_mmio(&pdev->dev, regs, + &npcm_video_ece_regmap_cfg); + if (IS_ERR(video->ece.regmap)) { + dev_err(&pdev->dev, "Failed to initialize ECE regmap\n"); + return PTR_ERR(video->ece.regmap); + } + + video->reset = devm_reset_control_get(&pdev->dev, NULL); + if (IS_ERR(video->reset)) { + dev_err(&pdev->dev, "Failed to get VCD reset control in DTS\n"); + return PTR_ERR(video->reset); + } + + video->ece.reset = devm_reset_control_get(&ece_pdev->dev, NULL); + if (IS_ERR(video->ece.reset)) { + dev_err(&pdev->dev, "Failed to get ECE reset control in DTS\n"); + return PTR_ERR(video->ece.reset); + } + + video->gcr_regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, + "nuvoton,sysgcr"); + if (IS_ERR(video->gcr_regmap)) + return PTR_ERR(video->gcr_regmap); + + video->gfx_regmap = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, + "nuvoton,sysgfxi"); + if (IS_ERR(video->gfx_regmap)) + return PTR_ERR(video->gfx_regmap); + + rc = npcm_video_init(video); + if (rc) + return rc; + + rc = npcm_video_setup_video(video); + if (rc) + return rc; + + dev_info(video->dev, "NPCM video driver probed\n"); + return 0; +} + +static int npcm_video_remove(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct v4l2_device *v4l2_dev = dev_get_drvdata(dev); + struct npcm_video *video = to_npcm_video(v4l2_dev); + + video_unregister_device(&video->vdev); + vb2_queue_release(&video->queue); + v4l2_ctrl_handler_free(&video->ctrl_handler); + v4l2_device_unregister(v4l2_dev); + npcm_video_ece_stop(video); + of_reserved_mem_device_release(dev); + + return 0; +} + +static const struct of_device_id npcm_video_match[] = { + { .compatible = "nuvoton,npcm750-vcd" }, + { .compatible = "nuvoton,npcm845-vcd" }, + {}, +}; + +MODULE_DEVICE_TABLE(of, npcm_video_match); + +static struct platform_driver npcm_video_driver = { + .driver = { + .name = DEVICE_NAME, + .of_match_table = npcm_video_match, + }, + .probe = npcm_video_probe, + .remove = npcm_video_remove, +}; + +module_platform_driver(npcm_video_driver); + +MODULE_AUTHOR("Joseph Liu"); +MODULE_AUTHOR("Marvin Lin"); +MODULE_DESCRIPTION("Driver for Nuvoton NPCM Video Capture/Encode Engine"); +MODULE_LICENSE("GPL");