From patchwork Mon Mar 27 19:57:11 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Heiner Kallweit X-Patchwork-Id: 9647423 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 30DA2601D7 for ; Mon, 27 Mar 2017 19:57:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B22D28334 for ; Mon, 27 Mar 2017 19:57:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0F17428435; Mon, 27 Mar 2017 19:57:23 +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.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID 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 AE4DF28334 for ; Mon, 27 Mar 2017 19:57:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751785AbdC0T5W (ORCPT ); Mon, 27 Mar 2017 15:57:22 -0400 Received: from mail-wr0-f194.google.com ([209.85.128.194]:33408 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751651AbdC0T5V (ORCPT ); Mon, 27 Mar 2017 15:57:21 -0400 Received: by mail-wr0-f194.google.com with SMTP id 20so16415966wrx.0 for ; Mon, 27 Mar 2017 12:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=to:cc:from:subject:message-id:date:user-agent:mime-version :content-transfer-encoding; bh=KMM2BMwaySWmyVaVAm31cXgCxy59IN4IbSutxDkgQF0=; b=LPlVGrJPjabrxnnjHZYsezpC9vMOz+SRkCUhZBtktZaGzii6YpgnSBMY2WS44A8hhq MpToZ61VOyYlLlw3E2V9aPFwBltMCfBNKYYUaHq7HzWge51uhb2rqcqsGNcDOiCIMmxB qVFaRVyF5TsN4RgDUcLNxA/pehF1IU6Mbb1/otEjnweLUJRwmfzQxnA1IVfLIt7kRS4i NrZIqmlQudPnvwoHcMh/0UlfLYeL/Zo8xQiSf30hJ5DtBR2m8bsfSj+tJInMBgO279mc 1MhDJmhYPeDrhtm9um3lP6gjAYEangMU2NWoDk0eE/sS7SueYPhdeqttdMPyPhdYsigR wMYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:to:cc:from:subject:message-id:date:user-agent :mime-version:content-transfer-encoding; bh=KMM2BMwaySWmyVaVAm31cXgCxy59IN4IbSutxDkgQF0=; b=K1ll5vJZifJpHGayRDbz8IrsoptySfuaepiCTP8F79VLIUqAXrhOeBzjBg7bmpIPxo OAR/w3+oFo2Fr39BVdPwxf/UYf36V7GgPWZH3vN2qv6PLEly9Sr48NB6CWOhc7BBHD4w Cu21Bpp7pa2d+06q2lZ+rQOf4cWV+ogU8C83FpoC/KeYS9U2l/IGNWBbZPOGhyeThiJd 2KQh8jYBdJJG47GNtkw1RO46Q3vYYn1ecS3U+rbLNf0Q3oM1efixbzH3T0OnD2jNSApo N/gm89SDjo/y6Ege9j05gbqvFnCJFrctdLSTtEfJi12rp4jQ0w/+xIMBdGLbnjoGDDMe Kv6Q== X-Gm-Message-State: AFeK/H1/OENQmigqXBJAEZlOMm0401gvIOBmiBY0IytzhIl0RCxQXsizff4ZGLTkqtBmYA== X-Received: by 10.28.126.133 with SMTP id z127mr11450647wmc.60.1490644639501; Mon, 27 Mar 2017 12:57:19 -0700 (PDT) Received: from ?IPv6:2003:c6:ebdc:4000:9598:a7fc:fe65:51e7? (p200300C6EBDC40009598A7FCFE6551E7.dip0.t-ipconnect.de. [2003:c6:ebdc:4000:9598:a7fc:fe65:51e7]) by smtp.googlemail.com with ESMTPSA id h187sm695725wma.32.2017.03.27.12.57.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Mar 2017 12:57:19 -0700 (PDT) To: Ulf Hansson , Kevin Hilman Cc: "linux-mmc@vger.kernel.org" , linux-amlogic@lists.infradead.org From: Heiner Kallweit Subject: [PATCH 1/2] mmc: meson-gx: factor out setting block size Message-ID: Date: Mon, 27 Mar 2017 21:57:11 +0200 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Factor out setting the block size. This also contributes to reducing complexity of function meson_mmc_start_cmd. Signed-off-by: Heiner Kallweit Reviewed-by: Kevin Hilman --- drivers/mmc/host/meson-gx-mmc.c | 42 ++++++++++++++++++++++++++--------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/drivers/mmc/host/meson-gx-mmc.c b/drivers/mmc/host/meson-gx-mmc.c index f5dd5cc7..0de32008 100644 --- a/drivers/mmc/host/meson-gx-mmc.c +++ b/drivers/mmc/host/meson-gx-mmc.c @@ -431,12 +431,36 @@ static void meson_mmc_request_done(struct mmc_host *mmc, mmc_request_done(host->mmc, mrq); } +static void meson_mmc_set_blksz(struct mmc_host *mmc, unsigned int blksz) +{ + struct meson_host *host = mmc_priv(mmc); + u32 cfg, blksz_old; + + cfg = readl(host->regs + SD_EMMC_CFG); + blksz_old = FIELD_GET(CFG_BLK_LEN_MASK, cfg); + + if (!is_power_of_2(blksz)) + dev_err(host->dev, "blksz %u is not a power of 2\n", blksz); + + blksz = ilog2(blksz); + + /* check if block-size matches, if not update */ + if (blksz == blksz_old) + return; + + dev_dbg(host->dev, "%s: update blk_len %d -> %d\n", __func__, + blksz_old, blksz); + + cfg &= ~CFG_BLK_LEN_MASK; + cfg |= FIELD_PREP(CFG_BLK_LEN_MASK, blksz); + writel(cfg, host->regs + SD_EMMC_CFG); +} + static void meson_mmc_start_cmd(struct mmc_host *mmc, struct mmc_command *cmd) { struct meson_host *host = mmc_priv(mmc); struct mmc_data *data = cmd->data; - u32 cfg, cmd_cfg = 0, cmd_data = 0; - u8 blk_len; + u32 cmd_cfg = 0, cmd_data = 0; unsigned int xfer_bytes = 0; /* Setup descriptors */ @@ -470,19 +494,7 @@ static void meson_mmc_start_cmd(struct mmc_host *mmc, struct mmc_command *cmd) cmd_cfg |= CMD_CFG_BLOCK_MODE; cmd_cfg |= FIELD_PREP(CMD_CFG_LENGTH_MASK, data->blocks); - - /* check if block-size matches, if not update */ - cfg = readl(host->regs + SD_EMMC_CFG); - blk_len = FIELD_GET(CFG_BLK_LEN_MASK, cfg); - if (blk_len != ilog2(data->blksz)) { - dev_dbg(host->dev, "%s: update blk_len %d -> %d\n", - __func__, blk_len, - ilog2(data->blksz)); - blk_len = ilog2(data->blksz); - cfg &= ~CFG_BLK_LEN_MASK; - cfg |= FIELD_PREP(CFG_BLK_LEN_MASK, blk_len); - writel(cfg, host->regs + SD_EMMC_CFG); - } + meson_mmc_set_blksz(mmc, data->blksz); } else { cmd_cfg |= FIELD_PREP(CMD_CFG_LENGTH_MASK, data->blksz); }