From patchwork Mon Apr 21 21:47:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 28735 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yh0-f71.google.com (mail-yh0-f71.google.com [209.85.213.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7EA2A2032B for ; Mon, 21 Apr 2014 21:48:18 +0000 (UTC) Received: by mail-yh0-f71.google.com with SMTP id a41sf25009427yho.10 for ; Mon, 21 Apr 2014 14:48:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=tQIu5r14G5aO5WeVeqw1nqT1Bdn+vtzvatMRqiEV39Q=; b=QxfjDZPOL/q8lQ1Og6hbh58MW2pSeDqehSCmQjr3jkNiJmdGAKqOiunN3zhA4wCiHA 2rvut3dFGA1lRDca9qeA2zS318Yf3/kxKOgAT0EWLUV43X/8g+3afe5NjJhzrfMvuOsb en4EIi3bVp/e/PBNJYAYSQ8EKqSOpLW7pAQstd/Rj0slmv2F8f2ZlH87pE83MGwSs+d7 c/aK/JVKYVqwEMeddgRv7oazTZAVM7opThUKVALcutVRS9RjlzwnM8vUcUfBNz3ZdKLp Q+hiBuKg+7DY1a1HtfCI3KPnBMzTIMbnJfNsHyW6Ddw1qzc4sc6ehWThAKLTDfp04OAZ 3bbg== X-Gm-Message-State: ALoCoQmSZ/PmBk5mHHLKc/oOXR6zCMUZP5mgEY7nOnx7opyjUMFAzJysX6letCJUEcBNX7S05MiG X-Received: by 10.236.210.48 with SMTP id t36mr16861453yho.44.1398116897972; Mon, 21 Apr 2014 14:48:17 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.108.72 with SMTP id i66ls1246831qgf.78.gmail; Mon, 21 Apr 2014 14:48:17 -0700 (PDT) X-Received: by 10.58.13.104 with SMTP id g8mr32253187vec.16.1398116897817; Mon, 21 Apr 2014 14:48:17 -0700 (PDT) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id q1si6466116ves.117.2014.04.21.14.48.17 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Apr 2014 14:48:17 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id jx11so8761475veb.3 for ; Mon, 21 Apr 2014 14:48:17 -0700 (PDT) X-Received: by 10.52.189.193 with SMTP id gk1mr10554481vdc.12.1398116897722; Mon, 21 Apr 2014 14:48:17 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp320760vcb; Mon, 21 Apr 2014 14:48:17 -0700 (PDT) X-Received: by 10.66.121.131 with SMTP id lk3mr40395743pab.61.1398116896907; Mon, 21 Apr 2014 14:48:16 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id px1si9677520pbb.499.2014.04.21.14.48.16; Mon, 21 Apr 2014 14:48:16 -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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754839AbaDUVsG (ORCPT + 26 others); Mon, 21 Apr 2014 17:48:06 -0400 Received: from mail-wg0-f45.google.com ([74.125.82.45]:39249 "EHLO mail-wg0-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754806AbaDUVrz (ORCPT ); Mon, 21 Apr 2014 17:47:55 -0400 Received: by mail-wg0-f45.google.com with SMTP id l18so3085158wgh.28 for ; Mon, 21 Apr 2014 14:47:53 -0700 (PDT) X-Received: by 10.180.12.206 with SMTP id a14mr1348814wic.48.1398116873908; Mon, 21 Apr 2014 14:47:53 -0700 (PDT) Received: from srinivas-Inspiron-N5050.dlink.com (host-78-149-8-254.as13285.net. [78.149.8.254]) by mx.google.com with ESMTPSA id be3sm58837726wjc.5.2014.04.21.14.47.52 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 21 Apr 2014 14:47:53 -0700 (PDT) From: srinivas.kandagatla@linaro.org To: linux-mmc@vger.kernel.org Cc: Russell King , Chris Ball , Ulf Hansson , linux-kernel@vger.kernel.org, agross@quicinc.com, linux-arm-msm@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH RFC 04/12] mmc: mmci: Add register read/write wrappers. Date: Mon, 21 Apr 2014 22:47:46 +0100 Message-Id: <1398116866-31357-1-git-send-email-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1398116624-31052-1-git-send-email-srinivas.kandagatla@linaro.org> References: <1398116624-31052-1-git-send-email-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: srinivas.kandagatla@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Srinivas Kandagatla This patch adds wrappers for readl/writel functions used in the driver. The reason for this wrappers is to accommodate SOCs like Qualcomm which has requirement for delaying the write for few cycles when writing to its SD Card Controller registers. Signed-off-by: Srinivas Kandagatla --- drivers/mmc/host/mmci.c | 114 +++++++++++++++++++++++++---------------------- 1 file changed, 61 insertions(+), 53 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 19d6b6f..36db31e 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -171,6 +171,16 @@ static struct variant_data variant_qcom = { .pwrreg_powerup = MCI_PWR_UP, }; +static inline u32 mmci_readl(struct mmci_host *host, u32 off) +{ + return readl(host->base + off); +} + +static inline void mmci_writel(struct mmci_host *host, u32 data, u32 off) +{ + writel(data, host->base + off); +} + static int mmci_card_busy(struct mmc_host *mmc) { struct mmci_host *host = mmc_priv(mmc); @@ -180,7 +190,7 @@ static int mmci_card_busy(struct mmc_host *mmc) pm_runtime_get_sync(mmc_dev(mmc)); spin_lock_irqsave(&host->lock, flags); - if (readl(host->base + MMCISTATUS) & MCI_ST_CARDBUSY) + if (mmci_readl(host, MMCISTATUS) & MCI_ST_CARDBUSY) busy = 1; spin_unlock_irqrestore(&host->lock, flags); @@ -230,7 +240,7 @@ static void mmci_write_clkreg(struct mmci_host *host, u32 clk) { if (host->clk_reg != clk) { host->clk_reg = clk; - writel(clk, host->base + MMCICLOCK); + mmci_writel(host, clk, MMCICLOCK); } } @@ -241,7 +251,7 @@ static void mmci_write_pwrreg(struct mmci_host *host, u32 pwr) { if (host->pwr_reg != pwr) { host->pwr_reg = pwr; - writel(pwr, host->base + MMCIPOWER); + mmci_writel(host, pwr, MMCIPOWER); } } @@ -255,7 +265,7 @@ static void mmci_write_datactrlreg(struct mmci_host *host, u32 datactrl) if (host->datactrl_reg != datactrl) { host->datactrl_reg = datactrl; - writel(datactrl, host->base + MMCIDATACTRL); + mmci_writel(host, datactrl, MMCIDATACTRL); } } @@ -321,7 +331,7 @@ static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired) static void mmci_request_end(struct mmci_host *host, struct mmc_request *mrq) { - writel(0, host->base + MMCICOMMAND); + mmci_writel(host, 0, MMCICOMMAND); BUG_ON(host->data); @@ -336,18 +346,16 @@ mmci_request_end(struct mmci_host *host, struct mmc_request *mrq) static void mmci_set_mask1(struct mmci_host *host, unsigned int mask) { - void __iomem *base = host->base; - if (host->singleirq) { - unsigned int mask0 = readl(base + MMCIMASK0); + unsigned int mask0 = mmci_readl(host, MMCIMASK0); mask0 &= ~MCI_IRQ1MASK; mask0 |= mask; - writel(mask0, base + MMCIMASK0); + mmci_writel(host, mask0, MMCIMASK0); } - writel(mask, base + MMCIMASK1); + mmci_writel(host, mask, MMCIMASK1); } static void mmci_stop_data(struct mmci_host *host) @@ -498,7 +506,7 @@ static void mmci_dma_finalize(struct mmci_host *host, struct mmc_data *data) /* Wait up to 1ms for the DMA to complete */ for (i = 0; ; i++) { - status = readl(host->base + MMCISTATUS); + status = mmci_readl(host, MMCISTATUS); if (!(status & MCI_RXDATAAVLBLMASK) || i >= 100) break; udelay(10); @@ -637,8 +645,8 @@ static int mmci_dma_start_data(struct mmci_host *host, unsigned int datactrl) * to fire next DMA request. When that happens, MMCI will * call mmci_data_end() */ - writel(readl(host->base + MMCIMASK0) | MCI_DATAENDMASK, - host->base + MMCIMASK0); + mmci_writel(host, mmci_readl(host, MMCIMASK0) | MCI_DATAENDMASK, + MMCIMASK0); return 0; } @@ -756,8 +764,8 @@ static void mmci_start_data(struct mmci_host *host, struct mmc_data *data) timeout = data->timeout_clks + (unsigned int)clks; base = host->base; - writel(timeout, base + MMCIDATATIMER); - writel(host->size, base + MMCIDATALENGTH); + mmci_writel(host, timeout, MMCIDATATIMER); + mmci_writel(host, host->size, MMCIDATALENGTH); blksz_bits = ffs(data->blksz) - 1; BUG_ON(1 << blksz_bits != data->blksz); @@ -831,20 +839,19 @@ static void mmci_start_data(struct mmci_host *host, struct mmc_data *data) } mmci_write_datactrlreg(host, datactrl); - writel(readl(base + MMCIMASK0) & ~MCI_DATAENDMASK, base + MMCIMASK0); + mmci_writel(host, mmci_readl(host, MMCIMASK0) & ~MCI_DATAENDMASK, + MMCIMASK0); mmci_set_mask1(host, irqmask); } static void mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c) { - void __iomem *base = host->base; - dev_dbg(mmc_dev(host->mmc), "op %02x arg %08x flags %08x\n", cmd->opcode, cmd->arg, cmd->flags); - if (readl(base + MMCICOMMAND) & MCI_CPSM_ENABLE) { - writel(0, base + MMCICOMMAND); + if (mmci_readl(host, MMCICOMMAND) & MCI_CPSM_ENABLE) { + mmci_writel(host, 0, MMCICOMMAND); udelay(1); } @@ -859,8 +866,8 @@ mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c) host->cmd = cmd; - writel(cmd->arg, base + MMCIARGUMENT); - writel(c, base + MMCICOMMAND); + mmci_writel(host, cmd->arg, MMCIARGUMENT); + mmci_writel(host, c, MMCICOMMAND); } static void @@ -885,7 +892,7 @@ mmci_data_irq(struct mmci_host *host, struct mmc_data *data, * can be as much as a FIFO-worth of data ahead. This * matters for FIFO overruns only. */ - remain = readl(host->base + MMCIDATACNT); + remain = mmci_readl(host, MMCIDATACNT); success = data->blksz * data->blocks - remain; dev_dbg(mmc_dev(host->mmc), "MCI ERROR IRQ, status 0x%08x at 0x%08x\n", @@ -967,10 +974,10 @@ mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd, } else if (status & MCI_CMDCRCFAIL && cmd->flags & MMC_RSP_CRC) { cmd->error = -EILSEQ; } else { - cmd->resp[0] = readl(base + MMCIRESPONSE0); - cmd->resp[1] = readl(base + MMCIRESPONSE1); - cmd->resp[2] = readl(base + MMCIRESPONSE2); - cmd->resp[3] = readl(base + MMCIRESPONSE3); + cmd->resp[0] = mmci_readl(host, MMCIRESPONSE0); + cmd->resp[1] = mmci_readl(host, MMCIRESPONSE1); + cmd->resp[2] = mmci_readl(host, MMCIRESPONSE2); + cmd->resp[3] = mmci_readl(host, MMCIRESPONSE3); } if ((!sbc && !cmd->data) || cmd->error) { @@ -1081,11 +1088,10 @@ static irqreturn_t mmci_pio_irq(int irq, void *dev_id) struct mmci_host *host = dev_id; struct sg_mapping_iter *sg_miter = &host->sg_miter; struct variant_data *variant = host->variant; - void __iomem *base = host->base; unsigned long flags; u32 status; - status = readl(base + MMCISTATUS); + status = mmci_readl(host, MMCISTATUS); dev_dbg(mmc_dev(host->mmc), "irq1 (pio) %08x\n", status); @@ -1125,7 +1131,7 @@ static irqreturn_t mmci_pio_irq(int irq, void *dev_id) if (remain) break; - status = readl(base + MMCISTATUS); + status = mmci_readl(host, MMCISTATUS); } while (1); sg_miter_stop(sg_miter); @@ -1147,7 +1153,9 @@ static irqreturn_t mmci_pio_irq(int irq, void *dev_id) */ if (host->size == 0) { mmci_set_mask1(host, 0); - writel(readl(base + MMCIMASK0) | MCI_DATAENDMASK, base + MMCIMASK0); + mmci_writel(host, + mmci_readl(host, MMCIMASK0) | MCI_DATAENDMASK, + MMCIMASK0); } return IRQ_HANDLED; @@ -1168,10 +1176,10 @@ static irqreturn_t mmci_irq(int irq, void *dev_id) struct mmc_command *cmd; struct mmc_data *data; - status = readl(host->base + MMCISTATUS); + status = mmci_readl(host, MMCISTATUS); if (host->singleirq) { - if (status & readl(host->base + MMCIMASK1)) + if (status & mmci_readl(host, MMCIMASK1)) mmci_pio_irq(irq, dev_id); status &= ~MCI_IRQ1MASK; @@ -1182,8 +1190,8 @@ static irqreturn_t mmci_irq(int irq, void *dev_id) * enabled) since the HW seems to be triggering the IRQ on both * edges while monitoring DAT0 for busy completion. */ - status &= readl(host->base + MMCIMASK0); - writel(status, host->base + MMCICLEAR); + status &= mmci_readl(host, MMCIMASK0); + mmci_writel(host, status, MMCICLEAR); dev_dbg(mmc_dev(host->mmc), "irq0 (data+cmd) %08x\n", status); @@ -1627,9 +1635,9 @@ static int mmci_probe(struct amba_device *dev, spin_lock_init(&host->lock); - writel(0, host->base + MMCIMASK0); - writel(0, host->base + MMCIMASK1); - writel(0xfff, host->base + MMCICLEAR); + mmci_writel(host, 0, MMCIMASK0); + mmci_writel(host, 0, MMCIMASK1); + mmci_writel(host, 0xfff, MMCICLEAR); if (plat->gpio_cd == -EPROBE_DEFER) { ret = -EPROBE_DEFER; @@ -1689,7 +1697,7 @@ static int mmci_probe(struct amba_device *dev, goto irq0_free; } - writel(MCI_IRQENABLE, host->base + MMCIMASK0); + mmci_writel(host, MCI_IRQENABLE, MMCIMASK0); amba_set_drvdata(dev, mmc); @@ -1745,11 +1753,11 @@ static int mmci_remove(struct amba_device *dev) mmc_remove_host(mmc); - writel(0, host->base + MMCIMASK0); - writel(0, host->base + MMCIMASK1); + mmci_writel(host, 0, MMCIMASK0); + mmci_writel(host, 0, MMCIMASK1); - writel(0, host->base + MMCICOMMAND); - writel(0, host->base + MMCIDATACTRL); + mmci_writel(host, 0, MMCICOMMAND); + mmci_writel(host, 0, MMCIDATACTRL); mmci_dma_release(host); free_irq(dev->irq[0], host); @@ -1783,7 +1791,7 @@ static int mmci_suspend(struct device *dev) if (mmc) { struct mmci_host *host = mmc_priv(mmc); pm_runtime_get_sync(dev); - writel(0, host->base + MMCIMASK0); + mmci_writel(host, 0, MMCIMASK0); } return 0; @@ -1796,7 +1804,7 @@ static int mmci_resume(struct device *dev) if (mmc) { struct mmci_host *host = mmc_priv(mmc); - writel(MCI_IRQENABLE, host->base + MMCIMASK0); + mmci_writel(host, MCI_IRQENABLE, MMCIMASK0); pm_runtime_put(dev); } @@ -1812,10 +1820,10 @@ static void mmci_save(struct mmci_host *host) if (host->variant->pwrreg_nopower) { spin_lock_irqsave(&host->lock, flags); - writel(0, host->base + MMCIMASK0); - writel(0, host->base + MMCIDATACTRL); - writel(0, host->base + MMCIPOWER); - writel(0, host->base + MMCICLOCK); + mmci_writel(host, 0, MMCIMASK0); + mmci_writel(host, 0, MMCIDATACTRL); + mmci_writel(host, 0, MMCIPOWER); + mmci_writel(host, 0, MMCICLOCK); mmci_reg_delay(host); spin_unlock_irqrestore(&host->lock, flags); @@ -1830,10 +1838,10 @@ static void mmci_restore(struct mmci_host *host) if (host->variant->pwrreg_nopower) { spin_lock_irqsave(&host->lock, flags); - writel(host->clk_reg, host->base + MMCICLOCK); - writel(host->datactrl_reg, host->base + MMCIDATACTRL); - writel(host->pwr_reg, host->base + MMCIPOWER); - writel(MCI_IRQENABLE, host->base + MMCIMASK0); + mmci_writel(host, host->clk_reg, MMCICLOCK); + mmci_writel(host, host->datactrl_reg, MMCIDATACTRL); + mmci_writel(host, host->pwr_reg, MMCIPOWER); + mmci_writel(host, MCI_IRQENABLE, MMCIMASK0); mmci_reg_delay(host); spin_unlock_irqrestore(&host->lock, flags);