From patchwork Thu Nov 3 16:30:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Kocialkowski X-Patchwork-Id: 14989 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp637317wru; Thu, 3 Nov 2022 09:33:14 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6401UOVc/tiM7eYCxADCmQMBUl43x6+rUBZ6DciODe1B7SLOEdOqrVccDYbL0RkfG9Joqv X-Received: by 2002:aa7:d2cd:0:b0:463:23a4:aa9e with SMTP id k13-20020aa7d2cd000000b0046323a4aa9emr26432666edr.362.1667493194447; Thu, 03 Nov 2022 09:33:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667493194; cv=none; d=google.com; s=arc-20160816; b=bHbAL5bXaKHOeHe+hH9964PQg1q+FSeq/PlC4ltGVuaYCJ4y45YiDx7Do2NSDO4qCQ J5OYkZblA+fzb0x9c3AF1god6Epu68M3a/g9JhKkM7o0Oa4b23SYl2mH4L6bhC6iA/QY hHexveuhYtnCjVHN+ZEbAcvHWX3vAfnj1KSNlJpKSEhUdqU0ex/8wm99MUnixI7BGSCC GVw6xg0fluEFNkr3imjVOzAFqkrd+SQfLqQydCHhukPnt+82vi1vC5bXxyU3rGWOqsiG 0dEg0oLle80OR6cHTjntYz49mdbRga+K0HdzCV8lYIANxTsF0bQwASfX1DKO5iWS9ckX S2dQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LQyqzHTL++RGaItex4uVeobLkyhPnz1r6d4Sw3VlG+M=; b=Jt/RaTgb1dOv1pqNXwBjrF53bbVQdFQhqJYUUOmR04MxnRWthfZVIt+KpPyRL/6v1A hRAwso3S9uOl/hefmllnHSiemsW946RjOAVyS2CbrQSiRBwW8hHLvv1v19JKayyePAlw FTuFNrinvSwfvIf7nee80dK/tcr/062Zx1DvF1ZO9i9jhKi6CnpXjAOhb7+cCQ9K/Nng /ML5BekITuxBIYJgfj1/KIlWcJHJUcszUn+c5ljY9QkzzxhgzNE4TV1x9fYTIwsFv2L0 y+XaNrHD455+jxxMHUCfOlg0Hp1oWuV/tMetvAqrDzuvI+6AvBnGhgBwyf8nwuBB9lX2 Mtcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=DsYbmGVw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sc6-20020a1709078a0600b0078d1dc1b64csi1975015ejc.170.2022.11.03.09.32.49; Thu, 03 Nov 2022 09:33:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=DsYbmGVw; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232220AbiKCQc0 (ORCPT + 99 others); Thu, 3 Nov 2022 12:32:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55560 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231828AbiKCQbr (ORCPT ); Thu, 3 Nov 2022 12:31:47 -0400 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 355B81B9F6; Thu, 3 Nov 2022 09:31:42 -0700 (PDT) Received: (Authenticated sender: paul.kocialkowski@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 7484724000D; Thu, 3 Nov 2022 16:31:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1667493100; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LQyqzHTL++RGaItex4uVeobLkyhPnz1r6d4Sw3VlG+M=; b=DsYbmGVweA6LYsiGLeYmO6Ay8b/UN101pqYX+kYOePUlCxVPrWI7nf+U0xMfUgOaLFhTHX 9pahhTpkylnSsvnWjePrKlw/kkG+1/A/YWagiZueTQT+5nmZY3OQLV7+/Yy44beuxmOYmW U0pnp0Hx2H9MgOl6DkjDhG7J7/ND3/rV+bAMvcTqVGA3+6B6Xp1h98mCo8aLrDdaLAKFMR MiuyFtzDmnriRjoAY0PYKHwIaoAiw5XUECmxgF+fFWfNWlYHjBA/EsYLOQzA8Z3cr9MXKC DZqrzqwYxpGu0w0R8HqRE9YWAfPY+Q9GqV1DkuYw49KM7Hy5THMUUMCkZJQz2g== From: Paul Kocialkowski To: linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-sunxi@lists.linux.dev Cc: Yong Deng , Paul Kocialkowski , Mauro Carvalho Chehab , Chen-Yu Tsai , Jernej Skrabec , Samuel Holland , Laurent Pinchart , Maxime Ripard , Thomas Petazzoni Subject: [PATCH v7 06/28] media: sun6i-csi: Implement address configuration without indirection Date: Thu, 3 Nov 2022 17:30:51 +0100 Message-Id: <20221103163113.245462-7-paul.kocialkowski@bootlin.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221103163113.245462-1-paul.kocialkowski@bootlin.com> References: <20221103163113.245462-1-paul.kocialkowski@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748493343743242057?= X-GMAIL-MSGID: =?utf-8?q?1748493343743242057?= Instead of calculating the planar_offset at one point and using it later in a dedicated function, reimplement address configuration with v4l2 format info in the buffer_configure function. Signed-off-by: Paul Kocialkowski Acked-by: Jernej Skrabec --- .../platform/sunxi/sun6i-csi/sun6i_csi.c | 27 ---------------- .../platform/sunxi/sun6i-csi/sun6i_csi.h | 10 ------ .../sunxi/sun6i-csi/sun6i_csi_capture.c | 32 ++++++++++++++++++- 3 files changed, 31 insertions(+), 38 deletions(-) diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c index 79d4b00d1fcd..5e03069bd4c3 100644 --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c @@ -463,7 +463,6 @@ static void sun6i_csi_set_window(struct sun6i_csi_device *csi_dev) struct sun6i_csi_config *config = &csi_dev->config; u32 bytesperline_y; u32 bytesperline_c; - int *planar_offset = csi_dev->planar_offset; u32 width = config->width; u32 height = config->height; u32 hor_len = width; @@ -488,7 +487,6 @@ static void sun6i_csi_set_window(struct sun6i_csi_device *csi_dev) SUN6I_CSI_CH_VSIZE_LEN(height) | SUN6I_CSI_CH_VSIZE_START(0)); - planar_offset[0] = 0; switch (config->pixelformat) { case V4L2_PIX_FMT_NV12_16L16: case V4L2_PIX_FMT_NV12: @@ -497,23 +495,15 @@ static void sun6i_csi_set_window(struct sun6i_csi_device *csi_dev) case V4L2_PIX_FMT_NV61: bytesperline_y = width; bytesperline_c = width; - planar_offset[1] = bytesperline_y * height; - planar_offset[2] = -1; break; case V4L2_PIX_FMT_YUV420: case V4L2_PIX_FMT_YVU420: bytesperline_y = width; bytesperline_c = width / 2; - planar_offset[1] = bytesperline_y * height; - planar_offset[2] = planar_offset[1] + - bytesperline_c * height / 2; break; case V4L2_PIX_FMT_YUV422P: bytesperline_y = width; bytesperline_c = width / 2; - planar_offset[1] = bytesperline_y * height; - planar_offset[2] = planar_offset[1] + - bytesperline_c * height; break; default: /* raw */ dev_dbg(csi_dev->dev, @@ -522,8 +512,6 @@ static void sun6i_csi_set_window(struct sun6i_csi_device *csi_dev) bytesperline_y = (sun6i_csi_get_bpp(config->pixelformat) * config->width) / 8; bytesperline_c = 0; - planar_offset[1] = -1; - planar_offset[2] = -1; break; } @@ -547,21 +535,6 @@ int sun6i_csi_update_config(struct sun6i_csi_device *csi_dev, return 0; } -void sun6i_csi_update_buf_addr(struct sun6i_csi_device *csi_dev, - dma_addr_t addr) -{ - regmap_write(csi_dev->regmap, SUN6I_CSI_CH_FIFO0_ADDR_REG, - SUN6I_CSI_ADDR_VALUE(addr + csi_dev->planar_offset[0])); - if (csi_dev->planar_offset[1] != -1) - regmap_write(csi_dev->regmap, SUN6I_CSI_CH_FIFO1_ADDR_REG, - SUN6I_CSI_ADDR_VALUE(addr + - csi_dev->planar_offset[1])); - if (csi_dev->planar_offset[2] != -1) - regmap_write(csi_dev->regmap, SUN6I_CSI_CH_FIFO2_ADDR_REG, - SUN6I_CSI_ADDR_VALUE(addr + - csi_dev->planar_offset[2])); -} - void sun6i_csi_set_stream(struct sun6i_csi_device *csi_dev, bool enable) { struct regmap *regmap = csi_dev->regmap; diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h index 6c0110e4b3ab..75867cde7985 100644 --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h @@ -60,8 +60,6 @@ struct sun6i_csi_device { struct clk *clock_mod; struct clk *clock_ram; struct reset_control *reset; - - int planar_offset[3]; }; struct sun6i_csi_variant { @@ -98,14 +96,6 @@ int sun6i_csi_set_power(struct sun6i_csi_device *csi_dev, bool enable); int sun6i_csi_update_config(struct sun6i_csi_device *csi_dev, struct sun6i_csi_config *config); -/** - * sun6i_csi_update_buf_addr() - update the csi frame buffer address - * @csi_dev: pointer to the csi device - * @addr: frame buffer's physical address - */ -void sun6i_csi_update_buf_addr(struct sun6i_csi_device *csi_dev, - dma_addr_t addr); - /** * sun6i_csi_set_stream() - start/stop csi streaming * @csi_dev: pointer to the csi device diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c index a3c3bbf6a506..cb23dcdf250f 100644 --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi_capture.c @@ -6,6 +6,7 @@ */ #include +#include #include #include @@ -16,6 +17,7 @@ #include "sun6i_csi.h" #include "sun6i_csi_capture.h" +#include "sun6i_csi_reg.h" /* This is got from BSP sources. */ #define MIN_WIDTH (32) @@ -109,13 +111,41 @@ static void sun6i_csi_capture_buffer_configure(struct sun6i_csi_device *csi_dev, struct sun6i_csi_buffer *csi_buffer) { + struct regmap *regmap = csi_dev->regmap; + const struct v4l2_format_info *info; struct vb2_buffer *vb2_buffer; + unsigned int width, height; dma_addr_t address; + u32 pixelformat; vb2_buffer = &csi_buffer->v4l2_buffer.vb2_buf; address = vb2_dma_contig_plane_dma_addr(vb2_buffer, 0); - sun6i_csi_update_buf_addr(csi_dev, address); + regmap_write(regmap, SUN6I_CSI_CH_FIFO0_ADDR_REG, + SUN6I_CSI_ADDR_VALUE(address)); + + sun6i_csi_capture_dimensions(csi_dev, &width, &height); + sun6i_csi_capture_format(csi_dev, &pixelformat, NULL); + + info = v4l2_format_info(pixelformat); + /* Unsupported formats are single-plane, so we can stop here. */ + if (!info) + return; + + if (info->comp_planes > 1) { + address += info->bpp[0] * width * height; + + regmap_write(regmap, SUN6I_CSI_CH_FIFO1_ADDR_REG, + SUN6I_CSI_ADDR_VALUE(address)); + } + + if (info->comp_planes > 2) { + address += info->bpp[1] * DIV_ROUND_UP(width, info->hdiv) * + DIV_ROUND_UP(height, info->vdiv); + + regmap_write(regmap, SUN6I_CSI_CH_FIFO2_ADDR_REG, + SUN6I_CSI_ADDR_VALUE(address)); + } } static void sun6i_csi_capture_configure(struct sun6i_csi_device *csi_dev)