From patchwork Mon Apr 8 11:54:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10889401 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 6920C1669 for ; Mon, 8 Apr 2019 11:57:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4754926AE3 for ; Mon, 8 Apr 2019 11:57:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3ADCC28643; Mon, 8 Apr 2019 11:57:36 +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 06E6E26AE3 for ; Mon, 8 Apr 2019 11:57:35 +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=pAfoL1kEqCoA2zCXXdCBTiTxaTBAYBAhpIR+fOihO78=; b=s945xa0m2K3Q6r rOpLyIG0C38k75VJ4tW4qOxb5LSytxbiFRWucqtg+P3R/IqEUFODyFOKvYMSvdXWVOwPResbtBakq r3WV33mkao26tOd4BkcqHN/tRZLJ1Hlg6GdFwucSNpJ9Q0Kch8GXwwnsDh7iyh/cf39zg/LFauwbo /zI67mJdF0nOpQ69ZF2IDO1yjRpxK7HBJefONPmB8EVifZHSKP9eWdWJDlhEZfzPFrBrevxv1CEwM S9ip3f5XkvS/KjCWjahTTHGtTCvcwqWT5chzGNvqks3m8Atnlt0Qz4yM1BfZJE7w3X+3pYItrBCic myyPUXD7bFZfKq8tHVJQ==; 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 1hDSu5-0004Ib-Pc; Mon, 08 Apr 2019 11:57:33 +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 1hDSsC-0001mJ-4h; Mon, 08 Apr 2019 11:55:47 +0000 X-UUID: a111df328f36451d82dfb23c883ddf2b-20190408 X-UUID: a111df328f36451d82dfb23c883ddf2b-20190408 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 836784417; Mon, 08 Apr 2019 03:55:29 -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, 8 Apr 2019 04:55:27 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 19:55:19 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 8 Apr 2019 19:55:19 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Matthias Brugger Subject: [PATCH 01/14] [media] mtk-mipicsi: add mediatek mipicsi driver for mt2712 Date: Mon, 8 Apr 2019 19:54:52 +0800 Message-ID: <1554724505-19882-2-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> References: <1554724505-19882-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-20190408_045536_273825_CCBB29D1 X-CRM114-Status: GOOD ( 20.37 ) 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: srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add mediatek mipicsi driver for mt2712, including probe function to get the value from device tree, and register to v4l2 the host device. Signed-off-by: Stu Hsieh --- drivers/media/platform/mtk-mipicsi/Makefile | 4 + .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 768 ++++++++++++++++++ 2 files changed, 772 insertions(+) create mode 100644 drivers/media/platform/mtk-mipicsi/Makefile create mode 100644 drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c diff --git a/drivers/media/platform/mtk-mipicsi/Makefile b/drivers/media/platform/mtk-mipicsi/Makefile new file mode 100644 index 000000000000..326a5e3808fa --- /dev/null +++ b/drivers/media/platform/mtk-mipicsi/Makefile @@ -0,0 +1,4 @@ +mtk-mipicsi-y += mtk_mipicsi.o + +obj-$(CONFIG_VIDEO_MEDIATEK_MIPICSI) += mtk-mipicsi.o + diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c new file mode 100644 index 000000000000..2e6c3073c064 --- /dev/null +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -0,0 +1,768 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) 2017 MediaTek Inc. + * Author: Ricky Zhang + * Baoyin Zhang + * Alan Yue + * Stu Hsieh + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * http://www.gnu.org/licenses/gpl-2.0.html for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef CONFIG_VB2_MEDIATEK_DMA_SG +#include "mtkbuf-dma-cache-sg.h" +#endif + +#define MTK_MIPICSI_DRV_NAME "mtk-mipicsi" +#define MTK_PLATFORM_STR "platform:mt2712" +#define MIPICSI_COMMON_CLK 2 +#define MTK_CAMDMA_MAX_NUM 4U +#define MIPICSI_CLK (MIPICSI_COMMON_CLK + MTK_CAMDMA_MAX_NUM) +#define MTK_DATAWIDTH_8 (0x01U << 7U) +#define MAX_SUPPORT_WIDTH 4096U +#define MAX_SUPPORT_HEIGHT 4096U +#define MAX_BUFFER_NUM 32U +#define VID_LIMIT_BYTES (100U * 1024U * 1024U) + +/* buffer for one video frame */ +struct mtk_mipicsi_buf { + struct list_head queue; + struct vb2_buffer *vb; + dma_addr_t vb_dma_addr_phy; + int prepare_flag; +}; + +struct mtk_mipicsi_dev { + struct soc_camera_host soc_host; + struct platform_device *pdev; + unsigned int camsv_num; + struct v4l2_device v4l2_dev; + struct device *larb_pdev; + void __iomem *ana; + void __iomem *seninf_ctrl; + void __iomem *seninf; + struct regmap *seninf_top; + void __iomem *seninf_mux[MTK_CAMDMA_MAX_NUM]; + void __iomem *camsv[MTK_CAMDMA_MAX_NUM]; + const struct soc_camera_format_xlate *current_fmt; + u16 width_flags; /* max 12 bits */ + struct list_head capture_list[MTK_CAMDMA_MAX_NUM]; + struct list_head fb_list; + spinlock_t lock; + spinlock_t queue_lock; + struct mtk_mipicsi_buf cam_buf[MAX_BUFFER_NUM]; + bool streamon; + unsigned long frame_cnt[MTK_CAMDMA_MAX_NUM]; + unsigned int link; + unsigned long enqueue_cnt; + unsigned long dequeue_cnt; + struct v4l2_ctrl_handler ctrl_hdl; + char drv_name[16]; + u32 id; + int clk_num; + struct clk *clk[MIPICSI_CLK]; +}; + +#define MTK_MIPICSI_BUS_PARAM (V4L2_MBUS_MASTER | \ + V4L2_MBUS_HSYNC_ACTIVE_HIGH | \ + V4L2_MBUS_HSYNC_ACTIVE_LOW | \ + V4L2_MBUS_VSYNC_ACTIVE_HIGH | \ + V4L2_MBUS_VSYNC_ACTIVE_LOW | \ + V4L2_MBUS_PCLK_SAMPLE_RISING | \ + V4L2_MBUS_PCLK_SAMPLE_FALLING | \ + V4L2_MBUS_DATA_ACTIVE_HIGH) + +static int mtk_mipicsi_add_device(struct soc_camera_device *icd) +{ + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + struct v4l2_subdev_format format = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + }; + int ret; + + /* Get width/height info from subdev. Then use them to set register */ + ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &format); + if (ret < 0) { + dev_err(icd->parent, "sub device get_fmt fail\n"); + return ret; + } + + /* + * If power domain was closed before, it will be open. + * Then clock will be open and register will be set + */ + (void)pm_runtime_get_sync(icd->parent); + return 0; +} + +static void mtk_mipicsi_remove_device(struct soc_camera_device *icd) +{ + (void)pm_runtime_put_sync(icd->parent); +} + +static int mtk_mipicsi_set_fmt(struct soc_camera_device *icd, + struct v4l2_format *f) +{ + struct soc_camera_host *ici = to_soc_camera_host(icd->parent); + struct mtk_mipicsi_dev *mipicsi = ici->priv; + struct device *dev = &mipicsi->pdev->dev; + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + const struct soc_camera_format_xlate *xlate = NULL; + struct v4l2_pix_format *pix = &f->fmt.pix; + struct v4l2_subdev_format format = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + }; + struct v4l2_mbus_framefmt *mf = &format.format; + int ret = 0; + + xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); + if (xlate == NULL) { + dev_err(dev, "Format 0x%x not found\n", pix->pixelformat); + return -EINVAL; + } + + mf->width = pix->width; + mf->height = pix->height; + mf->field = pix->field; + mf->colorspace = pix->colorspace; + mf->code = xlate->code; + + ret = v4l2_subdev_call(sd, pad, set_fmt, NULL, &format); + pix->width = mf->width; + pix->height = mf->height; + pix->field = mf->field; + pix->colorspace = mf->colorspace; + icd->current_fmt = xlate; + if (pix->pixelformat == V4L2_PIX_FMT_YUYV) + pix->sizeimage = pix->width * pix->height * 2U; + + if (mf->code != xlate->code) + return -EINVAL; + + return ret; +} + +static int mtk_mipicsi_try_fmt(struct soc_camera_device *icd, + struct v4l2_format *f) +{ + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + const struct soc_camera_format_xlate *xlate = NULL; + struct v4l2_pix_format *pix = &f->fmt.pix; + struct v4l2_subdev_pad_config pad_cfg; + struct v4l2_subdev_format format = { + .which = V4L2_SUBDEV_FORMAT_TRY, + }; + struct v4l2_mbus_framefmt *mf = &format.format; + u32 pixfmt = pix->pixelformat; + int ret = 0; + + xlate = soc_camera_xlate_by_fourcc(icd, pixfmt); + if (xlate == NULL) { + xlate = icd->current_fmt; + dev_dbg(icd->parent, "Format %x not found, keeping %x\n", + pixfmt, xlate->host_fmt->fourcc); + pixfmt = xlate->host_fmt->fourcc; + pix->pixelformat = pixfmt; + pix->colorspace = icd->colorspace; + } + + /* limit to MTK hardware capabilities */ + pix->height = min(pix->height, MAX_SUPPORT_HEIGHT); + pix->width = min(pix->width, MAX_SUPPORT_WIDTH); + + /* limit to sensor capabilities */ + mf->width = pix->width; + mf->height = pix->height; + mf->field = pix->field; + mf->colorspace = pix->colorspace; + mf->code = xlate->code; + + ret = v4l2_subdev_call(sd, pad, set_fmt, &pad_cfg, &format); + if (ret < 0) + return ret; + + pix->width = mf->width; + pix->height = mf->height; + pix->field = mf->field; + pix->colorspace = mf->colorspace; + pix->bytesperline = pix->width * 2U; + pix->sizeimage = pix->bytesperline * pix->height; + + return ret; +} + +static int mtk_mipicsi_vb2_queue_setup(struct vb2_queue *vq, + unsigned int *nbufs, + unsigned int *num_planes, unsigned int sizes[], + struct device *alloc_devs[]) +{ + struct soc_camera_device *icd = soc_camera_from_vb2q(vq); + u32 sizeimage = icd->sizeimage; + + if (*nbufs == 0U || *nbufs > MAX_BUFFER_NUM) + *nbufs = MAX_BUFFER_NUM; + if (sizeimage * *nbufs > VID_LIMIT_BYTES) + *nbufs = VID_LIMIT_BYTES / sizeimage; + + /* + * Called from VIDIOC_REQBUFS or in compatibility mode For YUV422P + * format, even if there are 3 planes Y, U and V, we reply there is only + * one plane, containing Y, U and V data, one after the other. + */ + if (*num_planes != 0U) + return sizes[0] < sizeimage ? -EINVAL : 0; + sizes[0] = sizeimage; + *num_planes = 1; + return 0; +} + +static int mtk_mipicsi_vb2_init(struct vb2_buffer *vb) +{ + struct mtk_mipicsi_dev *mipicsi = vb2_get_drv_priv(vb->vb2_queue); + + mipicsi->cam_buf[vb->index].prepare_flag = 0; + + return 0; +} + +static int mtk_mipicsi_vb2_prepare(struct vb2_buffer *vb) +{ + struct soc_camera_device *icd = NULL; + struct soc_camera_host *ici = NULL; + struct mtk_mipicsi_dev *mipicsi = NULL; + struct mtk_mipicsi_buf *buf; + u32 size = 0; + char *va = NULL; + + /* notice that vb->vb2_queue addr equals to soc_camera_device->vb2_vidq. + * It was handled in reqbufs + */ + icd = soc_camera_from_vb2q(vb->vb2_queue); + ici = to_soc_camera_host(icd->parent); + mipicsi = ici->priv; + buf = &mipicsi->cam_buf[vb->index]; + size = icd->sizeimage; + + if (vb2_plane_size(vb, 0) < size) { + dev_err(icd->parent, "data will not fit into plane (%lu < %u)", + vb2_plane_size(vb, 0), size); + return -EINVAL; + } + + vb2_set_plane_payload(vb, 0, size); + + if ((buf->prepare_flag) == 0) { + buf->prepare_flag = 1; +#ifdef CONFIG_VB2_MEDIATEK_DMA_SG + buf->vb_dma_addr_phy = + mtk_dma_sg_plane_dma_addr(vb, 0); +#else + buf->vb_dma_addr_phy = + vb2_dma_contig_plane_dma_addr(vb, 0); +#endif + va = vb2_plane_vaddr(vb, 0); + buf->vb = vb; + } + + return 0; +} + +static void mtk_mipicsi_vb2_queue(struct vb2_buffer *vb) +{ + struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue); + struct soc_camera_host *ici = to_soc_camera_host(icd->parent); + struct mtk_mipicsi_dev *mipicsi = ici->priv; + char *va = NULL; + + spin_lock(&mipicsi->queue_lock); + list_add_tail(&(mipicsi->cam_buf[vb->index].queue), + &(mipicsi->fb_list)); + spin_unlock(&mipicsi->queue_lock); + + va = vb2_plane_vaddr(vb, 0); + + ++(mipicsi->enqueue_cnt); +} + +static int mtk_mipicsi_vb2_start_streaming(struct vb2_queue *vq, + unsigned int count) +{ + struct soc_camera_device *icd = soc_camera_from_vb2q(vq); + struct soc_camera_host *ici = to_soc_camera_host(icd->parent); + struct mtk_mipicsi_dev *mipicsi = ici->priv; + + icd->vdev->queue = vq; + + mipicsi->streamon = true; + return 0; +} + +static void mtk_mipicsi_vb2_stop_streaming(struct vb2_queue *vq) +{ + struct mtk_mipicsi_dev *mipicsi = vb2_get_drv_priv(vq); + struct mtk_mipicsi_buf *buf = NULL; + struct mtk_mipicsi_buf *tmp = NULL; + unsigned int index = 0; + + spin_lock(&mipicsi->queue_lock); + while (list_empty(&(mipicsi->fb_list)) == 0) { + list_for_each_entry_safe(buf, tmp, &(mipicsi->fb_list), queue) { + if (buf->vb->state == VB2_BUF_STATE_ACTIVE) { + vb2_buffer_done(buf->vb, VB2_BUF_STATE_ERROR); + break; + } + } + buf->vb_dma_addr_phy = 0ULL; + buf->prepare_flag = 0; + index = buf->vb->index; + list_del_init(&(mipicsi->cam_buf[index].queue)); + } + spin_unlock(&mipicsi->queue_lock); + mipicsi->streamon = false; + + INIT_LIST_HEAD(&(mipicsi->fb_list)); + + mipicsi->enqueue_cnt = 0UL; + mipicsi->dequeue_cnt = 0UL; +} + +static struct vb2_ops mtk_vb2_ops = { + .queue_setup = mtk_mipicsi_vb2_queue_setup, + .buf_init = mtk_mipicsi_vb2_init, + .buf_prepare = mtk_mipicsi_vb2_prepare, + .buf_queue = mtk_mipicsi_vb2_queue, + .start_streaming = mtk_mipicsi_vb2_start_streaming, + .stop_streaming = mtk_mipicsi_vb2_stop_streaming, + .wait_prepare = vb2_ops_wait_prepare, + .wait_finish = vb2_ops_wait_finish, +}; + +static int mtk_mipicsi_init_videobuf2(struct vb2_queue *q, + struct soc_camera_device *icd) +{ + struct soc_camera_host *ici = to_soc_camera_host(icd->parent); + struct mtk_mipicsi_dev *mipicsi = ici->priv; + struct mutex *q_lock = NULL; + + q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + q->io_modes = VB2_MMAP; + q->drv_priv = mipicsi; + q->buf_struct_size = sizeof(struct vb2_buffer); + q->ops = &mtk_vb2_ops; +#ifdef CONFIG_VB2_MEDIATEK_DMA_SG + q->mem_ops = &mtk_dma_sg_memops; +#else + q->mem_ops = &vb2_dma_contig_memops; +#endif + q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; + q->dev = ici->v4l2_dev.dev; + q_lock = devm_kzalloc(mipicsi->soc_host.v4l2_dev.dev, + sizeof(*q_lock), GFP_KERNEL); + q->lock = q_lock; + mutex_init(q->lock); + + return vb2_queue_init(q); +} + +static int mtk_mipicsi_querycap(struct soc_camera_host *ici, + struct v4l2_capability *cap) +{ + struct mtk_mipicsi_dev *mipicsi = ici->priv; + + (void)strlcpy(cap->card, MTK_PLATFORM_STR, sizeof(cap->card)); + (void)strlcpy(cap->driver, mipicsi->drv_name, sizeof(cap->driver)); + (void)strlcpy(cap->bus_info, MTK_PLATFORM_STR, sizeof(cap->bus_info)); + cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING; + cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; + + return 0; +} + +static int mtk_mipicsi_set_bus_param(struct soc_camera_device *icd) +{ + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_PARALLEL,}; + unsigned int common_flags = 0U; + int ret = 0; + + ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg); + if (ret == 0) { + common_flags = soc_mbus_config_compatible(&cfg, + MTK_MIPICSI_BUS_PARAM); + if (common_flags == 0U) { + dev_err(icd->parent, "Flags incompatible: camera 0x%x", + cfg.flags); + return -EINVAL; + } + } else { + if (ret != -ENOIOCTLCMD) + return ret; + } + common_flags = MTK_MIPICSI_BUS_PARAM; + + dev_dbg(icd->parent, "Flags cam: 0x%x common: 0x%x\n", + cfg.flags, common_flags); + + cfg.flags = common_flags; + ret = v4l2_subdev_call(sd, video, s_mbus_config, &cfg); + if (ret < 0 && ret != -ENOIOCTLCMD) { + dev_dbg(icd->parent, "camera s_mbus_config(0x%x) returned %d\n", + common_flags, ret); + return ret; + } + + return 0; +} + +static struct soc_camera_host_ops mtk_soc_camera_host_ops = { + .owner = THIS_MODULE, + .add = mtk_mipicsi_add_device, + .remove = mtk_mipicsi_remove_device, + .set_fmt = mtk_mipicsi_set_fmt, + .try_fmt = mtk_mipicsi_try_fmt, + .init_videobuf2 = mtk_mipicsi_init_videobuf2, + .poll = vb2_fop_poll, + .querycap = mtk_mipicsi_querycap, + .set_bus_param = mtk_mipicsi_set_bus_param, +}; + +static int seninf_mux_camsv_node_parse(struct mtk_mipicsi_dev *mipicsi, + int index) +{ + struct clk *clk = NULL; + struct device *dev = NULL; + struct resource *res = NULL; + struct platform_device *camdma_pdev = NULL; + struct platform_device *pdev = NULL; + struct device_node *np = NULL; + + if (mipicsi == NULL) + return -EINVAL; + + dev = &mipicsi->pdev->dev; + pdev = mipicsi->pdev; + + np = of_parse_phandle(dev->of_node, + "mediatek,seninf_mux_camsv", index); + if (np == NULL) { + dev_err(dev, "no NO.%d mediatek,seninf_mux_camsv node\n", + index); + return -ENODEV; + } + + camdma_pdev = of_find_device_by_node(np); + of_node_put(np); + if (camdma_pdev == NULL) { + camdma_pdev = of_platform_device_create(np, NULL, + platform_bus_type.dev_root); + if (camdma_pdev == NULL) + return -EPROBE_DEFER; + } + + clk = of_clk_get(np, 0); + if (clk == NULL) { + dev_err(dev, "get clk fail in %s node\n", np->full_name); + return -ENODEV; + } + mipicsi->clk[index] = clk; + + res = platform_get_resource(camdma_pdev, IORESOURCE_MEM, 0); + if (res == NULL) { + dev_err(dev, "get seninf_mux memory failed in %s node\n", + np->full_name); + return -ENODEV; + } + mipicsi->seninf_mux[index] = + devm_ioremap_resource(&camdma_pdev->dev, res); + + res = platform_get_resource(camdma_pdev, IORESOURCE_MEM, 1); + if (res == NULL) { + dev_err(dev, "get camsv memory failed in %s node\n", + np->full_name); + return -ENODEV; + } + mipicsi->camsv[index] = + devm_ioremap_resource(&camdma_pdev->dev, res); + + INIT_LIST_HEAD(&mipicsi->capture_list[index]); + mipicsi->frame_cnt[index] = 0UL; + + dev_info(dev, "%s parse done\n", np->full_name); + + return 0; +} + +static int mtk_mipicsi_common_node_parse(struct mtk_mipicsi_dev *mipicsi, + struct device_node *node) +{ + int i = 0; + struct regmap *seninf_top = NULL; + struct device *dev = NULL; + struct platform_device *pdev = NULL; + struct clk *clk = NULL; + + if ((mipicsi == NULL) || (node == NULL)) + return -EINVAL; + + dev = &mipicsi->pdev->dev; + pdev = mipicsi->pdev; + + /* All the mipicsi HW share the same seninf_top */ + seninf_top = syscon_regmap_lookup_by_phandle(dev->of_node, + "mediatek,mipicsi"); + if (seninf_top == NULL) { + dev_err(dev, "Missing mediadek,mipicsi in %s node\n", + node->full_name); + return -EINVAL; + } + mipicsi->seninf_top = seninf_top; + + /* get IMG_SENINF_CAM_EN and IMG_SENINF_SCAM_EN clk*/ + mipicsi->clk_num = mipicsi->camsv_num; + + for (i = 0; i < MIPICSI_COMMON_CLK; ++i) { + clk = of_clk_get(node, i); + if (clk == NULL) { + dev_err(dev, "get clk fail in %s node\n", + node->full_name); + return -EINVAL; + } + mipicsi->clk[mipicsi->clk_num] = clk; + ++mipicsi->clk_num; + } + + dev_info(dev, "%s parse done\n", node->full_name); + + return 0; +} + +static int mtk_mipicsi_node_parse(struct mtk_mipicsi_dev *mipicsi) +{ + int ret; + int camsv_num = 0; + int i; + struct device *dev = NULL; + struct resource *res = NULL; + struct device_node *common_node = NULL; + struct platform_device *pdev = NULL; + + if (mipicsi == NULL) + return -EINVAL; + + dev = &mipicsi->pdev->dev; + pdev = mipicsi->pdev; + + /* mediatek,mipicsiid is a flag to show which mipicsi HW */ + ret = of_property_read_u32(dev->of_node, "mediatek,mipicsiid", + (u32 *)&mipicsi->id); + if (ret != 0) { + dev_info(dev, "not set mediatek,mipicsiid, use default id 0\n"); + mipicsi->id = 0; + } + (void)sprintf(mipicsi->drv_name, MTK_MIPICSI_DRV_NAME"%d", + mipicsi->id); + + /* get and parse seninf_mux_camsv */ + camsv_num = of_count_phandle_with_args(dev->of_node, + "mediatek,seninf_mux_camsv", NULL); + if (camsv_num <= 0) { + dev_err(dev, "no mediatek,seninf_mux_camsv\n"); + return -EINVAL; + } + mipicsi->camsv_num = camsv_num; + dev_info(dev, "there are %d camsv node\n", camsv_num); + + for (i = 0; i < mipicsi->camsv_num; ++i) { + ret = seninf_mux_camsv_node_parse(mipicsi, i); + if ((ret < 0) && (ret != -EPROBE_DEFER)) { + dev_err(dev, + "NO.%d seninf_mux_camsv node parse fail\n", i); + return ret; + } + } + + /* get mediatek,mipicsi node and its resource */ + common_node = of_parse_phandle(dev->of_node, "mediatek,mipicsi", 0); + if (common_node == NULL) { + dev_err(dev, "no mediadek,mipicsi\n"); + return -EINVAL; + } + + ret = mtk_mipicsi_common_node_parse(mipicsi, common_node); + if (ret < 0) + return ret; + + /*get ana and seninf reg*/ + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (res == NULL) { + dev_err(dev, "get ana register failed\n"); + return -ENODEV; + } + mipicsi->ana = devm_ioremap_resource(&pdev->dev, res); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 1); + if (res == NULL) { + dev_err(dev, "get seninf_ctrl register failed\n"); + return -ENODEV; + } + mipicsi->seninf_ctrl = devm_ioremap_resource(&pdev->dev, res); + + res = platform_get_resource(pdev, IORESOURCE_MEM, 2); + if (res == NULL) { + dev_err(dev, "get seninf register failed\n"); + return -ENODEV; + } + mipicsi->seninf = devm_ioremap_resource(&pdev->dev, res); + + dev_info(dev, "mipicsi node parse done\n"); + + return 0; +} + +static int mtk_mipicsi_probe(struct platform_device *pdev) +{ + struct mtk_mipicsi_dev *mipicsi = NULL; + int ret = 0; + struct iommu_domain *iommu = NULL; + struct device_node *larb_node = NULL; + struct platform_device *larb_pdev = NULL; + + iommu = iommu_get_domain_for_dev(&pdev->dev); + if (iommu == NULL) { + dev_err(&pdev->dev, "Waiting iommu driver ready...\n"); + return -EPROBE_DEFER; + } + + larb_node = of_parse_phandle(pdev->dev.of_node, "mediatek,larb", 0); + if (larb_node == NULL) { + dev_err(&pdev->dev, "Missing mediadek,larb in %s node\n", + pdev->dev.of_node->full_name); + return -EINVAL; + } + + larb_pdev = of_find_device_by_node(larb_node); + if (larb_pdev == NULL || !larb_pdev->dev.driver) { + dev_err(&pdev->dev, "Waiting for larb device %s\n", + larb_node->full_name); + return -EPROBE_DEFER; + } + of_node_put(larb_node); + + mipicsi = devm_kzalloc(&pdev->dev, sizeof(*mipicsi), GFP_KERNEL); + if (mipicsi == NULL) + return -ENOMEM; + + mipicsi->pdev = pdev; + mipicsi->larb_pdev = &larb_pdev->dev; + + ret = mtk_mipicsi_node_parse(mipicsi); + if (ret < 0) + return ret; + + pm_runtime_enable(&pdev->dev); + + mipicsi->soc_host.drv_name = mipicsi->drv_name; + mipicsi->soc_host.ops = &mtk_soc_camera_host_ops; + mipicsi->soc_host.priv = mipicsi; + mipicsi->soc_host.v4l2_dev.dev = &pdev->dev; + mipicsi->soc_host.nr = mipicsi->id; + mipicsi->width_flags = MTK_DATAWIDTH_8; + mipicsi->streamon = false; + + ret = soc_camera_host_register(&mipicsi->soc_host); + if (ret < 0) { + dev_err(&pdev->dev, "soc camera host register fail\n"); + pm_runtime_disable(&pdev->dev); + return ret; + } + + INIT_LIST_HEAD(&mipicsi->fb_list); + spin_lock_init(&mipicsi->queue_lock); + spin_lock_init(&mipicsi->lock); + mipicsi->enqueue_cnt = 0UL; + mipicsi->dequeue_cnt = 0UL; + +#ifdef CONFIG_VB2_MEDIATEK_DMA_SG + ret = mtk_dma_sg_init_ctx(&pdev->dev); +#else + ret = vb2_dma_contig_set_max_seg_size(&pdev->dev, DMA_BIT_MASK(32U)); +#endif + if (ret != 0) { + dev_err(&pdev->dev, "dma set max seg size fail\n"); + goto clean; + } + + dev_info(&pdev->dev, "probe done\n"); + return ret; +clean: + soc_camera_host_unregister(&mipicsi->soc_host); + pm_runtime_disable(&pdev->dev); + return ret; +} + +static int mtk_mipicsi_remove(struct platform_device *pdev) +{ + struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev); + + soc_camera_host_unregister(soc_host); + pm_runtime_disable(&pdev->dev); + + return 0; +} + +static const struct of_device_id mtk_mipicsi_of_match[] = { + { .compatible = "mediatek,mt2712-mipicsi", }, + {}, +}; + +static struct platform_driver mtk_mipicsi_driver = { + .driver = { + .name = MTK_MIPICSI_DRV_NAME, + .of_match_table = of_match_ptr(mtk_mipicsi_of_match), + }, + .probe = mtk_mipicsi_probe, + .remove = mtk_mipicsi_remove, +}; + +module_platform_driver(mtk_mipicsi_driver); +MODULE_DESCRIPTION("MediaTek SoC Camera Host driver"); +MODULE_LICENSE("GPL v2"); From patchwork Mon Apr 8 11:54:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10889353 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 2934A1669 for ; Mon, 8 Apr 2019 11:56:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0AC7F28643 for ; Mon, 8 Apr 2019 11:56:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F256E271CB; Mon, 8 Apr 2019 11:56:06 +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 9F0B4271CB for ; Mon, 8 Apr 2019 11:56:06 +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=cYL/0TOpI5nhZkb1u70HXAnraczI6Ll46L+bReFKqks=; b=Jow7kDyeBcqlp8 hPECX4rMaqnHY7bMiMk/bdhH09Ttn4zG1WS/ERj4oPBdSV1afvpRTMU6mcRNA/L60hnsQCrIiQSD3 vyJneP3j0BbghaxdUbYIx1S/jQEcmNcGPTdDwOGf/yfUomTwRu9IJmk7hS1vphmk7g3meOJzpoObm wSUlJ3PkKkrGd0NJk3Uw2WWR3BwAq4plIMTP+7KgROs1oTADGmpVGV3m6icnk4e/jBtuU7E21pc6M zwbxC4ut1oR0LvXl6/bNllVod0B1+uXpspazRBSzuc5jJU0CfwMXDkInPNEUR/e2luAK7FnJy2b1q bqh/ZvA5+AAkReTHOjEg==; 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 1hDSse-0002Pv-Nw; Mon, 08 Apr 2019 11:56:04 +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 1hDSsC-0001m9-2L; Mon, 08 Apr 2019 11:55:37 +0000 X-UUID: 408308bd6a3a42bcb7bbc9247603aefd-20190408 X-UUID: 408308bd6a3a42bcb7bbc9247603aefd-20190408 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1345941687; Mon, 08 Apr 2019 03:55:30 -0800 Received: from mtkmbs03n2.mediatek.inc (172.21.101.182) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 04:55:29 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs03n2.mediatek.inc (172.21.101.182) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 19:55:21 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 8 Apr 2019 19:55:21 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Matthias Brugger Subject: [PATCH 02/14] [media] mtk-mipicsi: add pm function Date: Mon, 8 Apr 2019 19:54:53 +0800 Message-ID: <1554724505-19882-3-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> References: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: FB59758C98CE6819ADDFF1D50DAAE8C7381E8E342FB07C671B408C9B57CAD6A42000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190408_045536_115497_38E29B40 X-CRM114-Status: GOOD ( 11.55 ) 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: srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add PM function to enable/disable clk and larb. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 2e6c3073c064..a5ed720df900 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -465,6 +465,85 @@ static struct soc_camera_host_ops mtk_soc_camera_host_ops = { .set_bus_param = mtk_mipicsi_set_bus_param, }; +static int mtk_mipicsi_pm_suspend(struct device *dev) +{ + struct soc_camera_host *ici = to_soc_camera_host(dev); + struct mtk_mipicsi_dev *mipicsi = NULL; + int ret = 0; + int i = 0; + + mipicsi = container_of(ici, struct mtk_mipicsi_dev, soc_host); + if (mipicsi->soc_host.icd != NULL) { + struct v4l2_subdev *sd = + soc_camera_to_subdev(mipicsi->soc_host.icd); + + ret = v4l2_subdev_call(sd, core, s_power, 0); + if (ret == -ENOIOCTLCMD) + ret = 0; + } + + /* close digtal and analog clock */ + for (i = 0; i < mipicsi->clk_num; ++i) + clk_disable_unprepare(mipicsi->clk[i]); + + if (mipicsi->larb_pdev != NULL) + mtk_smi_larb_put(mipicsi->larb_pdev); + + return ret; +} + +static int mtk_mipicsi_suspend(struct device *dev) +{ + if (pm_runtime_suspended(dev)) + return 0; + + return mtk_mipicsi_pm_suspend(dev); +} + +static int mtk_mipicsi_pm_resume(struct device *dev) +{ + struct soc_camera_host *ici = to_soc_camera_host(dev); + struct mtk_mipicsi_dev *mipicsi = + container_of(ici, struct mtk_mipicsi_dev, soc_host); + int ret = 0; + int i = 0; + + if (mipicsi->soc_host.icd != NULL) { + struct v4l2_subdev *sd = + soc_camera_to_subdev(mipicsi->soc_host.icd); + + ret = v4l2_subdev_call(sd, core, s_power, 1); + if (ret == -ENOIOCTLCMD) + ret = 0; + } + + if (mipicsi->larb_pdev != NULL) { + ret = mtk_smi_larb_get(mipicsi->larb_pdev); + if (ret != 0) + return ret; + } + + /* enable digtal clock */ + for (i = 0; i < mipicsi->clk_num; ++i) + (void)clk_prepare_enable(mipicsi->clk[i]); + + return ret; +} + +static int mtk_mipicsi_resume(struct device *dev) +{ + if (pm_runtime_suspended(dev)) + return 0; + + return mtk_mipicsi_pm_resume(dev); +} + +static const struct dev_pm_ops mtk_mipicsi_pm = { + SET_SYSTEM_SLEEP_PM_OPS(mtk_mipicsi_suspend, mtk_mipicsi_resume) + SET_RUNTIME_PM_OPS(mtk_mipicsi_pm_suspend, + mtk_mipicsi_pm_resume, NULL) +}; + static int seninf_mux_camsv_node_parse(struct mtk_mipicsi_dev *mipicsi, int index) { @@ -757,6 +836,7 @@ static const struct of_device_id mtk_mipicsi_of_match[] = { static struct platform_driver mtk_mipicsi_driver = { .driver = { .name = MTK_MIPICSI_DRV_NAME, + .pm = &mtk_mipicsi_pm, .of_match_table = of_match_ptr(mtk_mipicsi_of_match), }, .probe = mtk_mipicsi_probe, From patchwork Mon Apr 8 11:54:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10889395 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 521FC1669 for ; Mon, 8 Apr 2019 11:57:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3389226AE3 for ; Mon, 8 Apr 2019 11:57:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 273EA28643; Mon, 8 Apr 2019 11:57:16 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 237B526AE3 for ; Mon, 8 Apr 2019 11:57:10 +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=IhC0djKYv79W6Tc/FtpnMR6VXNiP/v1WA+sufBkKwyY=; b=phGegNREtsMIyk AVdZR87m83wsdSkhVLztm5tkVTW9ThiT/bi0U7xaMzpQhaH1K5w2oezE+zSmoEUF471P04LH4C5Ru KfK/juBfwZZxOzSdNPuRQ6yqhakgTW/+vvq8YaLpHoca8OzrahdbdADYQR7VzYe2PTkMMc4ACy5GP TEUY1N8jD3Flytq4nBdL7xKuA1lXcd7kUspmnem9SqrYyVO79vlld7bpTldPikUU/r11+0FojK5Zu Iz49yKgwrQWtaG0NcuNViqehwv2kynROdj6G1z3PAHTNas5F8OnlikV50p8R4tckeXd9tlSL+ueKA dvhLzav7AoFjbOlUHFUg==; 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 1hDStg-0003lq-KM; Mon, 08 Apr 2019 11:57:08 +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 1hDSsF-0001mH-VU; Mon, 08 Apr 2019 11:55:45 +0000 X-UUID: 5b40009eb8bb4fffbfdf0caf97345a26-20190408 X-UUID: 5b40009eb8bb4fffbfdf0caf97345a26-20190408 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1875018426; Mon, 08 Apr 2019 03:55:32 -0800 Received: from MTKMBS01N2.mediatek.inc (172.21.101.79) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 04:55:31 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 19:55:23 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 8 Apr 2019 19:55:23 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Matthias Brugger Subject: [PATCH 03/14] [media] mtk-mipicsi: add color format support for mt2712 Date: Mon, 8 Apr 2019 19:54:54 +0800 Message-ID: <1554724505-19882-4-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> References: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: 18EDCA312253150C541D4119A181E5C8EA8AC171CBF65635722FC11C2DBE24A52000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190408_045540_308948_F61339B2 X-CRM114-Status: UNSURE ( 9.71 ) X-CRM114-Notice: Please train this message. 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: srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add color format support for mt2712 Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index a5ed720df900..ccf2d18a3e74 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -139,6 +139,25 @@ static void mtk_mipicsi_remove_device(struct soc_camera_device *icd) (void)pm_runtime_put_sync(icd->parent); } +static bool is_supported(struct soc_camera_device *icd, const u32 pixformat) +{ + bool ret = false; + + switch (pixformat) { + /* YUV422 */ + case V4L2_PIX_FMT_YUYV: + case V4L2_PIX_FMT_UYVY: + case V4L2_PIX_FMT_YVYU: + case V4L2_PIX_FMT_VYUY: + ret = true; + break; + default: + break; + } + + return ret; +} + static int mtk_mipicsi_set_fmt(struct soc_camera_device *icd, struct v4l2_format *f) { @@ -154,6 +173,12 @@ static int mtk_mipicsi_set_fmt(struct soc_camera_device *icd, struct v4l2_mbus_framefmt *mf = &format.format; int ret = 0; + if (!is_supported(icd, pix->pixelformat)) { + dev_err(dev, "Format %x not support. set V4L2_PIX_FMT_YUYV as default\n", + pix->pixelformat); + pix->pixelformat = V4L2_PIX_FMT_YUYV; + } + xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat); if (xlate == NULL) { dev_err(dev, "Format 0x%x not found\n", pix->pixelformat); From patchwork Mon Apr 8 11:54:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10889429 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 DC1AD922 for ; Mon, 8 Apr 2019 12:06:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BFC4528426 for ; Mon, 8 Apr 2019 12:06:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B400D283A5; Mon, 8 Apr 2019 12:06:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6D6AA28426 for ; Mon, 8 Apr 2019 12:06:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=BsghLw+Ddl6tGzapVsUjn6YDFBmtgB3k8smc+RnWgQo=; b=WKm6nk69Gv6TYM bUb+1Wte/Zk2t/1KsHAkaZn1Hx8E7Du4lZEzCWZZlpYDu8zhPxORbkHweMvqFN9waeJMFKyHAbySr YFX+AhhMTWh43DQRdJUXLpeHzZ9LhEvOGs6Q/u3w1MSF2lENEqgkhr6Jq6whMznGFUC3JehXiSH2U cNkWwGfmwAssSKmNlysgMYyWut5oerc8ReBvC4sFIlF5FykG4aSswR0wOJdjfuCICLR94/i9uxdAs NpGCTsSDj7gMxVGtsYyOqY/CdMrGLV3SLtE0tAbF+YCVmp4ML09O6YheY8NB5YMM0wgrf59dSP9vR cGX0Own05s9hFuKeu4fw==; 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 1hDT2d-0002EL-L1; Mon, 08 Apr 2019 12:06:23 +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 1hDSsC-0001mH-LS; Mon, 08 Apr 2019 11:55:39 +0000 X-UUID: 428396b484cf401f9d140abdbba6bc34-20190408 X-UUID: 428396b484cf401f9d140abdbba6bc34-20190408 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 624587781; Mon, 08 Apr 2019 03:55:29 -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, 8 Apr 2019 04:55:28 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 19:55:23 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 8 Apr 2019 19:55:24 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Matthias Brugger Subject: [PATCH 04/14] [media] mtk-mipicsi: get the w/h/bytepwerline for mtk_mipicsi Date: Mon, 8 Apr 2019 19:54:55 +0800 Message-ID: <1554724505-19882-5-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> References: <1554724505-19882-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-20190408_045536_724121_A8A731A0 X-CRM114-Status: GOOD ( 11.65 ) 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: srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch get the w/h/bytepwerline to save in mtk_mipicsi. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index ccf2d18a3e74..f9deff1e5a9f 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -100,6 +100,9 @@ struct mtk_mipicsi_dev { u32 id; int clk_num; struct clk *clk[MIPICSI_CLK]; + u32 width; + u32 height; + u32 bytesperline; }; #define MTK_MIPICSI_BUS_PARAM (V4L2_MBUS_MASTER | \ @@ -111,13 +114,36 @@ struct mtk_mipicsi_dev { V4L2_MBUS_PCLK_SAMPLE_FALLING | \ V4L2_MBUS_DATA_ACTIVE_HIGH) +static u32 get_bytesperline(const u32 fmt, const u32 width) +{ + u32 bytesperline = 0; + + switch (fmt) { + case MEDIA_BUS_FMT_UYVY8_2X8: + case MEDIA_BUS_FMT_VYUY8_2X8: + case MEDIA_BUS_FMT_YUYV8_2X8: + case MEDIA_BUS_FMT_YVYU8_2X8: + bytesperline = width * 2U; + break; + default: + break; + } + + return bytesperline; +} + static int mtk_mipicsi_add_device(struct soc_camera_device *icd) { + struct soc_camera_host *ici = to_soc_camera_host(icd->parent); + struct mtk_mipicsi_dev *mipicsi = ici->priv; struct v4l2_subdev *sd = soc_camera_to_subdev(icd); struct v4l2_subdev_format format = { .which = V4L2_SUBDEV_FORMAT_ACTIVE, }; int ret; + u32 width; + u32 height; + u32 fmt; /* Get width/height info from subdev. Then use them to set register */ ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &format); @@ -126,6 +152,19 @@ static int mtk_mipicsi_add_device(struct soc_camera_device *icd) return ret; } + width = format.format.width; + height = format.format.height; + fmt = format.format.code; + mipicsi->bytesperline = get_bytesperline(fmt, width); + if ((width == 0U) || (height == 0U) || (mipicsi->bytesperline == 0U)) { + dev_err(icd->parent, "invalid sub device width/height/bytesperline %d/%d/%d\n", + width, height, mipicsi->bytesperline); + return -EINVAL; + } + + mipicsi->width = width; + mipicsi->height = height; + /* * If power domain was closed before, it will be open. * Then clock will be open and register will be set From patchwork Mon Apr 8 11:54:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10889355 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 2BBE814DB for ; Mon, 8 Apr 2019 11:56:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0C16F26AE3 for ; Mon, 8 Apr 2019 11:56:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3BEA28643; Mon, 8 Apr 2019 11:56:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5013726AE3 for ; Mon, 8 Apr 2019 11:56:05 +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=Bx5uBsZAeUlFXwYayeMcp1LxcVB9WCR2lkKIAQEJ7L4=; b=ZAW8vsq3IJbQRx +KJ1aRxk9aBHr5Aq3zyOvPumHuW2Ub348kowFkuU++DNK10P+GOahrw681ux/n7c3Mt22yOL9Tl7u 01HD3ZuE6iE3aTfVVf+vwIoRLDWPDsXG1N5805LubdDSkqjmVjP6pxHuFPBZEDpyyC1TFhh/93VhT ZztJhp71oLgLdFCjewacACIMTns9a+kT/Ce7SMKQ6Fp+EXQAolsLddaYpL6umuUkiWzZXtVU1GHLU /htzVuN/xOxecKghlWtL8pX5mDduCaeSyytDbtzZoIs7bgLP4e+Ro/hsEJRWg0C4VmT80W6syZc7X 7DmjOUkGrPVC6WGjX00A==; 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 1hDSsd-0002N9-4v; Mon, 08 Apr 2019 11:56:03 +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 1hDSsB-0001n8-4d; Mon, 08 Apr 2019 11:55:37 +0000 X-UUID: 789fa52cff174a9593f44e6097e988c5-20190408 X-UUID: 789fa52cff174a9593f44e6097e988c5-20190408 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1608976648; Mon, 08 Apr 2019 03:55:31 -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, 8 Apr 2019 04:55:29 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 19:55:24 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 8 Apr 2019 19:55:24 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Matthias Brugger Subject: [PATCH 05/14] [media] mtk-mipicsi: add function to support SerDes for link number Date: Mon, 8 Apr 2019 19:54:56 +0800 Message-ID: <1554724505-19882-6-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> References: <1554724505-19882-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-20190408_045535_181172_1E54DB3E X-CRM114-Status: GOOD ( 12.94 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , 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 f9deff1e5a9f..899cf17df480 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -57,12 +57,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; @@ -93,6 +97,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; @@ -114,6 +119,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; @@ -145,6 +208,7 @@ static int mtk_mipicsi_add_device(struct soc_camera_device *icd) u32 height; u32 fmt; + (void)get_subdev_link(icd, &mipicsi->link, &mipicsi->link_reg_val); /* Get width/height info from subdev. Then use them to set register */ ret = v4l2_subdev_call(sd, pad, get_fmt, NULL, &format); if (ret < 0) { From patchwork Mon Apr 8 11:54:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10889417 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 4391114DB for ; Mon, 8 Apr 2019 11:58:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 259A628643 for ; Mon, 8 Apr 2019 11:58:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1A26428682; Mon, 8 Apr 2019 11:58:42 +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 8926728643 for ; Mon, 8 Apr 2019 11:58:41 +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=I3kQ2Te6kGOOeul0sZYJThf//WYOq7ph5XDwGeP627U=; b=hBTWbU0EIliYF6 tePkCcYOFbzGI9rbUBWJIKdNtMuJM1jvN4wn5lSyCQkf6D0a4jiX+dSGNYatthbWiJ7h7DhTx4lkF cMToaN0Hoy4DnCJ84Goe2BiEeHN9gA7mb8vxmfVKPKlBQ9jBBe0LCUK1hTsB7ijCGY10V6qO6XBbf DeAL6g3pzbvbCqtGhuJj1HWr+9tOjmh6dhR8rmhz3LCpOJVgbvVkFW72PS/rJMm2RvcyoCr6DUk+C ba1FDaeauS9Ci/LeBvdX//cNzX8+3NmtgmQ/vXz/ilYfDgZQqInP59QYoUI+se4SY9ljZpYlHSgi2 Krk/L3bm2fbR5i2wgnZg==; 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 1hDSv9-0005iS-No; Mon, 08 Apr 2019 11:58:39 +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 1hDSsR-0001mJ-Jy; Mon, 08 Apr 2019 11:55:58 +0000 X-UUID: 60f1fbd443774b47922de164892241c7-20190408 X-UUID: 60f1fbd443774b47922de164892241c7-20190408 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 436642403; Mon, 08 Apr 2019 03:55:33 -0800 Received: from MTKMBS01N2.mediatek.inc (172.21.101.79) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 04:55:32 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 19:55:25 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 8 Apr 2019 19:55:25 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Matthias Brugger Subject: [PATCH 06/14] [media] mtk-mipicsi: add mipicsi reg setting for mt2712 Date: Mon, 8 Apr 2019 19:54:57 +0800 Message-ID: <1554724505-19882-7-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> References: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: A634257497D25F324E6F2FAC43FBA1C8C31E6314247CDC55D3E0561011F9BDEE2000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190408_045551_908294_34C178B3 X-CRM114-Status: GOOD ( 12.62 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add mipicsi register setting to HW for mt2712 Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 189 ++++++++++++++++++ 1 file changed, 189 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 899cf17df480..c2f75d9b64b8 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -65,6 +65,51 @@ #define MAX_BUFFER_NUM 32U #define VID_LIMIT_BYTES (100U * 1024U * 1024U) +#define MIPI_RX_ANA00_CSI 0x00 +#define MIPI_RX_ANA04_CSI 0x04 +#define MIPI_RX_ANA08_CSI 0x08 +#define MIPI_RX_ANA0C_CSI 0x0c +#define MIPI_RX_ANA10_CSI 0x10 +#define MIPI_RX_ANA20_CSI 0x20 +#define MIPI_RX_ANA24_CSI 0x24 +#define MIPI_RX_ANA4C_CSI 0x4c +#define MIPI_RX_ANA50_CSI 0x50 + +#define SENINF_CTRL 0x00 + +#define SENINF_NCSI2_CAL_24 0x24 +#define SENINF_NCSI2_CAL_38 0x38 +#define SENINF_NCSI2_CAL_3C 0x3C +#define SENINF_NCSI2_CTL 0xA0 +#define SENINF_NCSI2_LNRD_TIMING 0xA8 +#define SENINF_NCSI2_INT_EN 0xB0 +#define SENINF_NCSI2_INT_STATUS 0xB4 +#define SENINF_NCSI2_DBG_SEL 0xB8 +#define SENINF_NCSI2_HSRX_DBG 0xD8 +#define SENINF_NCSI2_DI 0xDC +#define SENINF_NCSI2_DI_CTRL 0xE4 + +#define SENINF_TOP_CTRL 0x00 +#define SENINF_TOP_CMODEL_PAR 0x04 +#define SENINF_TOP_MUX 0x08 + +#define SENINF_MUX_CTRL 0x00 + +#define CAMSV_MODULE_EN 0x10 +#define CAMSV_FMT_SEL 0x14 +#define CAMSV_INT_EN 0x18 +#define CAMSV_CLK_EN 0x30 + +#define CAMSV_TG_SEN_MODE 0x500 +#define CAMSV_TG_SEN_GRAB_PXL 0x508 +#define CAMSV_TG_SEN_GRAB_LIN 0x50C +#define CAMSV_TG_PATH_CFG 0x510 + +#define IMGO_XSIZE 0x230 +#define IMGO_YSIZE 0x234 +#define IMGO_STRIDE 0x238 +#define DMA_FRAME_HEADER_EN 0xE00 + #define SerDes_support 1 /* buffer for one video frame */ @@ -593,6 +638,149 @@ static struct soc_camera_host_ops mtk_soc_camera_host_ops = { .set_bus_param = mtk_mipicsi_set_bus_param, }; +static void mtk_mipicsi_ana_init(void __iomem *base) +{ + writel(0xFEFBEFBEU & readl(base + MIPI_RX_ANA4C_CSI), + base + MIPI_RX_ANA4C_CSI); + writel(0xFEFBEFBEU & readl(base + MIPI_RX_ANA50_CSI), + base + MIPI_RX_ANA50_CSI); + + /* clock lane and lane0-lane3 input select */ + writel(8UL | readl(base + MIPI_RX_ANA00_CSI), + base + MIPI_RX_ANA00_CSI); + writel(8UL | readl(base + MIPI_RX_ANA04_CSI), + base + MIPI_RX_ANA04_CSI); + writel(8UL | readl(base + MIPI_RX_ANA08_CSI), + base + MIPI_RX_ANA08_CSI); + writel(8UL | readl(base + MIPI_RX_ANA0C_CSI), + base + MIPI_RX_ANA0C_CSI); + writel(8UL | readl(base + MIPI_RX_ANA10_CSI), + base + MIPI_RX_ANA10_CSI); + + /* BG chopper clock and CSI BG enable */ + writel(11UL | readl(base + MIPI_RX_ANA24_CSI), + base + MIPI_RX_ANA24_CSI); + mdelay(1); + + /* LDO core bias enable */ + writel(0xFF030003U | readl(base + MIPI_RX_ANA20_CSI), + base + MIPI_RX_ANA20_CSI); + mdelay(1); +} + +static void mtk_mipicsi_seninf_ctrl_init(void __iomem *base) +{ + /*seninf enable. select NCSI2 as seninif input source */ + writel(0x8001U, base + SENINF_CTRL); +} + +static void mtk_mipicsi_seninf_init(void __iomem *base) +{ + writel(1U, base + SENINF_NCSI2_CAL_38); + writel(0x00051545U, base + SENINF_NCSI2_CAL_3C); + writel(5U, base + SENINF_NCSI2_CAL_38); + mdelay(1); + writel(4U, base + SENINF_NCSI2_CAL_38); + writel(0U, base + SENINF_NCSI2_CAL_3C); + writel(0x11U, base + SENINF_NCSI2_DBG_SEL); + writel(0x189617FU, base + SENINF_NCSI2_CTL); + writel(~(1UL << 27) & readl(base + SENINF_NCSI2_CTL), + base + SENINF_NCSI2_CTL); + writel((1UL << 27) | readl(base + SENINF_NCSI2_CTL), + base + SENINF_NCSI2_CTL); + writel(0x2800U, base + SENINF_NCSI2_LNRD_TIMING); + writel(0x7FFFU, base + SENINF_NCSI2_INT_STATUS); + writel(0x7FCFFFFEU, base + SENINF_NCSI2_INT_EN); + writel(0xE4000000U, base + SENINF_NCSI2_CAL_24); + writel(0xFFFFFF00U & readl(base + SENINF_NCSI2_DBG_SEL), + base + SENINF_NCSI2_DBG_SEL); + writel(0xFFFFFF45U | readl(base + SENINF_NCSI2_DBG_SEL), + base + SENINF_NCSI2_DBG_SEL); + writel(0xFFFFFFEFU & readl(base + SENINF_NCSI2_HSRX_DBG), + base + SENINF_NCSI2_HSRX_DBG); + writel(0x01010101U, base + SENINF_NCSI2_DI_CTRL); + writel(0x03020100U, base + SENINF_NCSI2_DI); + writel(0x10, base + SENINF_NCSI2_DBG_SEL); +} + +static void mtk_mipicsi_seninf_top_init(struct regmap *regmap) +{ + (void)regmap_write(regmap, SENINF_TOP_CTRL, 0x00010C00U); + (void)regmap_write(regmap, SENINF_TOP_CMODEL_PAR, 0x00079871); + (void)regmap_write(regmap, SENINF_TOP_MUX, 0x11110000); +} + +static void mtk_mipicsi_seninf_mux_init(void __iomem *base, unsigned int ch) +{ + unsigned int mux_ctrl_val = (((0x9EFF8U + ch) << 12U) | 0x180U); + + /* select seninf_mux1-4 as input for NCSI2 VC0-3*/ + writel(mux_ctrl_val, base + SENINF_MUX_CTRL); +} + +static void mtk_mipicsi_camsv_csr_init(void __iomem *base) +{ + /* double buffer enable. IMGO enable. PAK sel. TG enable */ + writel(0x40000019U, base + CAMSV_MODULE_EN); + /* IMGO DP, PAK DP and TG clk enable */ + writel(0x00008005U, base + CAMSV_CLK_EN); + /* 0: raw8, 1:raw10, 2:raw12, 3:YUV422, 4:raw14, 7:JPEG */ + writel(0x00000003U, base + CAMSV_FMT_SEL); + /* write clear enable. pass1 down interrupt enable */ + writel(0x80000400U, base + CAMSV_INT_EN); +} + +static void mtk_mipicsi_camsv_tg_init(void __iomem *base, u32 b, u32 h) +{ + /* bit[30:16] grab end pixel clock number. + * bit[14:0] grab start pixel clock number + */ + writel(b << 16U, base + CAMSV_TG_SEN_GRAB_PXL); + /* bit[29:16] end line number. bit[13:0] start line number */ + writel(h << 16U, base + CAMSV_TG_SEN_GRAB_LIN); + /* YUV sensor unsigned to signed enable */ + writel(0x1000U, base + CAMSV_TG_PATH_CFG); + /* cmos enable YUV422 mode */ + writel(3U, base + CAMSV_TG_SEN_MODE); +} + +static void mtk_mipicsi_camsv_dma_init(void __iomem *base, u32 b, u32 h) +{ + /* enable SW format setting. YUV format. 16bit */ + writel(0x01810000U | b, base + IMGO_STRIDE); + /* b -1 bytes per line to write */ + writel(b - 1U, base + IMGO_XSIZE); + /* w - 1 lines to write */ + writel(h - 1U, base + IMGO_YSIZE); + /* disable frame header function */ + writel(0U, base + DMA_FRAME_HEADER_EN); +} + +static void mtk_mipicsi_camsv_init(void __iomem *base, u32 b, u32 h) +{ + mtk_mipicsi_camsv_csr_init(base); + mtk_mipicsi_camsv_tg_init(base, b, h); + mtk_mipicsi_camsv_dma_init(base, b, h); +} + +static void mtk_mipicsi_reg_init(struct mtk_mipicsi_dev *mipicsi) +{ + unsigned int i; + + mtk_mipicsi_ana_init(mipicsi->ana); + mtk_mipicsi_seninf_ctrl_init(mipicsi->seninf_ctrl); + mtk_mipicsi_seninf_init(mipicsi->seninf); + mtk_mipicsi_seninf_top_init(mipicsi->seninf_top); + + for (i = 0U; i < mipicsi->camsv_num; ++i) { + u32 b = mipicsi->bytesperline; + u32 h = mipicsi->height; + + mtk_mipicsi_seninf_mux_init(mipicsi->seninf_mux[i], i); + mtk_mipicsi_camsv_init(mipicsi->camsv[i], b, h); + } +} + static int mtk_mipicsi_pm_suspend(struct device *dev) { struct soc_camera_host *ici = to_soc_camera_host(dev); @@ -655,6 +843,7 @@ static int mtk_mipicsi_pm_resume(struct device *dev) for (i = 0; i < mipicsi->clk_num; ++i) (void)clk_prepare_enable(mipicsi->clk[i]); + mtk_mipicsi_reg_init(mipicsi); return ret; } From patchwork Mon Apr 8 11:54:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10889381 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 E41B714DB for ; Mon, 8 Apr 2019 11:56:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C832D271CB for ; Mon, 8 Apr 2019 11:56:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BCC382867C; Mon, 8 Apr 2019 11:56:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 742DB271CB for ; Mon, 8 Apr 2019 11:56:45 +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=vhje78UOsOnyIcuEZIeJEFJMtvwpw2bevTeAqWxeYVE=; b=DGWON9zyxLouvM ODXtp62syK2zTP1XTbm9+RHOTpTOL8na3lZvNEnUbsuZpcG5LplDYHiy3wcr/EpsfWuYf3os6x4pn E6XMCJF7o4SnmkdxmWQyaTjmMbLlFYgfdTsIS6vOAbiqHAe13VAX/VqTMMV7gZm9wpb8691UVJlqu B4v2TbT1G5EWJAsEL+mK2lC84lYXjzXs0+PIPkn4gWrLkD4qjZg19awVeCnYFBWRkiqKf3arZp1hg g1mpbyhJ2zRsAwpWz+ugLeCcKvb8qq1mG2eA1T59ORffs4Te9UYuVJ+8K43n3Se1Lfc9Q9JTabwNW biAUIEuZRbOgGr/i8RAg==; 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 1hDStI-0003GS-8b; Mon, 08 Apr 2019 11:56:44 +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 1hDSsD-0001n8-JO; Mon, 08 Apr 2019 11:55:39 +0000 X-UUID: b6ce870694d345a182afb3e011e51cf9-20190408 X-UUID: b6ce870694d345a182afb3e011e51cf9-20190408 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1726993164; Mon, 08 Apr 2019 03:55:31 -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, 8 Apr 2019 04:55:30 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 19:55:26 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 8 Apr 2019 19:55:26 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Matthias Brugger Subject: [PATCH 07/14] [media] mtk-mipicsi: enable/disable ana clk Date: Mon, 8 Apr 2019 19:54:58 +0800 Message-ID: <1554724505-19882-8-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> References: <1554724505-19882-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-20190408_045537_654803_464A6116 X-CRM114-Status: UNSURE ( 9.56 ) X-CRM114-Notice: Please train this message. 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: srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch enable/disable ana clk when power on/off Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index c2f75d9b64b8..99991f698edf 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -164,6 +164,41 @@ struct mtk_mipicsi_dev { V4L2_MBUS_PCLK_SAMPLE_FALLING | \ V4L2_MBUS_DATA_ACTIVE_HIGH) +static void mtk_mipicsi_ana_clk_enable(void __iomem *base, bool enable) +{ + if (enable) { + writel(1UL | readl(base + MIPI_RX_ANA00_CSI), + base + MIPI_RX_ANA00_CSI); + writel(1UL | readl(base + MIPI_RX_ANA04_CSI), + base + MIPI_RX_ANA04_CSI); + writel(1UL | readl(base + MIPI_RX_ANA08_CSI), + base + MIPI_RX_ANA08_CSI); + writel(1UL | readl(base + MIPI_RX_ANA0C_CSI), + base + MIPI_RX_ANA0C_CSI); + writel(1UL | readl(base + MIPI_RX_ANA10_CSI), + base + MIPI_RX_ANA10_CSI); + writel(1UL | readl(base + MIPI_RX_ANA20_CSI), + base + MIPI_RX_ANA20_CSI); + writel(1UL | readl(base + MIPI_RX_ANA24_CSI), + base + MIPI_RX_ANA24_CSI); + } else { + writel(~1UL & readl(base + MIPI_RX_ANA00_CSI), + base + MIPI_RX_ANA00_CSI); + writel(~1UL & readl(base + MIPI_RX_ANA04_CSI), + base + MIPI_RX_ANA04_CSI); + writel(~1UL & readl(base + MIPI_RX_ANA08_CSI), + base + MIPI_RX_ANA08_CSI); + writel(~1UL & readl(base + MIPI_RX_ANA0C_CSI), + base + MIPI_RX_ANA0C_CSI); + writel(~1UL & readl(base + MIPI_RX_ANA10_CSI), + base + MIPI_RX_ANA10_CSI); + writel(~1UL & readl(base + MIPI_RX_ANA20_CSI), + base + MIPI_RX_ANA20_CSI); + writel(~1UL & readl(base + MIPI_RX_ANA24_CSI), + base + MIPI_RX_ANA24_CSI); + } +} + static int get_subdev_register(const struct soc_camera_device *icd, struct v4l2_dbg_register *reg) { @@ -802,6 +837,8 @@ static int mtk_mipicsi_pm_suspend(struct device *dev) for (i = 0; i < mipicsi->clk_num; ++i) clk_disable_unprepare(mipicsi->clk[i]); + mtk_mipicsi_ana_clk_enable(mipicsi->ana, false); + if (mipicsi->larb_pdev != NULL) mtk_smi_larb_put(mipicsi->larb_pdev); @@ -839,6 +876,8 @@ static int mtk_mipicsi_pm_resume(struct device *dev) return ret; } + mtk_mipicsi_ana_clk_enable(mipicsi->ana, true); + /* enable digtal clock */ for (i = 0; i < mipicsi->clk_num; ++i) (void)clk_prepare_enable(mipicsi->clk[i]); From patchwork Mon Apr 8 11:54:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10889425 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 BC387139A for ; Mon, 8 Apr 2019 12:06:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A0DFE283B0 for ; Mon, 8 Apr 2019 12:06:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9592D28426; Mon, 8 Apr 2019 12:06:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 492E1283B0 for ; Mon, 8 Apr 2019 12:06:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=48PdU5OJPRJ20jIFISFAgEwaUSAdGLZEn3zfUwbVE94=; b=smzq0FSmpU+mCc 2oyCdce3I3Kvp+NIZn1YCuNIAGczQBghpQMLcntBqZo4Rt3h8W8omSDxQuTNM4y/hyzekvjYeerLU tQBYF+M6vJ+GSplXkedCjxLd3n+7V7EaPlEy4i5nvfCf+T5trEwcmTS4H5Y1ZH3VXjzWfUwvncKhR bVdX6Z/BzKNn6j7jesmp1tanBeQOgXSojXjeaROOBz5mz6K3ifP8SDukIUiRohhcsw5r5NioNF4nl lCQos+kBd0lJ6/NyaVc75gnsdC6u2dlYIcyHJ9rnu7WFyElrbtsZHWhePdc1L9th624Nv4s9P3PAR A7htBSZo20hhinZw4/Vw==; 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 1hDT2f-0002IP-VE; Mon, 08 Apr 2019 12:06:25 +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 1hDSsN-0001mJ-7f; Mon, 08 Apr 2019 11:55:51 +0000 X-UUID: 46ddfa127be246ccac00e7740ae8e21e-20190408 X-UUID: 46ddfa127be246ccac00e7740ae8e21e-20190408 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 253267235; Mon, 08 Apr 2019 03:55:33 -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, 8 Apr 2019 04:55:31 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 19:55:27 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 8 Apr 2019 19:55:27 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Matthias Brugger Subject: [PATCH 08/14] [media] mtk-mipicsi: enable/disable cmos for mt2712 Date: Mon, 8 Apr 2019 19:54:59 +0800 Message-ID: <1554724505-19882-9-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> References: <1554724505-19882-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-20190408_045547_721705_5728553E X-CRM114-Status: GOOD ( 10.10 ) 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: srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch enable/disable cmos setting for mt2712 when vb2 start/stop streaming. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 99991f698edf..116fd2bfaaab 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -98,9 +98,11 @@ #define CAMSV_MODULE_EN 0x10 #define CAMSV_FMT_SEL 0x14 #define CAMSV_INT_EN 0x18 +#define CAMSV_SW_CTL 0x20 #define CAMSV_CLK_EN 0x30 #define CAMSV_TG_SEN_MODE 0x500 +#define CAMSV_TG_VF_CON 0x504 #define CAMSV_TG_SEN_GRAB_PXL 0x508 #define CAMSV_TG_SEN_GRAB_LIN 0x50C #define CAMSV_TG_PATH_CFG 0x510 @@ -537,9 +539,25 @@ static int mtk_mipicsi_vb2_start_streaming(struct vb2_queue *vq, struct soc_camera_device *icd = soc_camera_from_vb2q(vq); struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct mtk_mipicsi_dev *mipicsi = ici->priv; + unsigned int index = 0; + void __iomem *base = NULL; icd->vdev->queue = vq; + for (index = 0U; index < MTK_CAMDMA_MAX_NUM; ++index) + if (((mipicsi->link_reg_val >> index) & 0x01U) == 0x01U && + !mipicsi->is_enable_irq[index]) { + enable_irq(mipicsi->irq[index]); + mipicsi->is_enable_irq[index] = true; + + /*enable cmos_en and vf_en*/ + base = mipicsi->camsv[index]; + writel(0x00000001U | readl(base + CAMSV_TG_SEN_MODE), + base + CAMSV_TG_SEN_MODE); + writel(0x00000001U | readl(base + CAMSV_TG_VF_CON), + base + CAMSV_TG_VF_CON); + } + mipicsi->streamon = true; return 0; } @@ -549,7 +567,29 @@ static void mtk_mipicsi_vb2_stop_streaming(struct vb2_queue *vq) struct mtk_mipicsi_dev *mipicsi = vb2_get_drv_priv(vq); struct mtk_mipicsi_buf *buf = NULL; struct mtk_mipicsi_buf *tmp = NULL; + unsigned int i = 0U; unsigned int index = 0; + void __iomem *base = NULL; + + for (i = 0U; i < MTK_CAMDMA_MAX_NUM; ++i) + if (((mipicsi->link_reg_val >> i) & 0x01U) == 0x01U) { + /*disable cmos_en and vf_en*/ + base = mipicsi->camsv[i]; + writel(readl(base + CAMSV_TG_SEN_MODE) & 0xFFFFFFFEU, + base + CAMSV_TG_SEN_MODE); + writel(readl(base + CAMSV_TG_VF_CON) & 0xFFFFFFFEU, + base + CAMSV_TG_VF_CON); + /*camsv reset*/ + base = mipicsi->camsv[i]; + writel(0x00000004U | readl(base + CAMSV_SW_CTL), + base + CAMSV_SW_CTL); + writel(readl(base + CAMSV_SW_CTL) & 0xFFFFFFFBU, + base + CAMSV_SW_CTL); + disable_irq(mipicsi->irq[i]); + mipicsi->is_enable_irq[i] = false; + mipicsi->frame_cnt[i] = 0UL; + mipicsi->irq_status[i] = false; + } spin_lock(&mipicsi->queue_lock); while (list_empty(&(mipicsi->fb_list)) == 0) { From patchwork Mon Apr 8 11:55:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10889427 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 F06C81800 for ; Mon, 8 Apr 2019 12:06:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D04F5283B0 for ; Mon, 8 Apr 2019 12:06:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CE870283C9; Mon, 8 Apr 2019 12:06:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6ABB5283C3 for ; Mon, 8 Apr 2019 12:06:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Ljhl8PBjJDaliCZrzhuvkrCJxXjWirMA9vzNEUS2ZU4=; b=hjqzHaI47FDlC3 Aj8r8dlY2X8P2eZRgpex/lxODZcpZTeAvNoXvc+pR3amV7zPgCcbxQgVHuC+JcFsavM5V4CDdBbOC rxJTryve3GD+XxeEKlt1nbGSn5xCIUJ5MX4heMt3PI61DmBmfNQk2vBI9WUSx86R7pZDVakmWyEIs H+f7ulGjwiQlLVbQSnJDrPzlKXySIe1ogyK6w7k85Kq3CpWIwB8Kba3DzKPoebcuFGAZFZY+Xc6dQ zxuKw93ifG9k8b1jebfVGMxEbH3UAxb6KEmNYgTzEjGz2xHnlqSa0RhYL7b+4VIZvetJNG4aEuGjP m47Zf5MA2/FmzXTHrhUQ==; 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 1hDT2f-0002HW-OF; Mon, 08 Apr 2019 12:06:25 +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 1hDSsF-0001n8-QS; Mon, 08 Apr 2019 11:55:48 +0000 X-UUID: 8acb50f22adc4a8ebde2f96b76c2baa0-20190408 X-UUID: 8acb50f22adc4a8ebde2f96b76c2baa0-20190408 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 657013439; Mon, 08 Apr 2019 03:55:31 -0800 Received: from mtkmbs03n1.mediatek.inc (172.21.101.181) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 04:55:29 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs03n1.mediatek.inc (172.21.101.181) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 19:55:28 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 8 Apr 2019 19:55:28 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Matthias Brugger Subject: [PATCH 09/14] [media] mtk-mipicsi: add ISR for writing the data to buffer Date: Mon, 8 Apr 2019 19:55:00 +0800 Message-ID: <1554724505-19882-10-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> References: <1554724505-19882-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-20190408_045540_340741_4FBB086A X-CRM114-Status: GOOD ( 15.12 ) 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: srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add ISR for writing the data to buffer When mipicsi HW complete to write the data in buffer, the interrupt woulb be trigger. So, the ISR need to clear interrupt status for next interrupt. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 116fd2bfaaab..c8ce561dcc58 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -98,6 +99,8 @@ #define CAMSV_MODULE_EN 0x10 #define CAMSV_FMT_SEL 0x14 #define CAMSV_INT_EN 0x18 +#define CAMSV_INT_STATUS 0x1C +#define PASS1_DONE_STATUS 10 #define CAMSV_SW_CTL 0x20 #define CAMSV_CLK_EN 0x30 @@ -128,6 +131,8 @@ struct mtk_mipicsi_dev { unsigned int camsv_num; struct v4l2_device v4l2_dev; struct device *larb_pdev; + unsigned int irq[MTK_CAMDMA_MAX_NUM]; + bool irq_status[MTK_CAMDMA_MAX_NUM]; void __iomem *ana; void __iomem *seninf_ctrl; void __iomem *seninf; @@ -141,6 +146,7 @@ struct mtk_mipicsi_dev { spinlock_t lock; spinlock_t queue_lock; struct mtk_mipicsi_buf cam_buf[MAX_BUFFER_NUM]; + bool is_enable_irq[MTK_CAMDMA_MAX_NUM]; bool streamon; unsigned long frame_cnt[MTK_CAMDMA_MAX_NUM]; unsigned int link; @@ -940,9 +946,98 @@ static const struct dev_pm_ops mtk_mipicsi_pm = { mtk_mipicsi_pm_resume, NULL) }; +static int get_irq_channel(struct mtk_mipicsi_dev *mipicsi) +{ + int ch; + u32 int_reg_val; + + for (ch = 0; ch < mipicsi->camsv_num; ++ch) { + int_reg_val = readl(mipicsi->camsv[ch] + CAMSV_INT_STATUS); + if ((int_reg_val & (1UL << PASS1_DONE_STATUS)) != 0UL) + return ch; + } + + return -1; +} + +static void mtk_mipicsi_irq_buf_process(struct mtk_mipicsi_dev *mipicsi) +{ + unsigned int i = 0U; + struct mtk_mipicsi_buf *new_cam_buf = NULL; + struct mtk_mipicsi_buf *tmp = NULL; + unsigned int index = 0U; + unsigned int next = 0U; + + for (i = 0U; i < MTK_CAMDMA_MAX_NUM; ++i) + mipicsi->irq_status[i] = false; + + i = 0; + + /* only one buffer left */ + if ((&(mipicsi->fb_list))->next->next == &(mipicsi->fb_list)) + return; + + /*for each fb_lst 2 times to get the top 2 buffer.*/ + list_for_each_entry_safe(new_cam_buf, tmp, + &(mipicsi->fb_list), queue) { + if (i == 0U) { + index = new_cam_buf->vb->index; + } else { + next = new_cam_buf->vb->index; + break; + } + ++i; + } + + /* + * fb_list has one more buffer. Free the first buffer to user + * and fill the second buffer to HW. + */ + vb2_buffer_done(mipicsi->cam_buf[index].vb, + VB2_BUF_STATE_DONE); + ++(mipicsi->dequeue_cnt); + + list_del_init(&(mipicsi->cam_buf[index].queue)); +} + +static irqreturn_t mtk_mipicsi_isr(int irq, void *data) +{ + + struct mtk_mipicsi_dev *mipicsi = data; + unsigned long flags = 0; + int isr_ch; + u8 irq_cnt = 0, i = 0; + + spin_lock_irqsave(&mipicsi->lock, flags); + + isr_ch = get_irq_channel(mipicsi); + if (isr_ch < 0) { + spin_unlock_irqrestore(&mipicsi->lock, flags); + return IRQ_HANDLED; + } + + /* clear interrupt */ + writel(1UL << PASS1_DONE_STATUS, + mipicsi->camsv[isr_ch] + CAMSV_INT_STATUS); + mipicsi->irq_status[isr_ch] = true; + ++(mipicsi->frame_cnt[isr_ch]); + for (i = 0U; i < MTK_CAMDMA_MAX_NUM; ++i) { + if (mipicsi->irq_status[i]) + ++irq_cnt; + } + + if (irq_cnt == mipicsi->link) + mtk_mipicsi_irq_buf_process(mipicsi); + spin_unlock_irqrestore(&mipicsi->lock, flags); + + return IRQ_HANDLED; +} + static int seninf_mux_camsv_node_parse(struct mtk_mipicsi_dev *mipicsi, int index) { + int ret; + int irq; struct clk *clk = NULL; struct device *dev = NULL; struct resource *res = NULL; @@ -980,6 +1075,23 @@ static int seninf_mux_camsv_node_parse(struct mtk_mipicsi_dev *mipicsi, } mipicsi->clk[index] = clk; + irq = of_irq_get(np, 0); + if (irq <= 0) { + dev_err(dev, "get irq fail in %s node\n", np->full_name); + return -ENODEV; + } + mipicsi->irq[index] = irq; + + ret = devm_request_irq(dev, irq, + mtk_mipicsi_isr, 0, + mipicsi->drv_name, mipicsi); + if (ret != 0) { + dev_err(dev, "%s irq register failed\n", np->full_name); + return -ENODEV; + } + disable_irq(mipicsi->irq[index]); + mipicsi->irq_status[index] = false; + res = platform_get_resource(camdma_pdev, IORESOURCE_MEM, 0); if (res == NULL) { dev_err(dev, "get seninf_mux memory failed in %s node\n", From patchwork Mon Apr 8 11:55:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10889405 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 DC4BF14DB for ; Mon, 8 Apr 2019 11:57:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BCAC428643 for ; Mon, 8 Apr 2019 11:57:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id AE7AA28682; Mon, 8 Apr 2019 11:57: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 5D77C28643 for ; Mon, 8 Apr 2019 11:57:49 +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=LhHHsykEPQCwKnbx9LmnLomrEPSoy7u3I+xsozwnfM4=; b=BoLP9iCF7RIsAT 4Ww4r77ZXKnh0TKVaitrDw5bGXKyOHGCeqD81INdiuimBdvfECnr2eGaJZMj2tbOWwRyEgAxMGicf LxJruCytQ6lhg5usvf6TqhCN+f8mbo2Tt7Q1fDg/4bBYLV450jWV7OvAtUWft1dp+eCVOeRWQX4Tf 0MiHpzQr0UNd2cm4FMIVlLkn+Nno5zOwkDnbpWrzsK5UuvX3QyvH9B1YEtUhIY3YgS2lYT/iBMlxD 4NF4nsyj6Zf9kQ/fnWbNhUfnHckRCFo/pVrhV56BRysrB+CSXGTSktC+brhcnlB2EMcq5wxsq/gmP aQjElpVL6qd+cjhrJSiw==; 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 1hDSuJ-0004al-P0; Mon, 08 Apr 2019 11:57:47 +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 1hDSsM-0001m9-Er; Mon, 08 Apr 2019 11:55:51 +0000 X-UUID: 28321b083c534d4e94fa3702e9506ca4-20190408 X-UUID: 28321b083c534d4e94fa3702e9506ca4-20190408 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 328513976; Mon, 08 Apr 2019 03:55:30 -0800 Received: from mtkmbs03n2.mediatek.inc (172.21.101.182) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 04:55:30 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs03n2.mediatek.inc (172.21.101.182) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 19:55:28 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 8 Apr 2019 19:55:28 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Matthias Brugger Subject: [PATCH 10/14] [media] mtk-mipicsi: set the output address in HW reg Date: Mon, 8 Apr 2019 19:55:01 +0800 Message-ID: <1554724505-19882-11-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> References: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: A1A7B45C457C44D7CE9343134444973778A0CEE0F2DE69E1280E4C6A75BE56652000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190408_045547_071797_94AF449B X-CRM114-Status: GOOD ( 11.56 ) 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: srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch set the output address in HW reg when buffer queue and ISR. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index c8ce561dcc58..2098e3e30de6 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -110,6 +110,7 @@ #define CAMSV_TG_SEN_GRAB_LIN 0x50C #define CAMSV_TG_PATH_CFG 0x510 +#define IMGO_BASE_ADDR 0x220 #define IMGO_XSIZE 0x230 #define IMGO_YSIZE 0x234 #define IMGO_STRIDE 0x238 @@ -522,12 +523,22 @@ static int mtk_mipicsi_vb2_prepare(struct vb2_buffer *vb) return 0; } +static void mtk_mipicsi_fill_buffer(void __iomem *base, dma_addr_t dma_handle) +{ + writel(dma_handle, base + IMGO_BASE_ADDR); +} + static void mtk_mipicsi_vb2_queue(struct vb2_buffer *vb) { struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue); struct soc_camera_host *ici = to_soc_camera_host(icd->parent); struct mtk_mipicsi_dev *mipicsi = ici->priv; + unsigned int i = 0; + u64 offset = 0; + u8 link_index = 0U; char *va = NULL; + u32 bytesperline = mipicsi->bytesperline; + u32 height = mipicsi->height; spin_lock(&mipicsi->queue_lock); list_add_tail(&(mipicsi->cam_buf[vb->index].queue), @@ -536,6 +547,20 @@ static void mtk_mipicsi_vb2_queue(struct vb2_buffer *vb) va = vb2_plane_vaddr(vb, 0); + for (i = 0U; (mipicsi->enqueue_cnt == 0UL) && (i < MTK_CAMDMA_MAX_NUM); + ++i) + if (((mipicsi->link_reg_val >> i) & 0x01U) == 0x01U) { + offset = (u64)link_index * bytesperline * height; + + spin_lock(&mipicsi->lock); + mtk_mipicsi_fill_buffer(mipicsi->camsv[i], + mipicsi->cam_buf[vb->index].vb_dma_addr_phy + + offset); + spin_unlock(&mipicsi->lock); + + link_index++; + } + ++(mipicsi->enqueue_cnt); } @@ -967,6 +992,10 @@ static void mtk_mipicsi_irq_buf_process(struct mtk_mipicsi_dev *mipicsi) struct mtk_mipicsi_buf *tmp = NULL; unsigned int index = 0U; unsigned int next = 0U; + u64 offset = 0ULL; + u8 link_index = 0U; + void __iomem *base = NULL; + dma_addr_t pa; for (i = 0U; i < MTK_CAMDMA_MAX_NUM; ++i) mipicsi->irq_status[i] = false; @@ -989,6 +1018,16 @@ static void mtk_mipicsi_irq_buf_process(struct mtk_mipicsi_dev *mipicsi) ++i; } + for (i = 0U; i < MTK_CAMDMA_MAX_NUM; ++i) { + if (((mipicsi->link_reg_val >> i) & 0x01U) == 0x01U) { + offset = (u64)link_index * + mipicsi->bytesperline * mipicsi->height; + base = mipicsi->camsv[i]; + pa = mipicsi->cam_buf[next].vb_dma_addr_phy; + mtk_mipicsi_fill_buffer(base, pa + offset); + link_index++; + } + } /* * fb_list has one more buffer. Free the first buffer to user * and fill the second buffer to HW. From patchwork Mon Apr 8 11:55:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10889397 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 16A2214DB for ; Mon, 8 Apr 2019 11:57:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED10E26AE3 for ; Mon, 8 Apr 2019 11:57:22 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E0A4728643; Mon, 8 Apr 2019 11:57:22 +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 754FF26AE3 for ; Mon, 8 Apr 2019 11:57:22 +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=DkxzPUjyrHZsgpfTuh50iib/FdJfk+SFPrMVIpkIAN0=; b=RicDLVxpoRfV0G 3m6ShPeDe/rBVbNO8RzPsAWXREarmi9i5LVbFUA6tE/0t4uF7rK7pGpJzhrRdM/I7QK2CrJTIbcXT p8Mgq8/Qttbb0iYj+3A6/7iN7BlnI8QhJsDx0w0Xr+nrZHadET8JYJeDOQ8AritKetjDs9XsCN1fP nmWyDtpMrWl/3H6MSGEHD1lE19qRnWc/JUOYfEQ/inwMg1QW0NdfCaceEdljtxl9+TLqKmG7jBees F/i6gKV3qnIjgutURvozXcvRHmaPZ3d6Yu5ZPFeJgn1fLq605k6si7QcsV5p0letAVjkZrnZXfchW 3Fowaxi3GYU+8+pM4gOw==; 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 1hDSts-00041W-UD; Mon, 08 Apr 2019 11:57:20 +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 1hDSsG-0001m9-Gu; Mon, 08 Apr 2019 11:55:46 +0000 X-UUID: f6047089549e4be186f8ca2f9f98b3ab-20190408 X-UUID: f6047089549e4be186f8ca2f9f98b3ab-20190408 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 2043669709; Mon, 08 Apr 2019 03:55:31 -0800 Received: from mtkmbs03n1.mediatek.inc (172.21.101.181) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 04:55:30 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs03n1.mediatek.inc (172.21.101.181) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 19:55:29 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 8 Apr 2019 19:55:29 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Matthias Brugger Subject: [PATCH 11/14] [media] mtk-mipicsi: add function to get the format Date: Mon, 8 Apr 2019 19:55:02 +0800 Message-ID: <1554724505-19882-12-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> References: <1554724505-19882-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-20190408_045541_041855_A1E89657 X-CRM114-Status: GOOD ( 14.20 ) 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: srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add function to get the format This function can get the subdev format and host format. Calculate the number of format which intersection of subdev and host. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 148 ++++++++++++++++++ 1 file changed, 148 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 2098e3e30de6..9361cc4c77ac 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -164,6 +164,50 @@ struct mtk_mipicsi_dev { u32 bytesperline; }; +static const struct soc_mbus_lookup mtk_mipicsi_formats[] = { +{ + .code = MEDIA_BUS_FMT_YUYV8_2X8, + .fmt = { + .fourcc = V4L2_PIX_FMT_YUYV, + .name = "YUYV", + .bits_per_sample = 8, + .packing = SOC_MBUS_PACKING_2X8_PADHI, + .order = SOC_MBUS_ORDER_LE, + .layout = SOC_MBUS_LAYOUT_PACKED, + }, +}, { + .code = MEDIA_BUS_FMT_YVYU8_2X8, + .fmt = { + .fourcc = V4L2_PIX_FMT_YVYU, + .name = "YVYU", + .bits_per_sample = 8, + .packing = SOC_MBUS_PACKING_2X8_PADHI, + .order = SOC_MBUS_ORDER_LE, + .layout = SOC_MBUS_LAYOUT_PACKED, + }, +}, { + .code = MEDIA_BUS_FMT_UYVY8_2X8, + .fmt = { + .fourcc = V4L2_PIX_FMT_UYVY, + .name = "UYVY", + .bits_per_sample = 8, + .packing = SOC_MBUS_PACKING_2X8_PADHI, + .order = SOC_MBUS_ORDER_LE, + .layout = SOC_MBUS_LAYOUT_PACKED, + }, +}, { + .code = MEDIA_BUS_FMT_VYUY8_2X8, + .fmt = { + .fourcc = V4L2_PIX_FMT_VYUY, + .name = "VYUY", + .bits_per_sample = 8, + .packing = SOC_MBUS_PACKING_2X8_PADHI, + .order = SOC_MBUS_ORDER_LE, + .layout = SOC_MBUS_LAYOUT_PACKED, + }, +}, +}; + #define MTK_MIPICSI_BUS_PARAM (V4L2_MBUS_MASTER | \ V4L2_MBUS_HSYNC_ACTIVE_HIGH | \ V4L2_MBUS_HSYNC_ACTIVE_LOW | \ @@ -208,6 +252,43 @@ static void mtk_mipicsi_ana_clk_enable(void __iomem *base, bool enable) } } +static int mtk_mipicsi_try_bus_param(struct soc_camera_device *icd, + unsigned char buswidth) +{ + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + struct soc_camera_host *ici = to_soc_camera_host(icd->parent); + struct mtk_mipicsi_dev *mipicsi = ici->priv; + struct v4l2_mbus_config cfg = {.type = V4L2_MBUS_CSI2_DPHY,}; + unsigned long common_flags = 0; + int ret = 0; + + ret = v4l2_subdev_call(sd, video, g_mbus_config, &cfg); + if (ret == 0) { + common_flags = soc_mbus_config_compatible(&cfg, + MTK_MIPICSI_BUS_PARAM); + if (common_flags == 0U) { + dev_warn(icd->parent, "Flags incompatible: camera 0x%x\n", + cfg.flags); + return -EINVAL; + } + } else { + if (ret != -ENOIOCTLCMD) + return ret; + } + + if ((((u16)1U << (buswidth - 1U)) & mipicsi->width_flags) != 0U) + return 0; + + return -EINVAL; +} + +static bool mtk_mipicsi_packing_supported(const struct soc_mbus_pixelfmt *fmt) +{ + return fmt->packing == SOC_MBUS_PACKING_NONE || + (fmt->bits_per_sample == 8U && + fmt->packing == SOC_MBUS_PACKING_2X8_PADHI); +} + static int get_subdev_register(const struct soc_camera_device *icd, struct v4l2_dbg_register *reg) { @@ -331,6 +412,72 @@ static void mtk_mipicsi_remove_device(struct soc_camera_device *icd) (void)pm_runtime_put_sync(icd->parent); } +static int mtk_mipicsi_get_formats(struct soc_camera_device *icd, + unsigned int idx, struct soc_camera_format_xlate *xlate) +{ + struct v4l2_subdev *sd = soc_camera_to_subdev(icd); + int formats = 0, ret, i; + int n = ARRAY_SIZE(mtk_mipicsi_formats); + + struct v4l2_subdev_mbus_code_enum mbus_code = { + .which = V4L2_SUBDEV_FORMAT_ACTIVE, + .index = idx, + }; + /* subdev format */ + const struct soc_mbus_pixelfmt *fmt; + + ret = v4l2_subdev_call(sd, pad, enum_mbus_code, NULL, &mbus_code); + if (ret < 0) + /* No more formats */ + return 0; + + /* get subdev support format */ + fmt = soc_mbus_get_fmtdesc(mbus_code.code); + if (fmt == NULL) { + dev_err(icd->parent, "Invalid format code #%u: %d", + idx, mbus_code.code); + return 0; + } + + /* This also checks support for the requested bits-per-sample */ + ret = mtk_mipicsi_try_bus_param(icd, fmt->bits_per_sample); + if (ret < 0) { + dev_err(icd->parent, "Fail to try the bus parameters.\n"); + return 0; + } + + switch (mbus_code.code) { + case MEDIA_BUS_FMT_UYVY8_2X8: + case MEDIA_BUS_FMT_VYUY8_2X8: + case MEDIA_BUS_FMT_YUYV8_2X8: + case MEDIA_BUS_FMT_YVYU8_2X8: + dev_dbg(icd->parent, "Providing format %s using code %d\n", + fmt->name, mbus_code.code); + break; + default: + if (!mtk_mipicsi_packing_supported(fmt)) + return 0; + if (xlate != NULL) + dev_dbg(icd->parent, + "Providing format %s in pass-through mode\n", + fmt->name); + break; + } + + /* get camera host and subdev format intersection */ + for (i = 0; i < n; ++i) + if (mtk_mipicsi_formats[i].fmt.fourcc == fmt->fourcc) { + ++formats; + if (xlate != NULL) { + xlate->host_fmt = &mtk_mipicsi_formats[i].fmt; + xlate->code = mbus_code.code; + xlate++; + } + } + + return formats; +} + static bool is_supported(struct soc_camera_device *icd, const u32 pixformat) { bool ret = false; @@ -736,6 +883,7 @@ static struct soc_camera_host_ops mtk_soc_camera_host_ops = { .owner = THIS_MODULE, .add = mtk_mipicsi_add_device, .remove = mtk_mipicsi_remove_device, + .get_formats = mtk_mipicsi_get_formats, .set_fmt = mtk_mipicsi_set_fmt, .try_fmt = mtk_mipicsi_try_fmt, .init_videobuf2 = mtk_mipicsi_init_videobuf2, From patchwork Mon Apr 8 11:55:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10889423 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 48959922 for ; Mon, 8 Apr 2019 12:06:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2AD7928630 for ; Mon, 8 Apr 2019 12:06:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 291D528640; Mon, 8 Apr 2019 12:06:25 +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 D6BF51FFE6 for ; Mon, 8 Apr 2019 12:06:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ln61yEeb3nE8qDdIKRmdT7Ns1HFNDs05py+r73Jkq2A=; b=stMCVPjdSm2OKo pg1hhbtogtkrPaJnY2vKG/Jq1Jyku17ukQdOzdc7XSle50c5DilayQNr8k3ez2yMOLBcSWwLplN6a 6LEp/q4gKW32FMER2+OFOVPHY8Y1V+rYdyAgRNp11EA81NAHS+JkdqKDDduGMIjFE51PqM2qy4pG0 04PbGERFI5yvQse++F6bHLUvAMOwDNGYMA1+qwWvGq724/kbwy55iPCKFv/o0yQuW0IsFORdh54Dk oA5N+Dnm/dqbA2PM0h/3AJ2PKgdPwd4eam0JLcDLklF8ZOhDLX/BdTWixNmPvZIbPiXrsPL0rJWpG l6TqEWqTtxYBawX12Ncw==; 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 1hDT2d-0002DB-5l; Mon, 08 Apr 2019 12:06:23 +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 1hDSsD-0001m9-Ou; Mon, 08 Apr 2019 11:55:40 +0000 X-UUID: 009173bc7afb4922b1183f20cee21312-20190408 X-UUID: 009173bc7afb4922b1183f20cee21312-20190408 Received: from mtkcas66.mediatek.inc [(172.29.193.44)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 73213179; Mon, 08 Apr 2019 03:55:34 -0800 Received: from MTKMBS01N2.mediatek.inc (172.21.101.79) by MTKMBS62N1.mediatek.inc (172.29.193.41) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 04:55:32 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs01n2.mediatek.inc (172.21.101.79) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 19:55:30 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 8 Apr 2019 19:55:30 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Matthias Brugger Subject: [PATCH 12/14] [media] mtk-mipicsi: add the function for Get/Set PARM for application Date: Mon, 8 Apr 2019 19:55:03 +0800 Message-ID: <1554724505-19882-13-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> References: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> MIME-Version: 1.0 X-TM-SNTS-SMTP: 25D1DC7844124F8F09A5AECF193AC9E8E793571B9851CC0D816D8B62C8BC80B12000:8 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190408_045537_926849_F7077F20 X-CRM114-Status: UNSURE ( 9.93 ) X-CRM114-Notice: Please train this message. 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: srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add the function for Get/Set PARM for application. Application can get the information about number of link. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 34 +++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 9361cc4c77ac..faf9a94d5157 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -347,6 +347,38 @@ static int get_subdev_link(const struct soc_camera_device *icd, return 0; } +static int mtk_mipicsi_get_parm(struct soc_camera_device *icd, + struct v4l2_streamparm *a) +{ + unsigned int link = 0U; + u8 link_reg_val = 0x0U; + int ret = 0; + + /*get camera link number*/ + ret = get_subdev_link(icd, &link, &link_reg_val); + if (ret < 0) + return ret; + + a->parm.capture.timeperframe.numerator = 1; + a->parm.capture.timeperframe.denominator = 30; + a->parm.capture.reserved[0] = link_reg_val; + a->parm.capture.reserved[1] = (u32)(icd->use_count); + dev_info(icd->parent, "use count %d\n", icd->use_count); + + return 0; +} + +static int mtk_mipicsi_set_param(struct soc_camera_device *icd, + struct v4l2_streamparm *a) +{ + struct soc_camera_host *ici = to_soc_camera_host(icd->parent); + + if (ici->ops->get_parm == NULL) + return ici->ops->get_parm(icd, a); + + return 0; +} + static u32 get_bytesperline(const u32 fmt, const u32 width) { u32 bytesperline = 0; @@ -890,6 +922,8 @@ static struct soc_camera_host_ops mtk_soc_camera_host_ops = { .poll = vb2_fop_poll, .querycap = mtk_mipicsi_querycap, .set_bus_param = mtk_mipicsi_set_bus_param, + .get_parm = mtk_mipicsi_get_parm, + .set_parm = mtk_mipicsi_set_param, }; static void mtk_mipicsi_ana_init(void __iomem *base) From patchwork Mon Apr 8 11:55:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10889407 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 54AFE1669 for ; Mon, 8 Apr 2019 11:57:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 34C6728643 for ; Mon, 8 Apr 2019 11:57:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2764D28682; Mon, 8 Apr 2019 11:57:53 +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 B433828643 for ; Mon, 8 Apr 2019 11:57:52 +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=bl0mFaccFS0s325kz4ui19XK7Rvdq74yIO4sjp8BkZQ=; b=es/6Q7dBxfkAlk Lp+AIfiidrn6bfl3vlpau5Z3LPE7aV110IrkU1dXzpfo6975AHIRm1ogo50RJPzMAIz4AIEPeEfqq oUkS5Z0Z7JIsEyLLDqoWenL3s61dcrReGKeeQ4wR6Io61/2x5xBZE8gaOotTnNbYU+/jTu7vPJ8Nj j3Ryu1bNrMO8zrPxQ1Jpu5bglf+aLjfLtr7LEuEw69HYj/EgfS3+ja6qzm0aBK4a98LoYH7tGqhea 6E4mkdMpmirnizUcdPOBTcM1SCTyDN34cYQ+205OiJR3p7jC1OqP7y/I1c4bpG7NNw6YG7mRRNMz5 JUDO7IWEcgKKUR79gAcQ==; 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 1hDSuN-0004fA-2y; Mon, 08 Apr 2019 11:57:51 +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 1hDSsL-0001mH-Oi; Mon, 08 Apr 2019 11:55:53 +0000 X-UUID: fa9839f819b44ec4ac1f4ddae18b67d0-20190408 X-UUID: fa9839f819b44ec4ac1f4ddae18b67d0-20190408 Received: from mtkcas68.mediatek.inc [(172.29.94.19)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 702155388; Mon, 08 Apr 2019 03:55:33 -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, 8 Apr 2019 04:55:32 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 19:55:30 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 8 Apr 2019 19:55:31 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Matthias Brugger Subject: [PATCH 13/14] [media] mtk-mipicsi: add debug message for mipicsi driver Date: Mon, 8 Apr 2019 19:55:04 +0800 Message-ID: <1554724505-19882-14-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> References: <1554724505-19882-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-20190408_045546_207715_53C94976 X-CRM114-Status: GOOD ( 16.60 ) 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: srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add debug message for mipicsi driver. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 54 ++++++++++++++++++- 1 file changed, 52 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index faf9a94d5157..95d25db5e606 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -118,6 +119,15 @@ #define SerDes_support 1 +static int mtk_mipicsi_dbg_level; +#define mtk_mipicsi_dbg(level, fmt, args...) \ + do { \ + if (mtk_mipicsi_dbg_level >= level) \ + pr_info("[MTK_MIPICSI%d] L%d %s %d: " fmt "\n", \ + mipicsi->id, level, __func__, __LINE__, \ + ##args); \ + } while (0) + /* buffer for one video frame */ struct mtk_mipicsi_buf { struct list_head queue; @@ -155,6 +165,8 @@ struct mtk_mipicsi_dev { unsigned long enqueue_cnt; unsigned long dequeue_cnt; struct v4l2_ctrl_handler ctrl_hdl; + struct timespec64 fps_time_cur; + struct timespec64 fps_time_pre; char drv_name[16]; u32 id; int clk_num; @@ -430,6 +442,8 @@ static int mtk_mipicsi_add_device(struct soc_camera_device *icd) mipicsi->width = width; mipicsi->height = height; + mtk_mipicsi_dbg(1, "sub device width/height/bytesperline %d/%d/%d", + width, height, mipicsi->bytesperline); /* * If power domain was closed before, it will be open. @@ -571,6 +585,9 @@ static int mtk_mipicsi_set_fmt(struct soc_camera_device *icd, if (pix->pixelformat == V4L2_PIX_FMT_YUYV) pix->sizeimage = pix->width * pix->height * 2U; + mtk_mipicsi_dbg(0, "width/height/sizeimage %u/%u/%u", + pix->width, pix->height, pix->sizeimage); + if (mf->code != xlate->code) return -EINVAL; @@ -696,6 +713,9 @@ static int mtk_mipicsi_vb2_prepare(struct vb2_buffer *vb) vb2_dma_contig_plane_dma_addr(vb, 0); #endif va = vb2_plane_vaddr(vb, 0); + mtk_mipicsi_dbg(1, "va=%p vb_dma_addr_phy=%lx size=%d", + va, (unsigned long)buf->vb_dma_addr_phy, + vb->planes[0].bytesused); buf->vb = vb; } @@ -741,6 +761,8 @@ static void mtk_mipicsi_vb2_queue(struct vb2_buffer *vb) } ++(mipicsi->enqueue_cnt); + mtk_mipicsi_dbg(2, "enqueue NO.%d buffer(%p). Total %lu buffer", + vb->index, vb, mipicsi->enqueue_cnt); } static int mtk_mipicsi_vb2_start_streaming(struct vb2_queue *vq, @@ -1125,8 +1147,10 @@ static int mtk_mipicsi_pm_resume(struct device *dev) if (mipicsi->larb_pdev != NULL) { ret = mtk_smi_larb_get(mipicsi->larb_pdev); - if (ret != 0) + if (ret != 0) { + mtk_mipicsi_dbg(0, "failed to get larb, err %d", ret); return ret; + } } mtk_mipicsi_ana_clk_enable(mipicsi->ana, true); @@ -1176,6 +1200,7 @@ static void mtk_mipicsi_irq_buf_process(struct mtk_mipicsi_dev *mipicsi) unsigned int next = 0U; u64 offset = 0ULL; u8 link_index = 0U; + long time_interval; void __iomem *base = NULL; dma_addr_t pa; @@ -1185,8 +1210,10 @@ static void mtk_mipicsi_irq_buf_process(struct mtk_mipicsi_dev *mipicsi) i = 0; /* only one buffer left */ - if ((&(mipicsi->fb_list))->next->next == &(mipicsi->fb_list)) + if ((&(mipicsi->fb_list))->next->next == &(mipicsi->fb_list)) { + mtk_mipicsi_dbg(1, "only 1 buffer left, drop frame"); return; + } /*for each fb_lst 2 times to get the top 2 buffer.*/ list_for_each_entry_safe(new_cam_buf, tmp, @@ -1219,6 +1246,27 @@ static void mtk_mipicsi_irq_buf_process(struct mtk_mipicsi_dev *mipicsi) ++(mipicsi->dequeue_cnt); list_del_init(&(mipicsi->cam_buf[index].queue)); + + if (mtk_mipicsi_dbg_level >= 2) { + ktime_get_real_ts64(&(mipicsi->fps_time_cur)); + if (mipicsi->dequeue_cnt == 1) { + mipicsi->fps_time_pre.tv_sec = + mipicsi->fps_time_cur.tv_sec; + mipicsi->fps_time_pre.tv_nsec = + mipicsi->fps_time_cur.tv_nsec; + } else { + time_interval = (mipicsi->fps_time_cur.tv_sec + - mipicsi->fps_time_pre.tv_sec) * 1000000000 + + (mipicsi->fps_time_cur.tv_nsec + - mipicsi->fps_time_pre.tv_nsec); + mtk_mipicsi_dbg(0, "time interval is %ld\n", + time_interval); + mipicsi->fps_time_pre.tv_sec = + mipicsi->fps_time_cur.tv_sec; + mipicsi->fps_time_pre.tv_nsec = + mipicsi->fps_time_cur.tv_nsec; + } + } } static irqreturn_t mtk_mipicsi_isr(int irq, void *data) @@ -1233,6 +1281,7 @@ static irqreturn_t mtk_mipicsi_isr(int irq, void *data) isr_ch = get_irq_channel(mipicsi); if (isr_ch < 0) { + mtk_mipicsi_dbg(0, "no interrupt occur"); spin_unlock_irqrestore(&mipicsi->lock, flags); return IRQ_HANDLED; } @@ -1573,5 +1622,6 @@ static struct platform_driver mtk_mipicsi_driver = { }; module_platform_driver(mtk_mipicsi_driver); +module_param(mtk_mipicsi_dbg_level, int, 0644); MODULE_DESCRIPTION("MediaTek SoC Camera Host driver"); MODULE_LICENSE("GPL v2"); From patchwork Mon Apr 8 11:55:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stu Hsieh X-Patchwork-Id: 10889419 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 A88041669 for ; Mon, 8 Apr 2019 11:58:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AEF026AE3 for ; Mon, 8 Apr 2019 11:58:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7F49E28682; Mon, 8 Apr 2019 11:58:44 +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 176F226AE3 for ; Mon, 8 Apr 2019 11:58:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=94XeiWdBOj8MwaaNOZhzxknquY6gI4CgQ6WSAkz811A=; b=jVXWuyqpsGOiQU BQlmsSA9ot1+ANIlCDiGQSTzgkjx2djmfO4KIIfwibe4SKXMeRnYuYjMl4AQrvFCj8MUlEOL9qmC0 oR04bIqPX4uo85pc2LxARHeaW5M3BwR75wNj3J2eVQ+frH0dJwR9xLC8OJ5915wfi2vCyvN7xO+oQ G7xkgxLNruyEBLDY8O8rHOv6fO29SoNEmfLjGpkqpuR8aKvkP6HW6SsZH4X0ZIUQKaW/P58BOKGDV 2i9W1HYxn6uF6oE+dkr10k1mCtUaXu17AA0e273MqaG79P64d0U5Of6Y2uHY+W6laBUXJ5KWL5aQN lqNrO3CZeGhJsYsYli5A==; 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 1hDSvC-0005ly-6I; Mon, 08 Apr 2019 11:58:42 +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 1hDSsT-0001mH-MR; Mon, 08 Apr 2019 11:55:58 +0000 X-UUID: 14184cf1024d4ac6a4de13bc82913310-20190408 X-UUID: 14184cf1024d4ac6a4de13bc82913310-20190408 Received: from mtkcas67.mediatek.inc [(172.29.193.45)] by mailgw01.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLS) with ESMTP id 1789826199; Mon, 08 Apr 2019 03:55:36 -0800 Received: from MTKMBS01N1.mediatek.inc (172.21.101.68) by MTKMBS62N2.mediatek.inc (172.29.193.42) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 04:55:34 -0700 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs01n1.mediatek.inc (172.21.101.68) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Mon, 8 Apr 2019 19:55:33 +0800 Received: from mtksdccf07.mediatek.inc (172.21.84.99) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Mon, 8 Apr 2019 19:55:33 +0800 From: Stu Hsieh To: Mauro Carvalho Chehab , Matthias Brugger Subject: [PATCH 14/14] [media] mtk-mipicsi: add debugfs for mipicsi driver Date: Mon, 8 Apr 2019 19:55:05 +0800 Message-ID: <1554724505-19882-15-git-send-email-stu.hsieh@mediatek.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1554724505-19882-1-git-send-email-stu.hsieh@mediatek.com> References: <1554724505-19882-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-20190408_045554_026744_FFD9064E X-CRM114-Status: GOOD ( 11.99 ) 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: srv_heupstream@mediatek.com, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, Stu Hsieh , linux-arm-kernel@lists.infradead.org, linux-media@vger.kernel.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This patch add debugfs for mipicsi driver. Signed-off-by: Stu Hsieh --- .../media/platform/mtk-mipicsi/mtk_mipicsi.c | 65 +++++++++++++++++++ 1 file changed, 65 insertions(+) diff --git a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c index 95d25db5e606..77aecadab6b7 100644 --- a/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c +++ b/drivers/media/platform/mtk-mipicsi/mtk_mipicsi.c @@ -49,6 +49,7 @@ #include #include #include +#include #ifdef CONFIG_VB2_MEDIATEK_DMA_SG #include "mtkbuf-dma-cache-sg.h" @@ -87,6 +88,7 @@ #define SENINF_NCSI2_INT_EN 0xB0 #define SENINF_NCSI2_INT_STATUS 0xB4 #define SENINF_NCSI2_DBG_SEL 0xB8 +#define SENINF_NCSI2_DBG_PORT 0xBC #define SENINF_NCSI2_HSRX_DBG 0xD8 #define SENINF_NCSI2_DI 0xDC #define SENINF_NCSI2_DI_CTRL 0xE4 @@ -96,6 +98,7 @@ #define SENINF_TOP_MUX 0x08 #define SENINF_MUX_CTRL 0x00 +#define SENINF_MUX_DEBUG_2 0x14 #define CAMSV_MODULE_EN 0x10 #define CAMSV_FMT_SEL 0x14 @@ -118,6 +121,7 @@ #define DMA_FRAME_HEADER_EN 0xE00 #define SerDes_support 1 +#define CONFIG_DEBUG_FS 1 static int mtk_mipicsi_dbg_level; #define mtk_mipicsi_dbg(level, fmt, args...) \ @@ -174,6 +178,9 @@ struct mtk_mipicsi_dev { u32 width; u32 height; u32 bytesperline; +#ifdef CONFIG_DEBUG_FS + struct dentry *mtk_mipicsi_debugfs; +#endif }; static const struct soc_mbus_lookup mtk_mipicsi_formats[] = { @@ -229,6 +236,49 @@ static const struct soc_mbus_lookup mtk_mipicsi_formats[] = { V4L2_MBUS_PCLK_SAMPLE_FALLING | \ V4L2_MBUS_DATA_ACTIVE_HIGH) +#ifdef CONFIG_DEBUG_FS +static ssize_t mtk_mipicsi_debug_read(struct file *file, char __user *user_buf, + size_t count, loff_t *ppos) +{ + struct device *dev = file->private_data; + struct soc_camera_host *soc_host = to_soc_camera_host(dev); + struct mtk_mipicsi_dev *mipicsi = soc_host->priv; + u32 int_val; + u32 dbg_port; + u32 cnt_val; + u32 hcnt; + u32 vcnt; + char buf[256]; + char cnt_info[150]; + int i; + + int_val = readl(mipicsi->seninf + SENINF_NCSI2_INT_STATUS); + dbg_port = readl(mipicsi->seninf + SENINF_NCSI2_DBG_PORT); + memset(buf, 0, sizeof(buf)); + snprintf(buf, sizeof(buf), "%s\nSENINF_NCSI2_INT_STATUS: 0x%X\n" + "SENINF_NCSI2_DBG_PORT: 0x%X\n", + dev_name(dev), int_val, dbg_port); + + for (i = 0; i < mipicsi->camsv_num; ++i) { + cnt_val = readl(mipicsi->seninf_mux[i] + SENINF_MUX_DEBUG_2); + hcnt = (cnt_val >> 16) & 0xFFFF; + vcnt = cnt_val & 0xFFFF; + memset(cnt_info, 0, sizeof(cnt_info)); + snprintf(cnt_info, sizeof(cnt_info), + "HCNT[%d]: 0x%X\n" + "VCNT[%d]: 0x%X\n", + i, hcnt, i, vcnt); + strcat(buf, cnt_info); + } + + return simple_read_from_buffer(user_buf, count, ppos, buf, strlen(buf)); +} +static const struct file_operations mtk_mipicsi_debug_fops = { + .open = simple_open, + .read = mtk_mipicsi_debug_read, +}; +#endif /* CONFIG_DEBUG_FS */ + static void mtk_mipicsi_ana_clk_enable(void __iomem *base, bool enable) { if (enable) { @@ -1588,6 +1638,16 @@ static int mtk_mipicsi_probe(struct platform_device *pdev) goto clean; } +#ifdef CONFIG_DEBUG_FS + mipicsi->mtk_mipicsi_debugfs = + debugfs_create_file(mipicsi->drv_name, 0444, NULL, + (void *)(&pdev->dev), &mtk_mipicsi_debug_fops); + if (mipicsi->mtk_mipicsi_debugfs == NULL) { + dev_err(&pdev->dev, "debugfs_create_file fail\n"); + goto clean; + } +#endif + dev_info(&pdev->dev, "probe done\n"); return ret; clean: @@ -1600,6 +1660,11 @@ static int mtk_mipicsi_remove(struct platform_device *pdev) { struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev); +#ifdef CONFIG_DEBUG_FS + struct mtk_mipicsi_dev *mipicsi = soc_host->priv; + + debugfs_remove(mipicsi->mtk_mipicsi_debugfs); +#endif soc_camera_host_unregister(soc_host); pm_runtime_disable(&pdev->dev);