From patchwork Tue May 14 06:13:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10942309 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 605D314DB for ; Tue, 14 May 2019 06:16:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4CE792846C for ; Tue, 14 May 2019 06:16:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FE432855A; Tue, 14 May 2019 06:16:18 +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 DBFCD2846C for ; Tue, 14 May 2019 06:16:17 +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=82kqKG16qv0BHu6+22DxGpRkgt1UPsYB8MOVAL3n1lA=; b=sC3xzChukiVSE9 UaW2VBaieAr7KaqFHZqkV6NwHe2/oEV3RhZHFNDA6Y+/ed870vOx976tfh4pVRQzqw5qjycre/LLc BPAIcQFhwK1ESOeUHRZ7FiHLLh5Lc5APOY5sRZpArZDqjN5pNSkMdN6tMAMAkR0SNWr2By8Z20Lvu RmWMfQQGsP3txLZhYPeFUwZGj1jpsA71moW3xRkkQKKApQk/YSAMVfuO+TU5GEjun9qAPRjuSCO6E zWLmqH4oxXpCksU2iuG9pErpL3X/l2nciJ7uYVfJEVD71CP7y3Ns32gvAzF0PlKleumIPnVEiO/R5 URLa8SV55MU2UR9JOcLg==; 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 1hQQjX-0002wP-Kw; Tue, 14 May 2019 06:16:15 +0000 Received: from mailgw01.mediatek.com ([216.200.240.184]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hQQhf-0007QT-V4; Tue, 14 May 2019 06:14:26 +0000 X-UUID: 39c7a978693a43eca904fa0efebdd368-20190513 X-UUID: 39c7a978693a43eca904fa0efebdd368-20190513 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 27969667; Mon, 13 May 2019 22:14:05 -0800 Received: from MTKMBS01N1.mediatek.inc (172.21.101.68) by MTKMBS62DR.mediatek.inc (172.29.94.18) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 13 May 2019 23:14:04 -0700 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 14 May 2019 14:13:54 +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, 14 May 2019 14:13:54 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Rob Herring , CK Hu Subject: [PATCH v3 06/13] [media] mtk-mipicsi: add function to support SerDes for link number Date: Tue, 14 May 2019 14:13:43 +0800 Message-ID: <1557814430-9675-7-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1557814430-9675-1-git-send-email-stu.hsieh@mediatek.com> References: <1557814430-9675-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190513_231420_392038_4A0EE1BC X-CRM114-Status: GOOD ( 15.05 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , Matthias Brugger , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add function to support SerDes for link number. Mt2712 can server at most four camera link for each mipicsi port. Therefore, driver need to know how many camera link in SerDes and set the mipicsi HW to serve. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 920848e965e3..117eb1939014 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -53,6 +53,8 @@ #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 MAX_SUPPORT_WIDTH 4096U #define MAX_SUPPORT_HEIGHT 4096U #define MAX_BUFFER_NUM 32U @@ -103,6 +105,8 @@ #define IMGO_STRIDE 0x238 #define DMA_FRAME_HEADER_EN 0xE00 +#define SerDes_support 1 + /* buffer for one video frame */ struct mtk_mipicsi_buf { struct list_head queue; @@ -127,6 +131,8 @@ struct mtk_mipicsi_dev { spinlock_t queue_lock; struct mtk_mipicsi_buf cam_buf[MAX_BUFFER_NUM]; bool streamon; + unsigned int link; + u8 link_reg_val; unsigned long enqueue_cnt; char drv_name[16]; u32 id; @@ -146,6 +152,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; @@ -177,6 +241,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) {