From patchwork Tue Apr 16 09:27:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10902359 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 52B00161F for ; Tue, 16 Apr 2019 09:30:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 281142892B for ; Tue, 16 Apr 2019 09:30:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BBB028931; Tue, 16 Apr 2019 09:30:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B40332892B for ; Tue, 16 Apr 2019 09:30:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pJ/JhwbTl8jgoNURXb7wO4jzMq02J4KuuC9yJKyp9mY=; b=B4Za9CF/0v/xhU P4ishil5xoWtcpOsfby9FIJPS7YOn77tULTmyIFvRvbs4WKhheFkx7R9v2wlK5ffJiNNAeLe55+by h3EpOFXm6FUeJvY601tK3nwWWilEzJR5b/pY1Fct/eWT0E1ol9sXV/yZVRCrPh4NJjsZhntzYjKKE ghw1PTjS6XRlYNHxBBae6d/kuaPj23+5nYzgz7n2vA0+DUEAtZe1NTG1DYTlFqScFGbfzduJaUbEl Ihg8ryF4EM/g4t31PeHtm+g8rKvyKVFTYGVvHlG6aic6k6o1AlJDJO05We+YXnY7MTr0ItzzrGEDY i3g9XcrmvLKsvQkCLKQw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKQQ-0005TH-GY; Tue, 16 Apr 2019 09:30:46 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hGKO7-0001Wk-1o; Tue, 16 Apr 2019 09:28:41 +0000 X-UUID: ee9bfb35c027484da4baacb56c81d2c7-20190416 X-UUID: ee9bfb35c027484da4baacb56c81d2c7-20190416 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1457213447; Tue, 16 Apr 2019 01:28:03 -0800 Received: from MTKMBS01N2.mediatek.inc (172.21.101.79) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 02:28:02 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 16 Apr 2019 17:27:47 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 16 Apr 2019 17:27:47 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v2 06/15] [media] mtk-mipicsi: add function to support SerDes for link number Date: Tue, 16 Apr 2019 17:27:34 +0800 Message-ID: <1555406863-18069-7-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1555406863-18069-1-git-send-email-stu.hsieh@mediatek.com> References: <1555406863-18069-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: 30009AA0D98A828B24D83753B640F6CBFD3112A4F8698811C6D2BDE8875B76262000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190416_022823_484594_447A3912 X-CRM114-Status: GOOD ( 14.59 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, wsd_upstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add function to support SerDes for link number. Mt2712 can server at most four camera link for each mipicsi port. Therefore, driver need to know how many camera link in SerDes and set the mipicsi HW to serve. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 10782fccca79..ec05f3b38cc9 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -56,12 +56,16 @@ #define MIPICSI_COMMON_CLK 2 #define MTK_CAMDMA_MAX_NUM 4U #define MIPICSI_CLK (MIPICSI_COMMON_CLK + MTK_CAMDMA_MAX_NUM) +#define MAX_DES_LINK 4U +#define SUBDEV_LINK_REG 0x49 #define MTK_DATAWIDTH_8 (0x01U << 7U) #define MAX_SUPPORT_WIDTH 4096U #define MAX_SUPPORT_HEIGHT 4096U #define MAX_BUFFER_NUM 32U #define VID_LIMIT_BYTES (100U * 1024U * 1024U) +#define SerDes_support 1 + /* buffer for one video frame */ struct mtk_mipicsi_buf { struct list_head queue; @@ -92,6 +96,7 @@ struct mtk_mipicsi_dev { bool streamon; unsigned long frame_cnt[MTK_CAMDMA_MAX_NUM]; unsigned int link; + u8 link_reg_val; unsigned long enqueue_cnt; unsigned long dequeue_cnt; struct v4l2_ctrl_handler ctrl_hdl; @@ -113,6 +118,64 @@ struct mtk_mipicsi_dev { V4L2_MBUS_PCLK_SAMPLE_FALLING | \ V4L2_MBUS_DATA_ACTIVE_HIGH) +static int get_subdev_register(const struct soc_camera_device *icd, + struct v4l2_dbg_register *reg) +{ + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + int ret = 0; + + reg->match.type = V4L2_CHIP_MATCH_SUBDEV; + reg->match.addr = 0; + ret = v4l2_subdev_call(sd, core, g_register, reg); + if (ret != 2) { + dev_err(icd->parent, "mipicsi get des register 0x%llx fail, ret=%d\n", + reg->reg, ret); + return -EIO; + } + + dev_info(icd->parent, "read DES [reg/val/ret] is [0x%llx/0x%llx/%d]\n", + reg->reg, reg->val, ret); + return ret; +} + +static int get_subdev_link(const struct soc_camera_device *icd, + unsigned int *link, u8 *link_reg_val) +{ + struct v4l2_dbg_register reg; + int ret = 0; + unsigned int index = 0U; + *link_reg_val = 0x0U; + + if (SerDes_support == 0) { + *link = 1; + *link_reg_val = 0x1; + dev_info(icd->parent, "subdev not support SerDes\n"); + return 0; + } + + if (link == NULL) + return -EINVAL; + + memset(®, 0, sizeof(reg)); + /*get camera link number*/ + reg.reg = SUBDEV_LINK_REG; + ret = get_subdev_register(icd, ®); + if (ret < 0) + return ret; + + *link = 0U; + for (index = 0U; index < MAX_DES_LINK; ++index) { + if ((reg.val & 0x01U) == 0x01U) { + *link += 1U; + *link_reg_val |= (0x01U << index); + } + reg.val >>= 1U; + } + + dev_info(icd->parent, "%u camera linked to sub device\n", *link); + return 0; +} + static u32 get_bytesperline(const u32 fmt, const u32 width) { u32 bytesperline = 0; @@ -144,6 +207,7 @@ static int mtk_mipicsi_add_device(struct soc_camera_device *icd) u32 height; u32 fmt; + (void)get_subdev_link(icd, &mipicsi->link, &mipicsi->link_reg_val); /* Get width/height info from subdev. Then use them to set register */ ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &format); if (ret < 0) {