From nobody Tue Nov 26 13:29:30 2024 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (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 8209520265D; Fri, 18 Oct 2024 10:54:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729248862; cv=none; b=XLvB56OsAuT+BRc17Hu5wFX83k89D/2yR86En3d6GNEq2frU6sOaqPL9ic5jbX3U1f3IJ5k126LM4YxChIVyTXYMiH6UnmCm5e0p+vPcgcQBJpJqXyy9rqTDKWlVMZ8zTSYbIcHEMMz7HeBGGHV8lalOMsQ9muzFasiz8HEVYVU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1729248862; c=relaxed/simple; bh=YFLqV890Z42BNuleGy/377WU3cFQMODtUvsZxEvUggE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JdeSq5ene7QX0oHM4KmKBByP8eiggBsEw68gFD1jaGl461oqaNb/WG5WDkEDFsvFa7rK/3Ua/eJ+x8Ibyyl4wPfxirhZFba29Z+jhAO4w5It5JqblPWrIdcXECAdwe0/i0mXSU1BN9V50+FQcPCqUmu2IFhHsvSXbgyG+NTMpMU= 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=Xv2pq2Ss; arc=none smtp.client-ip=209.85.214.179 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="Xv2pq2Ss" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-20e576dbc42so7708815ad.0; Fri, 18 Oct 2024 03:54:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1729248859; x=1729853659; 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=sA8jKHOlnNb5oztdOQ8CqUpGZDm97ramC29vExw2ghw=; b=Xv2pq2Ss6wZhAeJ+qabq95JTCZYZJFmPXyt72tyIJx4A1NpO5UQ4He/pvRctGCNgzE povO4klMpr+objfJFAQvyi084XtYPxAVGu+1WzuzwnZOUOhbI8zWU76hejMzgYCofLZn vEFpzCoAfj0KYZ+vRYozRXZhtAyFE2Sj5amX6qanVlwHeaCUcCXAus+Bc4EzSwqr7k4U 4JIRtItE92GvZewCKmoy53E9CaJBg4fs1XYVJXHEiFMzi0Hv9ozi4sAo/8OB2uweDK5w dN0l1iOap2v9Kib8YxQpuEbGtYfuPiigiEeqczZB9oOjKAyAO9KB94elrX29nyzURyGe dIRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1729248859; x=1729853659; 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=sA8jKHOlnNb5oztdOQ8CqUpGZDm97ramC29vExw2ghw=; b=HiPsOox64EZWEGlWQa1znLxWGuvLjeMa5Sd22dmdbjZ6nQinCZfgA7xqcjQ7MGPAiv KRVAkP6Jm05WoAGfrCuT//3UASY3YPJN4sWdmU5Q+VE4i8EQiEWVwVc6KS1Cv8y8tcl5 OGxgjcxrBO/29fv8oa/P4qfQjxJ5SKkF8GuqRkI4quibewM6viek3YPv/0alIeynDOYp NQ3MbWvQbJMytECz2qTw3C+N6XcruDCvo1QedTAP14izV/3jqShGOW/WE3Q+PAWGXZtT L6G1LIHImCp/jtRwICeRyDLhUJOgBJyy/H5J93523DrwGPhy63L1pGViNDTBvQlEFYSS 8Jwg== X-Forwarded-Encrypted: i=1; AJvYcCWvwtK31QyBMUBKcLYe9Wr/CNsIlTSpTT+c+H1eOVCrBz6Sd3HYEMHLfvV71HNLOYEZP3xNw4uA2hKU9jg=@vger.kernel.org X-Gm-Message-State: AOJu0YxMRWno1Hq8S8sA8mnbSEqVVjuNEXvSXCJq9mEVEtPOiyIWlwuf S+BhxOZYfF49aelr4doWrC9bCu8cEl7OF1yW84xDYE7fLS60EM9D X-Google-Smtp-Source: AGHT+IERopjt8r9bhq/ChS9B6ZO65gD63rvt5VLmh9BZQ1cWJ0Oi8Id6UQpRYAiFzub1gjFxVzCiLQ== X-Received: by 2002:a17:902:c412:b0:20b:c287:202d with SMTP id d9443c01a7336-20e5a9b14e2mr21154235ad.55.1729248858701; Fri, 18 Oct 2024 03:54:18 -0700 (PDT) Received: from localhost.localdomain ([2402:7500:47a:11ee:3789:3bcf:d64f:bc9a]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20e5a8fa20esm10237455ad.234.2024.10.18.03.54.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Oct 2024 03:54:18 -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 V23 08/16] mmc: sdhci-uhs2: add add_host() and others to set up the driver Date: Fri, 18 Oct 2024 18:53:25 +0800 Message-Id: <20241018105333.4569-9-victorshihgli@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241018105333.4569-1-victorshihgli@gmail.com> References: <20241018105333.4569-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 UHS-II version of sdhci's add_host/remove_host operation. Any sdhci drivers which are capable of handling UHS-II cards must call those functions instead of the corresponding sdhci's. 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#18 to v22 patch#14 and remove unnecessary code to avoid defined but not used warnings. Updates in V14: - Use mmc_card_uhs2() to stead sdhci_uhs2_mode() in the __sdhci_uhs2_remove_host(). Updates in V13: - Re-order function to avoid declaration. - Use vqmmc2 to stead vmmc2. Updates in V11: - Remove unused ocr_avail_uhs2. Updates in V10: - Move some definitions of PatchV9[05/23] to PatchV10[20/23]. Updates in V8: - Change return type to void for __sdhci_uhs2_add_host_v4(). - Remove unused variables in __sdhci_uhs2_add_host_v4(). Updates in V7: - __sdhci_add_host() to instead of __sdhci_uhs2_add_host() in sdhci_uhs2_add_host(). - Cancel export state of some functions. Updates in V6: - Add complete_work_fn/thread_irq_fn variables in struct sdhci_host. - Use complete_work_fn/thread_irq_fn variables in sdhci_alloc_host() and sdhci_uhs2_add_host(). - Use sdhci_uhs2_mode() to simplify code in __sdhci_uhs2_remove_host(). --- drivers/mmc/host/sdhci-uhs2.c | 91 +++++++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci-uhs2.h | 2 + 2 files changed, 93 insertions(+) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index 6b249eb8395a..d3af620c7b68 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -14,6 +14,7 @@ #include #include #include +#include =20 #include "sdhci.h" #include "sdhci-uhs2.h" @@ -224,6 +225,96 @@ static void __exit sdhci_uhs2_mod_exit(void) } module_exit(sdhci_uhs2_mod_exit); =20 +/*************************************************************************= ****\ + * + * Device allocation/registration = * + * = * +\*************************************************************************= ****/ + +static void __sdhci_uhs2_add_host_v4(struct sdhci_host *host, u32 caps1) +{ + struct mmc_host *mmc; + u32 max_current_caps2; + + mmc =3D host->mmc; + + /* Support UHS2 */ + if (caps1 & SDHCI_SUPPORT_UHS2) + mmc->caps2 |=3D MMC_CAP2_SD_UHS2; + + max_current_caps2 =3D sdhci_readl(host, SDHCI_MAX_CURRENT_1); + + if ((caps1 & SDHCI_CAN_VDD2_180) && + !max_current_caps2 && + !IS_ERR(mmc->supply.vqmmc2)) { + /* UHS2 - VDD2 */ + int curr =3D regulator_get_current_limit(mmc->supply.vqmmc2); + + if (curr > 0) { + /* convert to SDHCI_MAX_CURRENT format */ + curr =3D curr / 1000; /* convert to mA */ + curr =3D curr / SDHCI_MAX_CURRENT_MULTIPLIER; + curr =3D min_t(u32, curr, SDHCI_MAX_CURRENT_LIMIT); + max_current_caps2 =3D curr; + } + } + + if (!(caps1 & SDHCI_CAN_VDD2_180)) + mmc->caps2 &=3D ~MMC_CAP2_SD_UHS2; +} + +static void __sdhci_uhs2_remove_host(struct sdhci_host *host, int dead) +{ + if (!mmc_card_uhs2(host->mmc)) + return; + + if (!dead) + sdhci_uhs2_reset(host, SDHCI_UHS2_SW_RESET_FULL); +} + +int sdhci_uhs2_add_host(struct sdhci_host *host) +{ + struct mmc_host *mmc =3D host->mmc; + int ret; + + ret =3D sdhci_setup_host(host); + if (ret) + return ret; + + if (host->version >=3D SDHCI_SPEC_400) + __sdhci_uhs2_add_host_v4(host, host->caps1); + + if ((mmc->caps2 & MMC_CAP2_SD_UHS2) && !host->v4_mode) + /* host doesn't want to enable UHS2 support */ + mmc->caps2 &=3D ~MMC_CAP2_SD_UHS2; + + /* LED support not implemented for UHS2 */ + host->quirks |=3D SDHCI_QUIRK_NO_LED; + + ret =3D __sdhci_add_host(host); + if (ret) + goto cleanup; + + return 0; + +cleanup: + if (host->version >=3D SDHCI_SPEC_400) + __sdhci_uhs2_remove_host(host, 0); + + sdhci_cleanup_host(host); + + return ret; +} +EXPORT_SYMBOL_GPL(sdhci_uhs2_add_host); + +void sdhci_uhs2_remove_host(struct sdhci_host *host, int dead) +{ + __sdhci_uhs2_remove_host(host, dead); + + sdhci_remove_host(host, dead); +} +EXPORT_SYMBOL_GPL(sdhci_uhs2_remove_host); + MODULE_AUTHOR("Intel, Genesys Logic, Linaro"); MODULE_DESCRIPTION("MMC UHS-II Support"); MODULE_LICENSE("GPL"); diff --git a/drivers/mmc/host/sdhci-uhs2.h b/drivers/mmc/host/sdhci-uhs2.h index 9bd3f610cf8c..0e1866a6bdb6 100644 --- a/drivers/mmc/host/sdhci-uhs2.h +++ b/drivers/mmc/host/sdhci-uhs2.h @@ -181,5 +181,7 @@ void sdhci_uhs2_dump_regs(struct sdhci_host *host); void sdhci_uhs2_reset(struct sdhci_host *host, u16 mask); void sdhci_uhs2_set_power(struct sdhci_host *host, unsigned char mode, uns= igned short vdd); 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); =20 #endif /* __SDHCI_UHS2_H */ --=20 2.25.1