From nobody Sat Nov 30 01:50:06 2024 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 527291D88CE; Fri, 13 Sep 2024 10:29:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223392; cv=none; b=uEQ2KOGsfJc67t4D+hDJ/CN3EMcnr8mZkXXH1L6aJGo6fVJ29Tw3lZnnBGucJoNYULRp6wCBoAVPrk2cJqDDLxSrimeGc/W0paR0kh8Re9fH4c8iIMM8t88h1j9T04wxZAZUbqcqG92g5BsvTEQybtCAhYZUdmftSG4E+VrWt5k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223392; c=relaxed/simple; bh=/JGGu5nDYI0vbIjPMjEZXEoUudVSjlnLNyEB4KbX6lc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=S/k14ZbPgUl5Al5fIgRbcaEjGtIz5eru3B4NEwhuxJegS4KhYoEQpVOCyLJYpcNPz3SNbtNmJxCnRowOFZ0nomxdo9mox+cRkyWtX30wPrnWYazmrNpmqB+JLzC47C7UcSnfE9ST1n06HDtg7dmMroo0LIMmDCC4JVM/9RLXYRE= 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=B3WHzZ5B; arc=none smtp.client-ip=209.85.210.174 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="B3WHzZ5B" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-718d91eef2eso1272988b3a.1; Fri, 13 Sep 2024 03:29:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223389; x=1726828189; 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=bRxYP/3L9etmG5st97ljUDA62zSBZ2TyFV2jG4B0Jn8=; b=B3WHzZ5B0ER5tI6XRu6rsbsYy2Jz5jD109W634PC/6wYP7EiMYHkxabaaFCON38snG k4WAmKYX923PjPDv8X4UMIOZ0z2TyHi2p7DN7rJr24ql/e69oDR227WfFUrVos7mOcjP W86YFFd560u8bLU5MZIwx9aSxmKTIDeF13cfNz+2MXNLeHWUGyP3vGmS16bLAiLNl3hY PwC/pX3WrP1Ycd1zdXWY2e2h7KarrZfg1RLxCEcOMALjq5zNMOSCUrn94fOqznGu3SV+ e9pEs6pvw0dfzRzlb3ypmILytf4/UYZOAT9ExoIMQiP4GKGCB3cloRu3308zfjl8xAB3 k12Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223389; x=1726828189; 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=bRxYP/3L9etmG5st97ljUDA62zSBZ2TyFV2jG4B0Jn8=; b=xVZxRnge85c+e0DDnEwdfxee+G41SciW9zQK6eX0ULigpo9phjKBPCh/hARZSO99pJ cC+4o5UrC21cXYXd80tq2tbzwzn1Ta4ijlS+n6AVZJZXc9DTTgVCNpFiWvNUZycszPIe aTLobJZOn5ppxYlbxHPbkgzjzNW3dIi37SOwgVpNVPf4v71UwInevQJA8XeAuqn2hnrM I5Se34O7OxqwClqlkudPrMN8Ejpf8L18ywmy0h1FZm2qnVc4duUg4Yt67miYDVeurB73 EHc62xVCkaC84KKq2S6qDtBlaw2dqZDeVARiFace8POcvZ0bS0BIgIhp6MG30M7NU/cB nevQ== X-Forwarded-Encrypted: i=1; AJvYcCW5gRJpLOyottueCQQcYusLGqLVp/xezFY5/tRvMgmdB77IKzo7QIxzOg7ml5WHNbAJfMz2EcAi96foY00=@vger.kernel.org X-Gm-Message-State: AOJu0YwpEW5vmuWzUIWmxvz2t4o8os9+Sa0u2BHkaMLkS6luQJVHksyQ hPruxPr6gMem9XE7Y5PLS2NH9OtI/ezi2emCzYbrJnSPSGizcXyG X-Google-Smtp-Source: AGHT+IEwixaczgipVCRjgSY1JiCuWGfPp9+dC5/BGLa5Qcpy2rB7TZRyr1SPTovWyiH7Vt5WkpjxCQ== X-Received: by 2002:a05:6a00:17a7:b0:708:41c4:8849 with SMTP id d2e1a72fcca58-7192643cd9cmr9340815b3a.9.1726223389293; Fri, 13 Sep 2024 03:29:49 -0700 (PDT) Received: from localhost.localdomain ([2402:7500:568:acb8:4bcf:ada3:4620:3cfb]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7db1fad0ac6sm3137683a12.0.2024.09.13.03.29.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:29:49 -0700 (PDT) From: Victor Shih To: ulf.hansson@linaro.org, adrian.hunter@intel.com Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, benchuanggli@gmail.com, Lucas.Lai@genesyslogic.com.tw, HL.Liu@genesyslogic.com.tw, Greg.tu@genesyslogic.com.tw, dlunev@chromium.org, Victor Shih , Ben Chuang , AKASHI Takahiro , Victor Shih Subject: [PATCH V22 15/22] mmc: sdhci-uhs2: add set_ios() Date: Fri, 13 Sep 2024 18:28:29 +0800 Message-Id: <20240913102836.6144-16-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20240913102836.6144-1-victorshihgli@gmail.com> References: <20240913102836.6144-1-victorshihgli@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Victor Shih This is a sdhci version of mmc's set_ios operation. This is used to handle basic IO bus setting. It covers both UHS-I and UHS-II. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih --- Updates in V22: - Adjust the patch order from v21 patch#14 to v22 patch#15 and add necessary code to avoid defined but not used warnings. Updates in V14: - Use mmc_card_uhs2() to stead sdhci_uhs2_mode() in the sdhci_uhs2_set_ios(). Updates in V13: - Add judgment condition for power mode in the __sdhci_uhs2_set_ios(). - Modify comment message. Updates in V9: - Simplity the turning_on_clk in sdhci_set_ios(). Updates in V8: - Add the judgment formula for MMC_TIMING_SPEED_A_HD, MMC_TIMING_SPEED_B and MMC_TIMING_SPEED_B_HD in __sdhci_uhs2_set_ios(). - Add the switch case for MMC_TIMING_SPEED_A_HD, MMC_TIMING_SPEED_B and MMC_TIMING_SPEED_B_HD in sdhci_get_preset_value(). - mmc_opt_regulator_set_ocr() to instead of mmc_regulator_set_ocr() in sdhci_uhs2_set_ios(). Updates in V7: - Remove unnecessary functions. Updates in V6: - Modify return value in some functions. - Remove unnecessary functions. --- drivers/mmc/host/sdhci-uhs2.c | 128 ++++++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci-uhs2.h | 1 + drivers/mmc/host/sdhci.c | 55 +++++++++------ drivers/mmc/host/sdhci.h | 2 + 4 files changed, 165 insertions(+), 21 deletions(-) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index d3af620c7b68..ee46dac891e5 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -208,12 +208,136 @@ void sdhci_uhs2_set_timeout(struct sdhci_host *host,= struct mmc_command *cmd) } EXPORT_SYMBOL_GPL(sdhci_uhs2_set_timeout); =20 +/** + * sdhci_uhs2_clear_set_irqs - set Error Interrupt Status Enable register + * @host: SDHCI host + * @clear: bit-wise clear mask + * @set: bit-wise set mask + * + * Set/unset bits in UHS-II Error Interrupt Status Enable register + */ +void sdhci_uhs2_clear_set_irqs(struct sdhci_host *host, u32 clear, u32 set) +{ + u32 ier; + + ier =3D sdhci_readl(host, SDHCI_UHS2_INT_STATUS_ENABLE); + ier &=3D ~clear; + ier |=3D set; + sdhci_writel(host, ier, SDHCI_UHS2_INT_STATUS_ENABLE); + sdhci_writel(host, ier, SDHCI_UHS2_INT_SIGNAL_ENABLE); +} +EXPORT_SYMBOL_GPL(sdhci_uhs2_clear_set_irqs); + +static void __sdhci_uhs2_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) +{ + struct sdhci_host *host =3D mmc_priv(mmc); + u8 cmd_res, dead_lock; + u16 ctrl_2; + + /* UHS2 Timeout Control */ + sdhci_calc_timeout_uhs2(host, &cmd_res, &dead_lock); + + /* change to use calculate value */ + cmd_res |=3D FIELD_PREP(SDHCI_UHS2_TIMER_CTRL_DEADLOCK_MASK, dead_lock); + + sdhci_uhs2_clear_set_irqs(host, + SDHCI_UHS2_INT_CMD_TIMEOUT | + SDHCI_UHS2_INT_DEADLOCK_TIMEOUT, + 0); + sdhci_writeb(host, cmd_res, SDHCI_UHS2_TIMER_CTRL); + sdhci_uhs2_clear_set_irqs(host, 0, + SDHCI_UHS2_INT_CMD_TIMEOUT | + SDHCI_UHS2_INT_DEADLOCK_TIMEOUT); + + /* UHS2 timing. Note, UHS2 timing is disabled when powering off */ + ctrl_2 =3D sdhci_readw(host, SDHCI_HOST_CONTROL2); + if (ios->power_mode !=3D MMC_POWER_OFF && + (ios->timing =3D=3D MMC_TIMING_UHS2_SPEED_A || + ios->timing =3D=3D MMC_TIMING_UHS2_SPEED_A_HD || + ios->timing =3D=3D MMC_TIMING_UHS2_SPEED_B || + ios->timing =3D=3D MMC_TIMING_UHS2_SPEED_B_HD)) + ctrl_2 |=3D SDHCI_CTRL_UHS2 | SDHCI_CTRL_UHS2_ENABLE; + else + ctrl_2 &=3D ~(SDHCI_CTRL_UHS2 | SDHCI_CTRL_UHS2_ENABLE); + sdhci_writew(host, ctrl_2, SDHCI_HOST_CONTROL2); + host->timing =3D ios->timing; + + if (!(host->quirks2 & SDHCI_QUIRK2_PRESET_VALUE_BROKEN)) + sdhci_enable_preset_value(host, true); + + if (host->ops->set_power) + host->ops->set_power(host, ios->power_mode, ios->vdd); + else + sdhci_uhs2_set_power(host, ios->power_mode, ios->vdd); + + sdhci_set_clock(host, host->clock); +} + +static int sdhci_uhs2_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) +{ + struct sdhci_host *host =3D mmc_priv(mmc); + + pr_debug("%s: clock %uHz powermode %u Vdd %u timing %u\n", + mmc_hostname(mmc), ios->clock, ios->power_mode, ios->vdd, ios->timing); + + if (!mmc_card_uhs2(mmc)) { + sdhci_set_ios(mmc, ios); + return 0; + } + + if (ios->power_mode =3D=3D MMC_POWER_UNDEFINED) + return 0; + + if (host->flags & SDHCI_DEVICE_DEAD) { + if (ios->power_mode =3D=3D MMC_POWER_OFF) { + mmc_opt_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); + mmc_regulator_set_vqmmc2(mmc, ios); + } + return -1; + } + + sdhci_set_ios_common(mmc, ios); + + __sdhci_uhs2_set_ios(mmc, ios); + + return 0; +} + +static int sdhci_uhs2_control(struct mmc_host *mmc, enum sd_uhs2_operation= op) +{ + struct sdhci_host *host =3D mmc_priv(mmc); + struct mmc_ios *ios =3D &mmc->ios; + int err =3D 0; + + DBG("Begin uhs2 control, act %d.\n", op); + + switch (op) { + case UHS2_SET_IOS: + err =3D sdhci_uhs2_set_ios(mmc, ios); + break; + default: + pr_err("%s: input sd uhs2 operation %d is wrong!\n", + mmc_hostname(host->mmc), op); + err =3D -EIO; + break; + } + + return err; +} + /*************************************************************************= ****\ * = * * Driver init/exit = * * = * \*************************************************************************= ****/ =20 +static int sdhci_uhs2_host_ops_init(struct sdhci_host *host) +{ + host->mmc_host_ops.uhs2_control =3D sdhci_uhs2_control; + + return 0; +} + static int __init sdhci_uhs2_mod_init(void) { return 0; @@ -288,6 +412,10 @@ int sdhci_uhs2_add_host(struct sdhci_host *host) /* host doesn't want to enable UHS2 support */ mmc->caps2 &=3D ~MMC_CAP2_SD_UHS2; =20 + /* overwrite ops */ + if (mmc->caps2 & MMC_CAP2_SD_UHS2) + sdhci_uhs2_host_ops_init(host); + /* LED support not implemented for UHS2 */ host->quirks |=3D SDHCI_QUIRK_NO_LED; =20 diff --git a/drivers/mmc/host/sdhci-uhs2.h b/drivers/mmc/host/sdhci-uhs2.h index 0e1866a6bdb6..14713a31f8a5 100644 --- a/drivers/mmc/host/sdhci-uhs2.h +++ b/drivers/mmc/host/sdhci-uhs2.h @@ -183,5 +183,6 @@ void sdhci_uhs2_set_power(struct sdhci_host *host, unsi= gned char mode, unsigned void sdhci_uhs2_set_timeout(struct sdhci_host *host, struct mmc_command *c= md); int sdhci_uhs2_add_host(struct sdhci_host *host); void sdhci_uhs2_remove_host(struct sdhci_host *host, int dead); +void sdhci_uhs2_clear_set_irqs(struct sdhci_host *host, u32 clear, u32 set= ); =20 #endif /* __SDHCI_UHS2_H */ diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 366c3d30dba6..63fa1714930a 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -47,8 +47,6 @@ static unsigned int debug_quirks =3D 0; static unsigned int debug_quirks2; =20 -static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable= ); - static bool sdhci_send_command(struct sdhci_host *host, struct mmc_command= *cmd); =20 void sdhci_dumpregs(struct sdhci_host *host) @@ -1877,6 +1875,12 @@ static u16 sdhci_get_preset_value(struct sdhci_host = *host) case MMC_TIMING_MMC_HS400: preset =3D sdhci_readw(host, SDHCI_PRESET_FOR_HS400); break; + case MMC_TIMING_UHS2_SPEED_A: + case MMC_TIMING_UHS2_SPEED_A_HD: + case MMC_TIMING_UHS2_SPEED_B: + case MMC_TIMING_UHS2_SPEED_B_HD: + preset =3D sdhci_readw(host, SDHCI_PRESET_FOR_UHS2); + break; default: pr_warn("%s: Invalid UHS-I mode selected\n", mmc_hostname(host->mmc)); @@ -2323,24 +2327,9 @@ static bool sdhci_presetable_values_change(struct sd= hci_host *host, struct mmc_i (sdhci_preset_needed(host, ios->timing) || host->drv_type !=3D ios= ->drv_type); } =20 -void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) +void sdhci_set_ios_common(struct mmc_host *mmc, struct mmc_ios *ios) { struct sdhci_host *host =3D mmc_priv(mmc); - bool reinit_uhs =3D host->reinit_uhs; - bool turning_on_clk =3D false; - u8 ctrl; - - host->reinit_uhs =3D false; - - if (ios->power_mode =3D=3D MMC_POWER_UNDEFINED) - return; - - if (host->flags & SDHCI_DEVICE_DEAD) { - if (!IS_ERR(mmc->supply.vmmc) && - ios->power_mode =3D=3D MMC_POWER_OFF) - mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); - return; - } =20 /* * Reset the chip on each power off. @@ -2357,8 +2346,6 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_i= os *ios) sdhci_enable_preset_value(host, false); =20 if (!ios->clock || ios->clock !=3D host->clock) { - turning_on_clk =3D ios->clock && !host->clock; - host->ops->set_clock(host, ios->clock); host->clock =3D ios->clock; =20 @@ -2374,6 +2361,31 @@ void sdhci_set_ios(struct mmc_host *mmc, struct mmc_= ios *ios) mmc->max_busy_timeout /=3D host->timeout_clk; } } +} +EXPORT_SYMBOL_GPL(sdhci_set_ios_common); + +void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) +{ + struct sdhci_host *host =3D mmc_priv(mmc); + bool reinit_uhs =3D host->reinit_uhs; + bool turning_on_clk; + u8 ctrl; + + host->reinit_uhs =3D false; + + if (ios->power_mode =3D=3D MMC_POWER_UNDEFINED) + return; + + if (host->flags & SDHCI_DEVICE_DEAD) { + if (!IS_ERR(mmc->supply.vmmc) && + ios->power_mode =3D=3D MMC_POWER_OFF) + mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); + return; + } + + turning_on_clk =3D ios->clock !=3D host->clock && ios->clock && !host->cl= ock; + + sdhci_set_ios_common(mmc, ios); =20 if (host->ops->set_power) host->ops->set_power(host, ios->power_mode, ios->vdd); @@ -2942,7 +2954,7 @@ int sdhci_execute_tuning(struct mmc_host *mmc, u32 op= code) } EXPORT_SYMBOL_GPL(sdhci_execute_tuning); =20 -static void sdhci_enable_preset_value(struct sdhci_host *host, bool enable) +void sdhci_enable_preset_value(struct sdhci_host *host, bool enable) { /* Host Controller v3.00 defines preset value registers */ if (host->version < SDHCI_SPEC_300) @@ -2970,6 +2982,7 @@ static void sdhci_enable_preset_value(struct sdhci_ho= st *host, bool enable) host->preset_enabled =3D enable; } } +EXPORT_SYMBOL_GPL(sdhci_enable_preset_value); =20 static void sdhci_post_req(struct mmc_host *mmc, struct mmc_request *mrq, int err) diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index 0f78708d0c70..5c66927210bd 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -848,6 +848,8 @@ void sdhci_reset(struct sdhci_host *host, u8 mask); void sdhci_set_uhs_signaling(struct sdhci_host *host, unsigned timing); int sdhci_execute_tuning(struct mmc_host *mmc, u32 opcode); int __sdhci_execute_tuning(struct sdhci_host *host, u32 opcode); +void sdhci_enable_preset_value(struct sdhci_host *host, bool enable); +void sdhci_set_ios_common(struct mmc_host *mmc, struct mmc_ios *ios); void sdhci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios); int sdhci_start_signal_voltage_switch(struct mmc_host *mmc, struct mmc_ios *ios); --=20 2.25.1