From patchwork Mon Mar 5 09:35:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10258481 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3920460365 for ; Mon, 5 Mar 2018 09:36:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 28EA42899E for ; Mon, 5 Mar 2018 09:36:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1D8AF289B1; Mon, 5 Mar 2018 09:36:05 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8C9F12899E for ; Mon, 5 Mar 2018 09:36:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933722AbeCEJfx (ORCPT ); Mon, 5 Mar 2018 04:35:53 -0500 Received: from mail.bootlin.com ([62.4.15.54]:49540 "EHLO mail.bootlin.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933621AbeCEJft (ORCPT ); Mon, 5 Mar 2018 04:35:49 -0500 Received: by mail.bootlin.com (Postfix, from userid 110) id 010EB2092C; Mon, 5 Mar 2018 10:35:46 +0100 (CET) Received: from localhost (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.bootlin.com (Postfix) with ESMTPSA id 9D72F20784; Mon, 5 Mar 2018 10:35:36 +0100 (CET) From: Maxime Ripard To: Yong Deng Cc: Mauro Carvalho Chehab , Chen-Yu Tsai , Maxime Ripard , Hans Verkuil , Sakari Ailus , linux-media@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Thomas Petazzoni , Mylene Josserand Subject: [PATCH 1/7] media: sun6i: Fill dma_pfn_offset to accomodate for the RAM offset Date: Mon, 5 Mar 2018 10:35:28 +0100 Message-Id: <20180305093535.11801-2-maxime.ripard@bootlin.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180305093535.11801-1-maxime.ripard@bootlin.com> References: <1519697113-32202-1-git-send-email-yong.deng@magewell.com> <20180305093535.11801-1-maxime.ripard@bootlin.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The CSI controller does its DMA accesses through a DMA bus that has the RAM mapped at the address 0. The current code removes from the dma_addr_t PHYS_OFFSET, and while it works, this is an abuse of the DMA API. Instead, fill the dma_pfn_offset field in the struct device that should be used to express such an offset, and the use the dma_addr_t directly as we should. Signed-off-by: Maxime Ripard --- drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c index 1aaaae238d57..2ec33fb04632 100644 --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c @@ -563,20 +563,15 @@ int sun6i_csi_update_config(struct sun6i_csi *csi, void sun6i_csi_update_buf_addr(struct sun6i_csi *csi, dma_addr_t addr) { struct sun6i_csi_dev *sdev = sun6i_csi_to_dev(csi); - /* transform physical address to bus address */ -#if defined(CONFIG_COMPILE_TEST) && !defined(PHYS_OFFSET) -#define PHYS_OFFSET 0 -#endif - dma_addr_t bus_addr = addr - PHYS_OFFSET; regmap_write(sdev->regmap, CSI_CH_F0_BUFA_REG, - (bus_addr + sdev->planar_offset[0]) >> 2); + (addr + sdev->planar_offset[0]) >> 2); if (sdev->planar_offset[1] != -1) regmap_write(sdev->regmap, CSI_CH_F1_BUFA_REG, - (bus_addr + sdev->planar_offset[1]) >> 2); + (addr + sdev->planar_offset[1]) >> 2); if (sdev->planar_offset[2] != -1) regmap_write(sdev->regmap, CSI_CH_F2_BUFA_REG, - (bus_addr + sdev->planar_offset[2]) >> 2); + (addr + sdev->planar_offset[2]) >> 2); } void sun6i_csi_set_stream(struct sun6i_csi *csi, bool enable) @@ -856,6 +851,14 @@ static int sun6i_csi_resource_request(struct sun6i_csi_dev *sdev, return 0; } +/* + * PHYS_OFFSET isn't available on all architectures. In order to + * accomodate for COMPILE_TEST, let's define it to something dumb. + */ +#ifndef PHYS_OFFSET +#define PHYS_OFFSET 0 +#endif + static int sun6i_csi_probe(struct platform_device *pdev) { struct sun6i_csi_dev *sdev; @@ -866,6 +869,8 @@ static int sun6i_csi_probe(struct platform_device *pdev) return -ENOMEM; sdev->dev = &pdev->dev; + /* The DMA bus has the memory mapped at 0 */ + sdev->dev->dma_pfn_offset = PHYS_OFFSET >> PAGE_SHIFT; ret = sun6i_csi_resource_request(sdev, pdev); if (ret)