From patchwork Tue Mar 19 11:59:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Khimich X-Patchwork-Id: 781755 Received: from mail-lf1-f44.google.com (mail-lf1-f44.google.com [209.85.167.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A2B017F478; Tue, 19 Mar 2024 11:59:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710849579; cv=none; b=uy+ZUTirlkEs1NdBEjouSBDyhYCiMZ3AvgCgtfc8YG9qLaH68CObL+J4HQhqc62ftpVTYSr7u7SbX/rJLMC/6O2yTU6Hk5YtIeuaGo0aQ5GPZtr1oqr3rnZduPvW3YmxoTj8o77oaxSIaY4x55Lf4VFvkTMTzaCUKoaqwzPEEjI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710849579; c=relaxed/simple; bh=eZ7+YWRuTJS+M+Tbb32Zj+n4QjgQnXl0BfWwdXSaSiI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=eNaBHxTS0KCEjjgDUj7rm4Y12cB/bjcgbl/IVTY2fhe8ltuVG4p8hDtm7cXzW8WKQsDgKLY3MeaLRbqfiaaM6YSD23o4TwMypVSPPHrSiX61RJjIvsEWWE/cakSuisiQWJ+2CFWp2ZaTOJJ4J4xUbeNVF+B0OhTMdOF2HQuVCh0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=AxyahYLK; arc=none smtp.client-ip=209.85.167.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="AxyahYLK" Received: by mail-lf1-f44.google.com with SMTP id 2adb3069b0e04-513da1c1f26so6266227e87.3; Tue, 19 Mar 2024 04:59:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710849575; x=1711454375; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RI1qGz8CIIXyUXChOvLqXgzJKN1FSHM3UtHTCtJhJhY=; b=AxyahYLKAxzqycXoKfcdfceihyDss5thPIWavMSTsOCZSLUWgVGkAP86VP5JxZI0LB 6FUr3SEtEYNuYwy0YHF6CJR2F8NVCqzUS+gvWWvDuAaiIQ0DkDDEMnCxCt9JeusV/DxE 2Vdkkws/b5UqtWzm+l8Wmi8OzfSqquGaK/ej1QqsQDd3UQEKFwMG0EdWsE1ZbcNG2RUc hPHIfGEG5WIcu++glYGfTQZa650OZL52QUoakVb/4V20v3ZM/oO3Tm8bIeMYN5J//C97 F+H3IhBYuLYewszKk3jVSu+AlhOKSwpEbVWPrmTPDSDlkdJMzwBe0B8e4yyZ7k056ZLS e+Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710849575; x=1711454375; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RI1qGz8CIIXyUXChOvLqXgzJKN1FSHM3UtHTCtJhJhY=; b=j+QGPsZo+HT8P1IiVZ3AfJQ+eSzo2lFSt+QmrHyk6F7i13wm9qGm+CXV7OAJoCeOAc Pvoolvr3fvM3MOKubhqRZlQH3FLrt+FxTtGM/qKLu2+GV+9aL8p74kzalkoqyJy5K0ug YoWy5GvBcz5X2u5RB4+l2sWJGJmN91JUc/Kd9mjYyV85gjX24a9YI1ELpam0U0/edeKo go1f0V/bJyVmSyg+djB5t/JgCO3EmrOh3eRz19JkJ53xiQ8Y9JebopkoXI3DGDEMxwqN /FqXGUmHl69jVXJ5tyZRrAgEy4dcfubtssd+uRcaS6ZMLn9fGqaqbN8/MKX3HGX1wVZv +Igg== X-Gm-Message-State: AOJu0Yz9u8PHhX0HGRkshRtRlmW7fDCipl9bbevs20SGpJ0ortR6YhIg 75q6XkEnsZQevDJh3v86uzWwaIwZQLWVZ4i7ZymdalsBLiUCCzTqgM9CYABuzu4= X-Google-Smtp-Source: AGHT+IH3aYI5oGqyB2XgE9DydyiTRKx+Y2yKyifpbuO4wzHv4f4LQTozvG6sgUKXSbOC2pVZV8y2JA== X-Received: by 2002:a19:8c55:0:b0:513:a1eb:c084 with SMTP id i21-20020a198c55000000b00513a1ebc084mr8865785lfj.7.1710849575314; Tue, 19 Mar 2024 04:59:35 -0700 (PDT) Received: from skhimich.dev.yadro.com (avpn01.yadro.com. [89.207.88.243]) by smtp.gmail.com with ESMTPSA id d11-20020a056512368b00b00513a53acdd4sm1915198lfs.104.2024.03.19.04.59.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 04:59:34 -0700 (PDT) From: Sergey Khimich To: linux-kernel@vger.kernel.org Cc: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter , Shawn Lin , Jyan Chou , Asutosh Das , Ritesh Harjani Subject: [PATCH v7 1/2] mmc: cqhci: Add cqhci set_tran_desc() callback Date: Tue, 19 Mar 2024 14:59:31 +0300 Message-Id: <20240319115932.4108904-2-serghox@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240319115932.4108904-1-serghox@gmail.com> References: <20240319115932.4108904-1-serghox@gmail.com> Precedence: bulk X-Mailing-List: linux-mmc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Sergey Khimich There are could be specific limitations for some mmc controllers for setting cqhci transfer descriptors. So add callback to allow implement driver specific function. Signed-off-by: Sergey Khimich --- drivers/mmc/host/cqhci-core.c | 11 ++++++++--- drivers/mmc/host/cqhci.h | 4 ++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/cqhci-core.c b/drivers/mmc/host/cqhci-core.c index 41e94cd14109..c14d7251d0bb 100644 --- a/drivers/mmc/host/cqhci-core.c +++ b/drivers/mmc/host/cqhci-core.c @@ -474,8 +474,8 @@ static int cqhci_dma_map(struct mmc_host *host, struct mmc_request *mrq) return sg_count; } -static void cqhci_set_tran_desc(u8 *desc, dma_addr_t addr, int len, bool end, - bool dma64) +void cqhci_set_tran_desc(u8 *desc, dma_addr_t addr, int len, bool end, + bool dma64) { __le32 *attr = (__le32 __force *)desc; @@ -495,6 +495,7 @@ static void cqhci_set_tran_desc(u8 *desc, dma_addr_t addr, int len, bool end, dataddr[0] = cpu_to_le32(addr); } } +EXPORT_SYMBOL(cqhci_set_tran_desc); static int cqhci_prep_tran_desc(struct mmc_request *mrq, struct cqhci_host *cq_host, int tag) @@ -522,7 +523,11 @@ static int cqhci_prep_tran_desc(struct mmc_request *mrq, if ((i+1) == sg_count) end = true; - cqhci_set_tran_desc(desc, addr, len, end, dma64); + if (cq_host->ops->set_tran_desc) + cq_host->ops->set_tran_desc(cq_host, &desc, addr, len, end, dma64); + else + cqhci_set_tran_desc(desc, addr, len, end, dma64); + desc += cq_host->trans_desc_len; } diff --git a/drivers/mmc/host/cqhci.h b/drivers/mmc/host/cqhci.h index 1a12e40a02e6..fab9d74445ba 100644 --- a/drivers/mmc/host/cqhci.h +++ b/drivers/mmc/host/cqhci.h @@ -293,6 +293,9 @@ struct cqhci_host_ops { int (*program_key)(struct cqhci_host *cq_host, const union cqhci_crypto_cfg_entry *cfg, int slot); #endif + void (*set_tran_desc)(struct cqhci_host *cq_host, u8 **desc, + dma_addr_t addr, int len, bool end, bool dma64); + }; static inline void cqhci_writel(struct cqhci_host *host, u32 val, int reg) @@ -318,6 +321,7 @@ irqreturn_t cqhci_irq(struct mmc_host *mmc, u32 intmask, int cmd_error, int cqhci_init(struct cqhci_host *cq_host, struct mmc_host *mmc, bool dma64); struct cqhci_host *cqhci_pltfm_init(struct platform_device *pdev); int cqhci_deactivate(struct mmc_host *mmc); +void cqhci_set_tran_desc(u8 *desc, dma_addr_t addr, int len, bool end, bool dma64); static inline int cqhci_suspend(struct mmc_host *mmc) { return cqhci_deactivate(mmc); From patchwork Tue Mar 19 11:59:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Khimich X-Patchwork-Id: 781275 Received: from mail-lf1-f43.google.com (mail-lf1-f43.google.com [209.85.167.43]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id CF65A7F47D; Tue, 19 Mar 2024 11:59:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.43 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710849580; cv=none; b=j2kdqAYR7x+6sYq9k0EgZW00e6R02wYMmw/2olFeFBvL02nkn9opCUHkcLW0RtT72gR/DytT73+oaCcJkTlU7OVQExtPu1IzgdpG2bGtxbIBxeHo5Is+n+o9mGkQDRRN0k9QEHMWRUKFGnPVIqzNztvOLeUvR468vslwVS9T738= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1710849580; c=relaxed/simple; bh=7mfsfsMePyU5u5hDRZdy8TuFnPPqvmVqhhU1/ivJaCs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=AbWkyNqugbSvQtTFKKPB9EArHe1tNAfSoU3HnCnKbsLvr3/Fl2AxgNGWL0vbTnAZygz0+RV471+QaZrf0qMheSpRgj9afu25XjqIczRZf4TRT70XnshjYGsx7otkvHyDizfDZqKcjM0JzJCWKilFAoyD9EPgotFFda6HiLkMf8g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=WV8EnfJx; arc=none smtp.client-ip=209.85.167.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="WV8EnfJx" Received: by mail-lf1-f43.google.com with SMTP id 2adb3069b0e04-513e14b2bd9so3624016e87.2; Tue, 19 Mar 2024 04:59:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1710849576; x=1711454376; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VUgQJSEr/+UzPYpDRAxqUU9yx+rpprq2HTDWl9Ui7HM=; b=WV8EnfJxYeaKXGehNXQ6kJWYuv+chYnBzaESB2JVHJpEULCPMuMvgfe6pJomPRlIlf 4TUtzoNu1FTF6zDyyI2MwhzIHJIHpNG59dFdr4QP8GIfppjawRHRo1sDieV6JK3W1bN9 EJotMNnEaOucXpI7vQuRfK8wcx/EKvdnL9pDqSPAThoxrhaYHD3YzAA3tpoF6KpSYUuY ro+8YNEdgcWMt1enR+gX2zNae15IVHPVDn9GiOtExD3flbV//bKg6El2T6wNyyDm6awG sz36mo4kb/AdDOnyKtELvX7/mwxPhiwM/oySAj/aBuTrZ6ctG0IlvzqkuoSDzTEBKsUD xoKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1710849576; x=1711454376; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VUgQJSEr/+UzPYpDRAxqUU9yx+rpprq2HTDWl9Ui7HM=; b=hl7LoSEiy9Gjq6ouUKwdomGtFjkeRJzbaS38VaHs75sFXZ3V4aVsVvOnP1+iDm4g/C DDAe1ubXGDqcEQHvlwfH1XGxyKRJE9hl2s+LRIhd/VOzKS5E8HZ0j+SQQywkbmkyD7sI gFn5ffc9MWyIVHY6MFjSOnFcjz88YeSNgCk36cL92PAXyVMtyT4vyVw0dQvx/NmZIjBd w43Ggm8rYw47ri9B6at6GyUiGxYD9JaFGd+704G97h03vn4MfNw7r9TaTTprArLo0/SJ EMnTKa4jpD1FkEslippQB203pEDDShTE61rxc+d5NV12kSFOapDDBhqEXT1KOUc9Go+p 5mHw== X-Gm-Message-State: AOJu0Yx9JMoxPAKcYSznrrbOXwJYIAgVhI3gAiwuegPstaqOgqvt0FA8 WLVBjssE13XUhuOlpXr/Fe4Z7cIt9uUGtd1K6qrPtq7N9mxLG9lWVEJ74WNkdXA= X-Google-Smtp-Source: AGHT+IEHVyTiOp4DrcYOSwxTKBzmkZGF7LE632vScihx5rxz+SXA9EDhM2RhezLiYw7foIZwZI3Tpg== X-Received: by 2002:ac2:5b9b:0:b0:513:d6d9:b0e7 with SMTP id o27-20020ac25b9b000000b00513d6d9b0e7mr8856109lfn.28.1710849576314; Tue, 19 Mar 2024 04:59:36 -0700 (PDT) Received: from skhimich.dev.yadro.com (avpn01.yadro.com. [89.207.88.243]) by smtp.gmail.com with ESMTPSA id d11-20020a056512368b00b00513a53acdd4sm1915198lfs.104.2024.03.19.04.59.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 19 Mar 2024 04:59:35 -0700 (PDT) From: Sergey Khimich To: linux-kernel@vger.kernel.org Cc: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter , Shawn Lin , Jyan Chou , Asutosh Das , Ritesh Harjani Subject: [PATCH v7 2/2] mmc: sdhci-of-dwcmshc: Implement SDHCI CQE support Date: Tue, 19 Mar 2024 14:59:32 +0300 Message-Id: <20240319115932.4108904-3-serghox@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20240319115932.4108904-1-serghox@gmail.com> References: <20240319115932.4108904-1-serghox@gmail.com> Precedence: bulk X-Mailing-List: linux-mmc@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 From: Sergey Khimich For enabling CQE support just set 'supports-cqe' in your DevTree file for appropriate mmc node. Signed-off-by: Sergey Khimich --- drivers/mmc/host/Kconfig | 1 + drivers/mmc/host/sdhci-of-dwcmshc.c | 191 +++++++++++++++++++++++++++- 2 files changed, 190 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig index 81f2c4e05287..554dbf7f2fa4 100644 --- a/drivers/mmc/host/Kconfig +++ b/drivers/mmc/host/Kconfig @@ -233,6 +233,7 @@ config MMC_SDHCI_OF_DWCMSHC depends on MMC_SDHCI_PLTFM depends on OF depends on COMMON_CLK + select MMC_CQHCI help This selects Synopsys DesignWare Cores Mobile Storage Controller support. diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c index a1f57af6acfb..8d6cfb648096 100644 --- a/drivers/mmc/host/sdhci-of-dwcmshc.c +++ b/drivers/mmc/host/sdhci-of-dwcmshc.c @@ -21,6 +21,7 @@ #include #include "sdhci-pltfm.h" +#include "cqhci.h" #define SDHCI_DWCMSHC_ARG2_STUFF GENMASK(31, 16) @@ -52,6 +53,9 @@ #define AT_CTRL_SWIN_TH_VAL_MASK GENMASK(31, 24) /* bits [31:24] */ #define AT_CTRL_SWIN_TH_VAL 0x9 /* sampling window threshold */ +/* DWC IP vendor area 2 pointer */ +#define DWCMSHC_P_VENDOR_AREA2 0xea + /* Rockchip specific Registers */ #define DWCMSHC_EMMC_DLL_CTRL 0x800 #define DWCMSHC_EMMC_DLL_RXCLK 0x804 @@ -167,6 +171,10 @@ #define BOUNDARY_OK(addr, len) \ ((addr | (SZ_128M - 1)) == ((addr + len - 1) | (SZ_128M - 1))) +#define DWCMSHC_SDHCI_CQE_TRNS_MODE (SDHCI_TRNS_MULTI | \ + SDHCI_TRNS_BLK_CNT_EN | \ + SDHCI_TRNS_DMA) + enum dwcmshc_rk_type { DWCMSHC_RK3568, DWCMSHC_RK3588, @@ -182,7 +190,9 @@ struct rk35xx_priv { struct dwcmshc_priv { struct clk *bus_clk; - int vendor_specific_area1; /* P_VENDOR_SPECIFIC_AREA reg */ + int vendor_specific_area1; /* P_VENDOR_SPECIFIC_AREA1 reg */ + int vendor_specific_area2; /* P_VENDOR_SPECIFIC_AREA2 reg */ + void *priv; /* pointer to SoC private stuff */ u16 delay_line; u16 flags; @@ -441,6 +451,90 @@ static void dwcmshc_hs400_enhanced_strobe(struct mmc_host *mmc, sdhci_writel(host, vendor, reg); } +static int dwcmshc_execute_tuning(struct mmc_host *mmc, u32 opcode) +{ + int err = sdhci_execute_tuning(mmc, opcode); + struct sdhci_host *host = mmc_priv(mmc); + + if (err) + return err; + + /* + * Tuning can leave the IP in an active state (Buffer Read Enable bit + * set) which prevents the entry to low power states (i.e. S0i3). Data + * reset will clear it. + */ + sdhci_reset(host, SDHCI_RESET_DATA); + + return 0; +} + +static u32 dwcmshc_cqe_irq_handler(struct sdhci_host *host, u32 intmask) +{ + int cmd_error = 0; + int data_error = 0; + + if (!sdhci_cqe_irq(host, intmask, &cmd_error, &data_error)) + return intmask; + + cqhci_irq(host->mmc, intmask, cmd_error, data_error); + + return 0; +} + +static void dwcmshc_sdhci_cqe_enable(struct mmc_host *mmc) +{ + struct sdhci_host *host = mmc_priv(mmc); + u8 ctrl; + + sdhci_writew(host, DWCMSHC_SDHCI_CQE_TRNS_MODE, SDHCI_TRANSFER_MODE); + + sdhci_cqe_enable(mmc); + + /* + * The "DesignWare Cores Mobile Storage Host Controller + * DWC_mshc / DWC_mshc_lite Databook" says: + * when Host Version 4 Enable" is 1 in Host Control 2 register, + * SDHCI_CTRL_ADMA32 bit means ADMA2 is selected. + * Selection of 32-bit/64-bit System Addressing: + * either 32-bit or 64-bit system addressing is selected by + * 64-bit Addressing bit in Host Control 2 register. + * + * On the other hand the "DesignWare Cores Mobile Storage Host + * Controller DWC_mshc / DWC_mshc_lite User Guide" says, that we have to + * set DMA_SEL to ADMA2 _only_ mode in the Host Control 2 register. + */ + ctrl = sdhci_readb(host, SDHCI_HOST_CONTROL); + ctrl &= ~SDHCI_CTRL_DMA_MASK; + ctrl |= SDHCI_CTRL_ADMA32; + sdhci_writeb(host, ctrl, SDHCI_HOST_CONTROL); +} + +static void dwcmshc_set_tran_desc(struct cqhci_host *cq_host, u8 **desc, + dma_addr_t addr, int len, bool end, bool dma64) +{ + int tmplen, offset; + + if (likely(!len || BOUNDARY_OK(addr, len))) { + cqhci_set_tran_desc(*desc, addr, len, end, dma64); + return; + } + + offset = addr & (SZ_128M - 1); + tmplen = SZ_128M - offset; + cqhci_set_tran_desc(*desc, addr, tmplen, false, dma64); + + addr += tmplen; + len -= tmplen; + *desc += cq_host->trans_desc_len; + cqhci_set_tran_desc(*desc, addr, len, end, dma64); +} + +static void dwcmshc_cqhci_dumpregs(struct mmc_host *mmc) +{ + sdhci_dumpregs(mmc_priv(mmc)); +} + static void dwcmshc_rk3568_set_clock(struct sdhci_host *host, unsigned int clock) { struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); @@ -649,6 +743,7 @@ static const struct sdhci_ops sdhci_dwcmshc_ops = { .get_max_clock = dwcmshc_get_max_clock, .reset = sdhci_reset, .adma_write_desc = dwcmshc_adma_write_desc, + .irq = dwcmshc_cqe_irq_handler, }; static const struct sdhci_ops sdhci_dwcmshc_rk35xx_ops = { @@ -700,6 +795,73 @@ static const struct sdhci_pltfm_data sdhci_dwcmshc_th1520_pdata = { .quirks2 = SDHCI_QUIRK2_PRESET_VALUE_BROKEN, }; +static const struct cqhci_host_ops dwcmshc_cqhci_ops = { + .enable = dwcmshc_sdhci_cqe_enable, + .disable = sdhci_cqe_disable, + .dumpregs = dwcmshc_cqhci_dumpregs, + .set_tran_desc = dwcmshc_set_tran_desc, +}; + +static void dwcmshc_cqhci_init(struct sdhci_host *host, struct platform_device *pdev) +{ + struct cqhci_host *cq_host; + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); + struct dwcmshc_priv *priv = sdhci_pltfm_priv(pltfm_host); + bool dma64 = false; + u16 clk; + int err; + + host->mmc->caps2 |= MMC_CAP2_CQE | MMC_CAP2_CQE_DCMD; + cq_host = devm_kzalloc(&pdev->dev, sizeof(*cq_host), GFP_KERNEL); + if (!cq_host) { + dev_err(mmc_dev(host->mmc), "Unable to setup CQE: not enough memory\n"); + goto dsbl_cqe_caps; + } + + /* + * For dwcmshc host controller we have to enable internal clock + * before access to some registers from Vendor Specific Area 2. + */ + clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); + clk |= SDHCI_CLOCK_INT_EN; + sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); + clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); + if (!(clk & SDHCI_CLOCK_INT_EN)) { + dev_err(mmc_dev(host->mmc), "Unable to setup CQE: internal clock enable error\n"); + goto free_cq_host; + } + + cq_host->mmio = host->ioaddr + priv->vendor_specific_area2; + cq_host->ops = &dwcmshc_cqhci_ops; + + /* Enable using of 128-bit task descriptors */ + dma64 = host->flags & SDHCI_USE_64_BIT_DMA; + if (dma64) { + dev_dbg(mmc_dev(host->mmc), "128-bit task descriptors\n"); + cq_host->caps |= CQHCI_TASK_DESC_SZ_128; + } + err = cqhci_init(cq_host, host->mmc, dma64); + if (err) { + dev_err(mmc_dev(host->mmc), "Unable to setup CQE: error %d\n", err); + goto int_clock_disable; + } + + dev_dbg(mmc_dev(host->mmc), "CQE init done\n"); + + return; + +int_clock_disable: + clk = sdhci_readw(host, SDHCI_CLOCK_CONTROL); + clk &= ~SDHCI_CLOCK_INT_EN; + sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); + +free_cq_host: + devm_kfree(&pdev->dev, cq_host); + +dsbl_cqe_caps: + host->mmc->caps2 &= ~(MMC_CAP2_CQE | MMC_CAP2_CQE_DCMD); +} + static int dwcmshc_rk35xx_init(struct sdhci_host *host, struct dwcmshc_priv *dwc_priv) { int err; @@ -796,7 +958,7 @@ static int dwcmshc_probe(struct platform_device *pdev) struct rk35xx_priv *rk_priv = NULL; const struct sdhci_pltfm_data *pltfm_data; int err; - u32 extra; + u32 extra, caps; pltfm_data = device_get_match_data(&pdev->dev); if (!pltfm_data) { @@ -847,6 +1009,7 @@ static int dwcmshc_probe(struct platform_device *pdev) host->mmc_host_ops.request = dwcmshc_request; host->mmc_host_ops.hs400_enhanced_strobe = dwcmshc_hs400_enhanced_strobe; + host->mmc_host_ops.execute_tuning = dwcmshc_execute_tuning; if (pltfm_data == &sdhci_dwcmshc_rk35xx_pdata) { rk_priv = devm_kzalloc(&pdev->dev, sizeof(struct rk35xx_priv), GFP_KERNEL); @@ -896,6 +1059,10 @@ static int dwcmshc_probe(struct platform_device *pdev) sdhci_enable_v4_mode(host); #endif + caps = sdhci_readl(host, SDHCI_CAPABILITIES); + if (caps & SDHCI_CAN_64BIT_V4) + sdhci_enable_v4_mode(host); + host->mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY; pm_runtime_get_noresume(dev); @@ -906,6 +1073,14 @@ static int dwcmshc_probe(struct platform_device *pdev) if (err) goto err_rpm; + /* Setup Command Queue Engine if enabled */ + if (device_property_read_bool(&pdev->dev, "supports-cqe")) { + priv->vendor_specific_area2 = + sdhci_readw(host, DWCMSHC_P_VENDOR_AREA2); + + dwcmshc_cqhci_init(host, pdev); + } + if (rk_priv) dwcmshc_rk35xx_postinit(host, priv); @@ -961,6 +1136,12 @@ static int dwcmshc_suspend(struct device *dev) pm_runtime_resume(dev); + if (host->mmc->caps2 & MMC_CAP2_CQE) { + ret = cqhci_suspend(host->mmc); + if (ret) + return ret; + } + ret = sdhci_suspend_host(host); if (ret) return ret; @@ -1005,6 +1186,12 @@ static int dwcmshc_resume(struct device *dev) if (ret) goto disable_rockchip_clks; + if (host->mmc->caps2 & MMC_CAP2_CQE) { + ret = cqhci_resume(host->mmc); + if (ret) + goto disable_rockchip_clks; + } + return 0; disable_rockchip_clks: