Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp38753ybi; Tue, 16 Jul 2019 15:48:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwEMkSNMNudQ7dy8QHRQeEcMOTyHE7xJquTsR9LrfWJ2Ypa8WZoPc1avyineTGgnwFjiyQO X-Received: by 2002:a17:902:b28b:: with SMTP id u11mr37121391plr.11.1563317316259; Tue, 16 Jul 2019 15:48:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563317316; cv=none; d=google.com; s=arc-20160816; b=H43j7u/1lrsvzrFtrbyFg2su5xfpDJXVLqVaOedK3iRe7WbyY4/gxF5Zn9kLvIJzrU ElM15D+6bDc/bE0+WXO/U9AghJ3Qn0So4y0KwItzeWr8ZdiA4eTY/bCTGUZOvFrlK37u FsbUc7uMNb5fwXBTVFDyEh1K3s736G4BhooyVVlB2848uBHKbh6lkYSQjYMvrUcI2o5R HZBRP1XmgbN3oxZfrO4Z/mphaWMn5w3QM6JhKZ23Ub7n5Q7iY9sYDKz1o8c6Uq75yyz1 /ASSBpIAAg8ybLeu0wRFz/t3x14gf/NCqbkeZkaG6vWy+Osev2GKREhP6dM6FcIkmytN D1xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=EUBk8+2sKEUtkDk6NHVWkL7pi99ktIpq+4HuNBsRe0s=; b=1EMxFea2OBqmaR35WgAIphlrOmxisYWaxa9g3pxi1b2pixQtLLTzpiY8UIeSP68BYo 6W21DUi1gw1Sg2BC0j7vkigqO9SRn4q51gfdF08iJ5h0r2/FzyLpS+aa6uHeIX6COEgt kF3iDL7Ri3dzHS8kDQ+VSkg4jJCiIjNPN3fWnBBjkDMwSGwXi/pKQpB/zj5qjwdXUwg4 xgb6gzegP8AU7Zb9/ct/K88wGsxTq0o7DcIapgDOw1jqMbP9Z7jLrgNRbzqfoj40FxA7 h4hE4Pz0Vond8/vTSP+jouFeMP9NhvcwlcRn1sWmtRtCjhMEx4iGhgqbKsccuP7HHhcX ph+A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p33si20157965pgb.0.2019.07.16.15.48.20; Tue, 16 Jul 2019 15:48:36 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389097AbfGPWqL (ORCPT + 99 others); Tue, 16 Jul 2019 18:46:11 -0400 Received: from mga12.intel.com ([192.55.52.136]:57961 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388105AbfGPWqJ (ORCPT ); Tue, 16 Jul 2019 18:46:09 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga007.jf.intel.com ([10.7.209.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 16 Jul 2019 15:46:08 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,271,1559545200"; d="scan'208";a="158276150" Received: from tthayer-hp-z620.an.intel.com ([10.122.105.146]) by orsmga007.jf.intel.com with ESMTP; 16 Jul 2019 15:46:08 -0700 From: thor.thayer@linux.intel.com To: mdf@kernel.org, richard.gong@linux.intel.com, agust@denx.de Cc: linux-fpga@vger.kernel.org, linux-kernel@vger.kernel.org, Thor Thayer Subject: [PATCHv2 2/3] fpga: altera-cvp: Preparation for V2 parts. Date: Tue, 16 Jul 2019 17:48:06 -0500 Message-Id: <1563317287-18834-3-git-send-email-thor.thayer@linux.intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1563317287-18834-1-git-send-email-thor.thayer@linux.intel.com> References: <1563317287-18834-1-git-send-email-thor.thayer@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thor Thayer In preparation for adding newer V2 parts that use a FIFO, reorganize altera_cvp_chk_error() and change the write function to block based. V2 parts have a block size matching the FIFO while older V1 parts write a 32 bit word at a time. Signed-off-by: Thor Thayer --- v2 Remove inline function declaration Reverse Christmas Tree format for local variables --- drivers/fpga/altera-cvp.c | 72 ++++++++++++++++++++++++++++++----------------- 1 file changed, 46 insertions(+), 26 deletions(-) diff --git a/drivers/fpga/altera-cvp.c b/drivers/fpga/altera-cvp.c index b78c90580071..37419d6b9915 100644 --- a/drivers/fpga/altera-cvp.c +++ b/drivers/fpga/altera-cvp.c @@ -140,6 +140,41 @@ static int altera_cvp_wait_status(struct altera_cvp_conf *conf, u32 status_mask, return -ETIMEDOUT; } +static int altera_cvp_chk_error(struct fpga_manager *mgr, size_t bytes) +{ + struct altera_cvp_conf *conf = mgr->priv; + u32 val; + + /* STEP 10 (optional) - check CVP_CONFIG_ERROR flag */ + altera_read_config_dword(conf, VSE_CVP_STATUS, &val); + if (val & VSE_CVP_STATUS_CFG_ERR) { + dev_err(&mgr->dev, "CVP_CONFIG_ERROR after %zu bytes!\n", + bytes); + return -EPROTO; + } + return 0; +} + +static int altera_cvp_send_block(struct altera_cvp_conf *conf, + const u32 *data, size_t len) +{ + u32 mask, words = len / sizeof(u32); + int i, remainder; + + for (i = 0; i < words; i++) + conf->write_data(conf, *data++); + + /* write up to 3 trailing bytes, if any */ + remainder = len % sizeof(u32); + if (remainder) { + mask = BIT(remainder * 8) - 1; + if (mask) + conf->write_data(conf, *data & mask); + } + + return 0; +} + static int altera_cvp_teardown(struct fpga_manager *mgr, struct fpga_image_info *info) { @@ -262,39 +297,29 @@ static int altera_cvp_write_init(struct fpga_manager *mgr, return 0; } -static inline int altera_cvp_chk_error(struct fpga_manager *mgr, size_t bytes) -{ - struct altera_cvp_conf *conf = mgr->priv; - u32 val; - - /* STEP 10 (optional) - check CVP_CONFIG_ERROR flag */ - altera_read_config_dword(conf, VSE_CVP_STATUS, &val); - if (val & VSE_CVP_STATUS_CFG_ERR) { - dev_err(&mgr->dev, "CVP_CONFIG_ERROR after %zu bytes!\n", - bytes); - return -EPROTO; - } - return 0; -} - static int altera_cvp_write(struct fpga_manager *mgr, const char *buf, size_t count) { struct altera_cvp_conf *conf = mgr->priv; + size_t done, remaining, len; const u32 *data; - size_t done, remaining; int status = 0; - u32 mask; /* STEP 9 - write 32-bit data from RBF file to CVP data register */ data = (u32 *)buf; remaining = count; done = 0; - while (remaining >= 4) { - conf->write_data(conf, *data++); - done += 4; - remaining -= 4; + while (remaining) { + if (remaining >= sizeof(u32)) + len = sizeof(u32); + else + len = remaining; + + altera_cvp_send_block(conf, data, len); + data++; + done += len; + remaining -= len; /* * STEP 10 (optional) and STEP 11 @@ -312,11 +337,6 @@ static int altera_cvp_write(struct fpga_manager *mgr, const char *buf, } } - /* write up to 3 trailing bytes, if any */ - mask = BIT(remaining * 8) - 1; - if (mask) - conf->write_data(conf, *data & mask); - if (altera_cvp_chkcfg) status = altera_cvp_chk_error(mgr, count); -- 2.7.4