From patchwork Thu Feb 25 17:03:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 387226 Delivered-To: patches@linaro.org Received: by 2002:a02:290e:0:0:0:0:0 with SMTP id p14csp476950jap; Thu, 25 Feb 2021 09:04:06 -0800 (PST) X-Received: by 2002:a05:6512:108e:: with SMTP id j14mr2246683lfg.364.1614272646563; Thu, 25 Feb 2021 09:04:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614272646; cv=none; d=google.com; s=arc-20160816; b=lQ04DfH+k65dI19orA+BNWiiUAhSxcq/UbORdmdeZIUSStnfQAQ8jJPgHhnWV4nJ9C gYO+pBomRWgM44CbiU1vMAvRsJ87EFniCRh5pnxJM549M18WlJcfJgat5GoE/s1WTgeM 5a2Ekb6aDycxg9LVSkY3842JOoAbYrTUVAfoFqr3JEoffI4y1eLafO4B8WR3Qfanm3nl A7jBtAoSt7Ay5DjMFdyS1oI9PS0rAW+NZpBPr/kAkWx0kvIdC3bswP2cLwIT/eZYpxeJ 0shOmvg2kFIu/auM642slxGxsB9sLHVZh+MXnQhKzYXMwe1ycrlXkHV5HmpRPGLHUE+H 6+Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=vj9rdIaC2NXd2ktY/guBoYHKwtZ19VGh75jY1riwXmk=; b=GolywWmgUtHUQW5NHyQxFJQaIQPPgY829gzz89m6XMl3o/dZYAVKRnxWBFFyRRQoYJ +hlokOb6/8lBaL5lDLYI9hgfXdTRIvhDprh1e5x7si8+dDBUGH9O9KJDgBb2OJnBA2b/ XBfqWZ2H/446wa4Q7IamUXY1OUvW3ozW8n5Y+zMS0hzkAse2XaQu8DG4CiUvS+Aupn5m gY0SfZCCi86agRbX6zWnDZLJfvRzrPrTEcrLzuVKkqjVC/lS7UWm8odQm3Bne0LTV3XC Ma6WZYt0RoeVZ0O1I88uA6/ZiB16vu3a7sp/RDyMOJ1FNSB0gddL8wF4d4HJMqd0OFmw B1cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=guHDoLEE; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id c13sor1445695lft.135.2021.02.25.09.04.06 for (Google Transport Security); Thu, 25 Feb 2021 09:04:06 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=guHDoLEE; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vj9rdIaC2NXd2ktY/guBoYHKwtZ19VGh75jY1riwXmk=; b=guHDoLEECvKjKyHltm0WRI213M65b10M0InJ3+CiKpohgzE/LmWJCZVMa3/9hcSsy1 7M95nwTk9s8UQEoTlg0+nasyj8VFxZ1YUj5JF/3viFIglVKrNUXkZVv5Swxk++ow7Qsw 3s7SfeSAzTds/HRMJPji2dHIPyM6ovWZSygdXeqCUOeS4gARnLP5nV+hbe8KUrAVx6VB KuWkQ6xAdaejLoXqPO3nVd6n9t9SAwbzvXWNLSYhfis5cYrhJMMf5ovGpjYi/JDD5it9 xPi92RBccdKq1vHi2CX9I6aTZiKj9XT585/lwOp1FtJ4UMhOrEr8Q+uORU+qyoAQU5qE xcng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vj9rdIaC2NXd2ktY/guBoYHKwtZ19VGh75jY1riwXmk=; b=VKbEo2rZwP61SlVseQ34MW7B9LTJn17GTKRvmeC2Yzv0ycv2mnV7iRkPSmguRHg9pU Cf2XrmPmouZSFnME9c/rPYKTsTRe/SNy8KZZqwx+51VFmlyrjugfZ0ZMKPrX7dQARltA CCryq2dApn3pa7/Ui9x5DSrcfJBXTOHPaRacIIkSERLZHlfXhNX516at9UI5XJ90PUCJ BuJELgxIS+fH0ZSbz90RGD+m6TAMR9C6z840o/ZPlBTnJgd/mqgLHwAq6YqzLw1GCcka JfBJ9Y8UqWbXHoo2Jy0doGzmCs1NCsC+/Y2VaNJlNvskshgz8W0jr2eSgrseY1li3Ofv 6gcw== X-Gm-Message-State: AOAM531ZwXiBrrc8T4D7nqJYJ4yuUAxEgewCPqbOanYPc8oZD7GTzxi5 91yLm/QlxZ8fexhH3hEyFQMpxxZx X-Google-Smtp-Source: ABdhPJwRC+KhmoMpNcZAsBwMSKrl2NeOaJRIlJkg1RF7mJ9XoLIydrpQAmVR0qTjIyxwhXBYYWonoQ== X-Received: by 2002:a05:6512:5d7:: with SMTP id o23mr2454322lfo.254.1614272646204; Thu, 25 Feb 2021 09:04:06 -0800 (PST) Return-Path: Received: from localhost.localdomain (h-155-4-129-234.NA.cust.bahnhof.se. [155.4.129.234]) by smtp.gmail.com with ESMTPSA id b39sm1103749ljf.68.2021.02.25.09.04.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Feb 2021 09:04:05 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: AKASHI Takahiro , Ben Chuang , greg.tu@genesyslogic.com.tw, Renius Chen , Masami Hiramatsu , Takao Orito , linux-kernel@vger.kernel.org Subject: [PATCH 1/4] mmc: core: Cleanup printing of speed mode at card insertion Date: Thu, 25 Feb 2021 18:03:49 +0100 Message-Id: <20210225170352.76872-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210225170352.76872-1-ulf.hansson@linaro.org> References: <20210225170352.76872-1-ulf.hansson@linaro.org> MIME-Version: 1.0 The current print of the bus speed mode in mmc_add_card() has grown over the years and is now difficult to parse. Let's clean up the code and also take the opportunity to properly announce "DDR" for eMMCs as "high speed DDR", which is according to the eMMC spec. Signed-off-by: Ulf Hansson --- drivers/mmc/core/bus.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) -- 2.25.1 diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c index c2e70b757dd1..f4851ec8290c 100644 --- a/drivers/mmc/core/bus.c +++ b/drivers/mmc/core/bus.c @@ -311,6 +311,7 @@ int mmc_add_card(struct mmc_card *card) { int ret; const char *type; + const char *speed_mode = ""; const char *uhs_bus_speed_mode = ""; static const char *const uhs_speeds[] = { [UHS_SDR12_BUS_SPEED] = "SDR12 ", @@ -349,27 +350,30 @@ int mmc_add_card(struct mmc_card *card) break; } + if (mmc_card_hs(card)) + speed_mode = "high speed "; + else if (mmc_card_uhs(card)) + speed_mode = "ultra high speed "; + else if (mmc_card_ddr52(card)) + speed_mode = "high speed DDR "; + else if (mmc_card_hs200(card)) + speed_mode = "HS200 "; + else if (mmc_card_hs400es(card)) + speed_mode = "HS400 Enhanced strobe "; + else if (mmc_card_hs400(card)) + speed_mode = "HS400 "; + if (mmc_card_uhs(card) && (card->sd_bus_speed < ARRAY_SIZE(uhs_speeds))) uhs_bus_speed_mode = uhs_speeds[card->sd_bus_speed]; - if (mmc_host_is_spi(card->host)) { - pr_info("%s: new %s%s%s card on SPI\n", - mmc_hostname(card->host), - mmc_card_hs(card) ? "high speed " : "", - mmc_card_ddr52(card) ? "DDR " : "", - type); - } else { - pr_info("%s: new %s%s%s%s%s%s card at address %04x\n", - mmc_hostname(card->host), - mmc_card_uhs(card) ? "ultra high speed " : - (mmc_card_hs(card) ? "high speed " : ""), - mmc_card_hs400(card) ? "HS400 " : - (mmc_card_hs200(card) ? "HS200 " : ""), - mmc_card_hs400es(card) ? "Enhanced strobe " : "", - mmc_card_ddr52(card) ? "DDR " : "", + if (mmc_host_is_spi(card->host)) + pr_info("%s: new %s%s card on SPI\n", + mmc_hostname(card->host), speed_mode, type); + else + pr_info("%s: new %s%s%s card at address %04x\n", + mmc_hostname(card->host), speed_mode, uhs_bus_speed_mode, type, card->rca); - } #ifdef CONFIG_DEBUG_FS mmc_add_card_debugfs(card); From patchwork Thu Feb 25 17:03:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 387227 Delivered-To: patches@linaro.org Received: by 2002:a02:290e:0:0:0:0:0 with SMTP id p14csp476998jap; Thu, 25 Feb 2021 09:04:09 -0800 (PST) X-Received: by 2002:a2e:9f57:: with SMTP id v23mr2066779ljk.337.1614272649606; Thu, 25 Feb 2021 09:04:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614272649; cv=none; d=google.com; s=arc-20160816; b=k3VlXoFR6S9BCuzQqfFGv1vtXv4vyS8LPZ25wHT/sSQ+jutY/WsB9VEn2pTtVx3w84 a2h89vRBbhrFNUNrWnjkzRu1xfNyiMxJOC1gSQW8NV/Cr2rZsa27l4BXRSXxbJjoGWBl njb9cX7EQUT2Vn8JXtk77bitMvO1ECIC/0JB79kl/I7V5i+B9apcGtOGvjTMSmw0Bu/f SCljALrMoEYPpM42rB/ruzTHCupq/dCdEJvszGG+HLmTJUZ4CKxWk2ydEmfTW4bHlB61 EL2j5DH1XYSVcyGZe3qPz09XbDMCm2zINJheOWRov2DYxlgVX5iki0ebPGDK6DT12oFt vo4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=uphKf+/2XvduEhPk2gKwTCsjBvYRfocewX9RcmUtw1A=; b=YkIQ5+r8igzdACy+sjVu+wSq4TCncGMLN9hjRTyzgNVKc/Rox/6/TQVviy4VgAP1tZ 7p2wGpi+FyK3wMDAQa7K9aL44ntoC7ma4ZinZcBNCk9KtEraB9b5cacUCEOEKXYQeRYp gAHRbH+uP8kS/MG2jGRTOaFrn1whm09oWahjj63vGAWtPELmnb67f24AHWZLkkXfw99U NO4pCJCobulauQBdoPG9HIgwC9VWoniJVlhdefnvLacAUQJVHJs8TvnUoLvjlDDlNpBI EtjgjB82D1cGaTXrYrtMn2mEsQV16eILHNnI1QFh50hx0yHfAVi2zWab5hZVGUT/eQJX CoCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J8JJPQMR; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id r5sor2755096ljh.16.2021.02.25.09.04.09 for (Google Transport Security); Thu, 25 Feb 2021 09:04:09 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=J8JJPQMR; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uphKf+/2XvduEhPk2gKwTCsjBvYRfocewX9RcmUtw1A=; b=J8JJPQMRr7tqw79j1G82JDMSUaGGf43OjkQ5PmEBPgg8UzTqosFL66TClCDO91XXPd +SGPz6uufKeve+XEz3nd9gFFKHKLofQy4aB4kwxMnnSYrwq01de7ouG70uQ6zKt8OUaw N221FhmFzCSIy/+kSez1acIQUqlINM3wrymBoa/LhJ1Oa596vxBl1C9hBDs32MacU8WJ EndyNB3mFk5cmb+kMkIWFWfAatiX+a6reXBwXn4XT2bieAnLw9jdttL3yJqKv+Dbf05T QGXQCQZLs/0hsQnxdSW97is7PHApGl4OeUv8GcCKFAekjmxsXGak54cmeTi9fHDcRbxc N76Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=uphKf+/2XvduEhPk2gKwTCsjBvYRfocewX9RcmUtw1A=; b=VMn1puoMBLPfFuo2bImujY+koBpVSgjsdfWKPnyVmfcZvsrYaehg0buOKdyejDJMuv fGBJedr3urPCFRHlGQUDocLKdVrX0dU4mL2aE1rRYObup53Udc5kIfZ/0oFebRAuHsFn +aOukFpPrGzh/ZJMzOclzZSsZhWfZwF0NY+uz+nNYt+HhOKDnsbWOTOAWQ59p/hznDXr 30FLIdkMz+ijnXx+cq1HACQceFEscX1MK2H2uCsCJEmmKqeX1jUMggptUglGXvrKxNlf 02Yd/CGwD5qnIr/Y/i5ga1vnFhcmXCchZgDIfFWMRIwoVTTzkSWllCt1aNHrZZYHLqgE IJ5Q== X-Gm-Message-State: AOAM532PhOu6OpkgUG33+Pi50jieGsSA0q2EC1xG7KKHFgGLXaRLujXa phK2x76fjse6W/WyZuAJLWsBwApkPyXaIs33 X-Google-Smtp-Source: ABdhPJzN9ryIQfvC49Ijr2Lx7fPEKqqhzNNhrRwS05PesPvL2NUxqBeUvOBDsn6ocF5agxrFuWgwvw== X-Received: by 2002:a05:651c:509:: with SMTP id o9mr2114368ljp.369.1614272648597; Thu, 25 Feb 2021 09:04:08 -0800 (PST) Return-Path: Received: from localhost.localdomain (h-155-4-129-234.NA.cust.bahnhof.se. [155.4.129.234]) by smtp.gmail.com with ESMTPSA id b39sm1103749ljf.68.2021.02.25.09.04.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Feb 2021 09:04:07 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: AKASHI Takahiro , Ben Chuang , greg.tu@genesyslogic.com.tw, Renius Chen , Masami Hiramatsu , Takao Orito , linux-kernel@vger.kernel.org Subject: [PATCH 2/4] mmc: core: Prepare to support SD UHS-II cards Date: Thu, 25 Feb 2021 18:03:50 +0100 Message-Id: <20210225170352.76872-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210225170352.76872-1-ulf.hansson@linaro.org> References: <20210225170352.76872-1-ulf.hansson@linaro.org> MIME-Version: 1.0 The SD UHS-II interface was introduced to the SD spec v4.00 several years ago. The interface is fundamentally different from an electrical and a protocol point of view, comparing to the legacy SD interface. However, the legacy SD protocol is supported through a specific transport layer (SD-TRAN) defined in the UHS-II addendum of the spec. This allows the SD card to be managed in a very similar way as a legacy SD card, hence a lot of code can be re-used to support these new types of cards through the mmc subsystem. Moreover, an SD card that supports the UHS-II interface shall also be backwards compatible with the legacy SD interface, which allows a UHS-II card to be inserted into a legacy slot. As a matter of fact, this is already supported by mmc subsystem as of today. To prepare to add support for UHS-II, this change puts the basic foundation in the mmc core in place, allowing it to be more easily reviewed before subsequent changes implements the actual support. Basically, the approach here adds a new UHS-II bus_ops type and adds a separate initialization path for the UHS-II card. The intent is to avoid us from sprinkling the legacy initialization path, but also to simplify implementation of the UHS-II specific bits. At this point, there is only one new host ops added to manage the various ios settings needed for UHS-II. Additional host ops that are needed, are being added from subsequent changes. Signed-off-by: Ulf Hansson --- drivers/mmc/core/Makefile | 2 +- drivers/mmc/core/core.c | 17 ++- drivers/mmc/core/core.h | 1 + drivers/mmc/core/sd_uhs2.c | 289 +++++++++++++++++++++++++++++++++++++ include/linux/mmc/card.h | 6 + include/linux/mmc/host.h | 19 +++ 6 files changed, 332 insertions(+), 2 deletions(-) create mode 100644 drivers/mmc/core/sd_uhs2.c -- 2.25.1 diff --git a/drivers/mmc/core/Makefile b/drivers/mmc/core/Makefile index 6a907736cd7a..10f1c3ca5e4a 100644 --- a/drivers/mmc/core/Makefile +++ b/drivers/mmc/core/Makefile @@ -8,7 +8,7 @@ mmc_core-y := core.o bus.o host.o \ mmc.o mmc_ops.o sd.o sd_ops.o \ sdio.o sdio_ops.o sdio_bus.o \ sdio_cis.o sdio_io.o sdio_irq.o \ - slot-gpio.o regulator.o + slot-gpio.o regulator.o sd_uhs2.o mmc_core-$(CONFIG_OF) += pwrseq.o obj-$(CONFIG_PWRSEQ_SIMPLE) += pwrseq_simple.o obj-$(CONFIG_PWRSEQ_SD8787) += pwrseq_sd8787.o diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 860995eb548b..7f785774f59e 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2207,6 +2207,18 @@ void mmc_rescan(struct work_struct *work) goto out; } + /* + * Ideally we should favor initialization of legacy SD cards and defer + * UHS-II enumeration. However, it seems like cards doesn't reliably + * announce their support for UHS-II in the response to the ACMD41, + * while initializing the legacy SD interface. Therefore, let's start + * with UHS-II for now. + */ + if (!mmc_attach_sd_uhs2(host)) { + mmc_release_host(host); + goto out; + } + for (i = 0; i < ARRAY_SIZE(freqs); i++) { unsigned int freq = freqs[i]; if (freq > host->f_max) { @@ -2228,10 +2240,13 @@ void mmc_rescan(struct work_struct *work) void mmc_start_host(struct mmc_host *host) { + bool power_up = !(host->caps2 & + (MMC_CAP2_NO_PRESCAN_POWERUP | MMC_CAP2_SD_UHS2)); + host->f_init = max(min(freqs[0], host->f_max), host->f_min); host->rescan_disable = 0; - if (!(host->caps2 & MMC_CAP2_NO_PRESCAN_POWERUP)) { + if (power_up) { mmc_claim_host(host); mmc_power_up(host, host->ocr_avail); mmc_release_host(host); diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h index 575ac0257af2..cbbf92b60a8a 100644 --- a/drivers/mmc/core/core.h +++ b/drivers/mmc/core/core.h @@ -78,6 +78,7 @@ int mmc_detect_card_removed(struct mmc_host *host); int mmc_attach_mmc(struct mmc_host *host); int mmc_attach_sd(struct mmc_host *host); int mmc_attach_sdio(struct mmc_host *host); +int mmc_attach_sd_uhs2(struct mmc_host *host); /* Module parameters */ extern bool use_spi_crc; diff --git a/drivers/mmc/core/sd_uhs2.c b/drivers/mmc/core/sd_uhs2.c new file mode 100644 index 000000000000..800957f74632 --- /dev/null +++ b/drivers/mmc/core/sd_uhs2.c @@ -0,0 +1,289 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (C) 2021 Linaro Ltd + * + * Author: Ulf Hansson + * + * Support for SD UHS-II cards + */ +#include + +#include +#include + +#include "core.h" +#include "bus.h" +#include "sd.h" +#include "mmc_ops.h" + +static const unsigned int sd_uhs2_freqs[] = { 52000000, 26000000 }; + +static int sd_uhs2_set_ios(struct mmc_host *host) +{ + struct mmc_ios *ios = &host->ios; + + return host->ops->uhs2_set_ios(host, ios); +} + +static int sd_uhs2_power_up(struct mmc_host *host) +{ + host->ios.vdd = fls(host->ocr_avail) - 1; + host->ios.clock = host->f_init; + host->ios.timing = MMC_TIMING_SD_UHS2; + host->ios.power_mode = MMC_POWER_UP; + + return sd_uhs2_set_ios(host); +} + +static void sd_uhs2_power_off(struct mmc_host *host) +{ + host->ios.vdd = 0; + host->ios.clock = 0; + host->ios.timing = MMC_TIMING_LEGACY; + host->ios.power_mode = MMC_POWER_OFF; + + sd_uhs2_set_ios(host); +} + +/* + * Run the phy initialization sequence, which mainly relies on the UHS-II host + * to check that we reach the expected electrical state, between the host and + * the card. + */ +static int sd_uhs2_phy_init(struct mmc_host *host) +{ + return 0; +} + +/* + * Do the early initialization of the card, by sending the device init broadcast + * command and wait for the process to be completed. + */ +static int sd_uhs2_dev_init(struct mmc_host *host) +{ + return 0; +} + +/* + * Run the enumeration process by sending the enumerate command to the card. + * Note that, we currently support only the point to point connection, which + * means only one card can be attached per host/slot. + */ +static int sd_uhs2_enum(struct mmc_host *host, u32 *node_id) +{ + return 0; +} + +/* + * Read the UHS-II configuration registers (CFG_REG) of the card, by sending it + * commands and by parsing the responses. Store a copy of the relevant data in + * card->uhs2_config. + */ +static int sd_uhs2_config_read(struct mmc_host *host, struct mmc_card *card) +{ + return 0; +} + +/* + * Based on the card's and host's UHS-II capabilities, let's update the + * configuration of the card and the host. This may also include to move to a + * greater speed range/mode. Depending on the updated configuration, we may need + * to do a soft reset of the card via sending it a GO_DORMANT_STATE command. + * + * In the final step, let's check if the card signals "config completion", which + * indicates that the card has moved from config state into active state. + */ +static int sd_uhs2_config_write(struct mmc_host *host, struct mmc_card *card) +{ + return 0; +} + +/* + * Initialize the UHS-II card through the SD-TRAN transport layer. This enables + * commands/requests to be backwards compatible through the legacy SD protocol. + * UHS-II cards has a specific power limit specified for VDD1/VDD2, that should + * be set through a legacy CMD6. Note that, the power limit that becomes set, + * survives a soft reset through the GO_DORMANT_STATE command. + */ +static int sd_uhs2_legacy_init(struct mmc_host *host, struct mmc_card *card) +{ + return 0; +} + +/* + * Allocate the data structure for the mmc_card and run the UHS-II specific + * initialization sequence. + */ +static int sd_uhs2_init_card(struct mmc_host *host) +{ + struct mmc_card *card; + u32 node_id; + int err; + + err = sd_uhs2_dev_init(host); + if (err) + return err; + + err = sd_uhs2_enum(host, &node_id); + if (err) + return err; + + card = mmc_alloc_card(host, &sd_type); + if (IS_ERR(card)) + return PTR_ERR(card); + + card->uhs2_config.node_id = node_id; + card->type = MMC_TYPE_SD; + + err = sd_uhs2_config_read(host, card); + if (err) + goto err; + + err = sd_uhs2_config_write(host, card); + if (err) + goto err; + + err = sd_uhs2_legacy_init(host, card); + if (err) + goto err; + + host->card = card; + return 0; + +err: + mmc_remove_card(card); + return err; +} + +static void sd_uhs2_remove(struct mmc_host *host) +{ + mmc_remove_card(host->card); + host->card = NULL; +} + +static int sd_uhs2_alive(struct mmc_host *host) +{ + return mmc_send_status(host->card, NULL); +} + +static void sd_uhs2_detect(struct mmc_host *host) +{ + int err; + + mmc_get_card(host->card, NULL); + err = _mmc_detect_card_removed(host); + mmc_put_card(host->card, NULL); + + if (err) { + sd_uhs2_remove(host); + + mmc_claim_host(host); + mmc_detach_bus(host); + sd_uhs2_power_off(host); + mmc_release_host(host); + } +} + +static int sd_uhs2_suspend(struct mmc_host *host) +{ + return 0; +} + +static int sd_uhs2_resume(struct mmc_host *host) +{ + return 0; +} + +static int sd_uhs2_runtime_suspend(struct mmc_host *host) +{ + return 0; +} + +static int sd_uhs2_runtime_resume(struct mmc_host *host) +{ + return 0; +} + +static int sd_uhs2_shutdown(struct mmc_host *host) +{ + return 0; +} + +static int sd_uhs2_hw_reset(struct mmc_host *host) +{ + return 0; +} + +static const struct mmc_bus_ops sd_uhs2_ops = { + .remove = sd_uhs2_remove, + .alive = sd_uhs2_alive, + .detect = sd_uhs2_detect, + .suspend = sd_uhs2_suspend, + .resume = sd_uhs2_resume, + .runtime_suspend = sd_uhs2_runtime_suspend, + .runtime_resume = sd_uhs2_runtime_resume, + .shutdown = sd_uhs2_shutdown, + .hw_reset = sd_uhs2_hw_reset, +}; + +static int sd_uhs2_attach(struct mmc_host *host) +{ + int err; + + err = sd_uhs2_power_up(host); + if (err) + goto err; + + err = sd_uhs2_phy_init(host); + if (err) + goto err; + + err = sd_uhs2_init_card(host); + if (err) + goto err; + + mmc_attach_bus(host, &sd_uhs2_ops); + + mmc_release_host(host); + + err = mmc_add_card(host->card); + if (err) + goto remove_card; + + mmc_claim_host(host); + return 0; + +remove_card: + mmc_remove_card(host->card); + host->card = NULL; + mmc_claim_host(host); + mmc_detach_bus(host); +err: + sd_uhs2_power_off(host); + return err; +} + +int mmc_attach_sd_uhs2(struct mmc_host *host) +{ + int i, err = 0; + + if (!(host->caps2 & MMC_CAP2_SD_UHS2)) + return -EOPNOTSUPP; + + /* Turn off the legacy SD interface before trying with UHS-II. */ + mmc_power_off(host); + + /* + * Start UHS-II initialization at 52MHz and possibly make a retry at + * 26MHz according to the spec. It's required that the host driver + * validates ios->clock, to set a rate within the correct range. + */ + for (i = 0; i < ARRAY_SIZE(sd_uhs2_freqs); i++) { + host->f_init = sd_uhs2_freqs[i]; + err = sd_uhs2_attach(host); + if (!err) + break; + } + + return err; +} diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index f9ad35dd6012..3f73b446ec2a 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -189,6 +189,11 @@ struct sd_switch_caps { #define SD_MAX_CURRENT_800 (1 << SD_SET_CURRENT_LIMIT_800) }; +struct sd_uhs2_config { + u32 node_id; + /* TODO: Extend with more register configs. */ +}; + struct sdio_cccr { unsigned int sdio_vsn; unsigned int sd_vsn; @@ -290,6 +295,7 @@ struct mmc_card { struct sd_scr scr; /* extra SD information */ struct sd_ssr ssr; /* yet more SD information */ struct sd_switch_caps sw_caps; /* switch (CMD6) caps */ + struct sd_uhs2_config uhs2_config; /* SD UHS-II config */ unsigned int sdio_funcs; /* number of SDIO functions */ atomic_t sdio_funcs_probed; /* number of probed SDIO funcs */ diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index a001ad2f5f23..0a777caaf7f3 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -63,6 +63,7 @@ struct mmc_ios { #define MMC_TIMING_MMC_HS400 10 #define MMC_TIMING_SD_EXP 11 #define MMC_TIMING_SD_EXP_1_2V 12 +#define MMC_TIMING_SD_UHS2 13 unsigned char signal_voltage; /* signalling voltage (1.8V or 3.3V) */ @@ -91,6 +92,10 @@ struct mmc_clk_phase_map { struct mmc_clk_phase phase[MMC_NUM_CLK_PHASES]; }; +struct sd_uhs2_caps { + /* TODO: Add UHS-II capabilities for the host. */ +}; + struct mmc_host; struct mmc_host_ops { @@ -126,6 +131,17 @@ struct mmc_host_ops { */ void (*set_ios)(struct mmc_host *host, struct mmc_ios *ios); + /* + * The uhs2_set_ios callback is mandatory to implement for hosts that + * supports the SD UHS-II interface (MMC_CAP2_SD_UHS2), while the + * callback is unused for the other cases. Note that, the struct + * mmc_ios is being re-used for this as well. + * + * Expected return values for the uhs2_set_ios callback are a negative + * errno in case of a failure or zero for success. + */ + int (*uhs2_set_ios)(struct mmc_host *host, struct mmc_ios *ios); + /* * Return values for the get_ro callback should be: * 0 for a read/write card @@ -377,6 +393,7 @@ struct mmc_host { MMC_CAP2_HS200_1_2V_SDR) #define MMC_CAP2_SD_EXP (1 << 7) /* SD express via PCIe */ #define MMC_CAP2_SD_EXP_1_2V (1 << 8) /* SD express 1.2V */ +#define MMC_CAP2_SD_UHS2 (1 << 9) /* SD UHS-II support */ #define MMC_CAP2_CD_ACTIVE_HIGH (1 << 10) /* Card-detect signal active high */ #define MMC_CAP2_RO_ACTIVE_HIGH (1 << 11) /* Write-protect signal active high */ #define MMC_CAP2_NO_PRESCAN_POWERUP (1 << 14) /* Don't power up before scan */ @@ -402,6 +419,8 @@ struct mmc_host { #define MMC_CAP2_CRYPTO 0 #endif + struct sd_uhs2_caps uhs2_caps; /* SD UHS-II capabilities */ + int fixed_drv_type; /* fixed driver type for non-removable media */ mmc_pm_flag_t pm_caps; /* supported pm features */ From patchwork Thu Feb 25 17:03:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 387228 Delivered-To: patches@linaro.org Received: by 2002:a02:290e:0:0:0:0:0 with SMTP id p14csp477012jap; Thu, 25 Feb 2021 09:04:10 -0800 (PST) X-Received: by 2002:a05:6512:3590:: with SMTP id m16mr2452293lfr.344.1614272650603; Thu, 25 Feb 2021 09:04:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614272650; cv=none; d=google.com; s=arc-20160816; b=sAwIAQKOG7UFbg4Y/Wu6ytRHUUqCmOGB4r64tYfqU1Cl8tqo+pm6GpeS2ssPttHoe9 lxkYjLMS0C2ho+YSbAmfmrGKtH6M8IWUVQc/7OdqLt539Ftozx9lD6V9UM7U0ipOInUv cnuDAgE+A6UUqqxNbOuuy6GU4lDF14uIjtaIHMJWeyJ/h8Tu9ozHwDLU6HzevMAZ1E4r I1OnngGFVeAwZ08j01Ko+z6mjHd504QAo2kXoWqZu3ASu0gbwaCgnyOenpe40Mr+UIUQ PCeM/i3rgUnucV7/dEq0ka5/uA35NAzF1zfoJJ7ZsEo82RBAPgL+HnZ6NqrIJXaUm5mQ briQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=ZVkhv4WLhPkQvvBDaC3A5L+BewGJsj7lWC/5+KaE4JA=; b=FfhikA5TylY7L6g/wNALkuFH2GiYOoNMU3QIxB9ziHcukcwmlfTxu3+/lMctsqQMGj pVV1vIl6lYm4iM6mGXPnWDyUeTZnE183xAQ8JEn9iiPEvlm1XSX9qeTDMsszhckucPY1 klehxezCpNTKeW4RgX4vf17ftk6FG8F5KlxP7xWPwRjb4WUUqArB8K8lRgS2MylRReNO A+oOg46IE9sF6/FF3qdCleXAiQz6zex0P60wVZWtgGdZOmBa6FEA6IPx2BCCqHUdCotq oZW+9Sp/lsBkY1EQL0dEYzBN5OeqBLQ/5+TBJcXCGb2M4nRTHgr7cBXGwxB9HossA8QH qHhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=enfH8oFi; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id e9sor1524509lfs.55.2021.02.25.09.04.10 for (Google Transport Security); Thu, 25 Feb 2021 09:04:10 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=enfH8oFi; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZVkhv4WLhPkQvvBDaC3A5L+BewGJsj7lWC/5+KaE4JA=; b=enfH8oFi28/hppzGCOifB4bJ74Bb94E6Vdwi3GjeNdzdskpS8ek8FB//2Rx3r/LI2M 8ngLNnIPsl1aGROSv4rIFHPg8s3mkN30n6yj0PaQ778NMwlmYeIoKJ+BovJTOnzx8NJh GpjkeSCCZ6/UpLIWQgF1y6mA3cjgZwEgpKZy3DXcOokdftd1jlxBL+FRxH58cgfuEzJV bfDXkCpbXdLAztgtCwIqlSQ/3RpU0cOSiBIdD829qkhBN0TUR3lRx78unnA84Uwn4Wr/ z0xWPQgRXOFW4zqUrtbZTGuiUCXtaz2MQUUETBE2p1hq/KZwb/a4CHCzvqhLKaMjVsPU ODLw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZVkhv4WLhPkQvvBDaC3A5L+BewGJsj7lWC/5+KaE4JA=; b=hJNJPp8jPdQnCViSUc7kjeZFNYRenLKBrNNiT0tQgrqGimwx3ErYeS3FArJy+f64E0 h7iGGxjA0/UA2OgWdgJsl9SC8aa3Tzn/iP+UQx/6ATopuSjNhyhEyhqHbmGWubFBpU3T 5WcT+IpGIj4g3oG3xRM6X3brXKIDUaSSj6Dm5BW79cH7Q28mx+M+9BabgmQ/FhS/nQuR IHDq+C3+TK3WBVcqLp5U/Mf9lDBjT/EZ2rRVIb6HEEb9L8EPgkGu3kg1kWPN5nFkWin/ 0WbxClMYDk6E9l+tXwjhtG84iroPyKoNx5kPzc61bgMN0VOObl6HPB8fWDZF/C/yAc1l uUXg== X-Gm-Message-State: AOAM531j/B1mwH2LX9NHNTBx39qnd8DqwwfU2l13n9bXy9ntkmrruzmR TPIMDDNQXrvesc23fWfi+f83B1pb X-Google-Smtp-Source: ABdhPJwBIn7qT2kk2z7x3v+0WSkxq4k+EqeVr0wX0+WBr8fHtR6BnMS1BIclwvkAmlKvish5zY1rvg== X-Received: by 2002:a05:6512:131f:: with SMTP id x31mr2485503lfu.552.1614272650258; Thu, 25 Feb 2021 09:04:10 -0800 (PST) Return-Path: Received: from localhost.localdomain (h-155-4-129-234.NA.cust.bahnhof.se. [155.4.129.234]) by smtp.gmail.com with ESMTPSA id b39sm1103749ljf.68.2021.02.25.09.04.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Feb 2021 09:04:09 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: AKASHI Takahiro , Ben Chuang , greg.tu@genesyslogic.com.tw, Renius Chen , Masami Hiramatsu , Takao Orito , linux-kernel@vger.kernel.org Subject: [PATCH 3/4] mmc: core: Announce successful insertion of an SD UHS-II card Date: Thu, 25 Feb 2021 18:03:51 +0100 Message-Id: <20210225170352.76872-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210225170352.76872-1-ulf.hansson@linaro.org> References: <20210225170352.76872-1-ulf.hansson@linaro.org> MIME-Version: 1.0 To inform the users about SD UHS-II cards, let's extend the print at card insertion with a "UHS-II" substring. Within this change, it seems reasonable to convert from using "ultra high speed" into "UHS-I speed", for the UHS-I type, as it should makes it more clear. Note that, the new print for UHS-II cards doesn't include the actual selected speed mode. Instead, this is going to be added from subsequent change. Signed-off-by: Ulf Hansson --- drivers/mmc/core/bus.c | 4 +++- drivers/mmc/core/host.h | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) -- 2.25.1 diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c index f4851ec8290c..887b0b80ac3f 100644 --- a/drivers/mmc/core/bus.c +++ b/drivers/mmc/core/bus.c @@ -353,7 +353,9 @@ int mmc_add_card(struct mmc_card *card) if (mmc_card_hs(card)) speed_mode = "high speed "; else if (mmc_card_uhs(card)) - speed_mode = "ultra high speed "; + speed_mode = "UHS-I speed "; + else if (mmc_card_uhs2(card)) + speed_mode = "UHS-II speed "; else if (mmc_card_ddr52(card)) speed_mode = "high speed DDR "; else if (mmc_card_hs200(card)) diff --git a/drivers/mmc/core/host.h b/drivers/mmc/core/host.h index ba407617ed23..76cb024a0868 100644 --- a/drivers/mmc/core/host.h +++ b/drivers/mmc/core/host.h @@ -83,5 +83,10 @@ static inline bool mmc_card_sd_express(struct mmc_host *host) host->ios.timing == MMC_TIMING_SD_EXP_1_2V; } +static inline bool mmc_card_uhs2(struct mmc_card *card) +{ + return card->host->ios.timing == MMC_TIMING_SD_UHS2; +} + #endif From patchwork Thu Feb 25 17:03:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 387229 Delivered-To: patches@linaro.org Received: by 2002:a02:290e:0:0:0:0:0 with SMTP id p14csp477063jap; Thu, 25 Feb 2021 09:04:13 -0800 (PST) X-Received: by 2002:a2e:8141:: with SMTP id t1mr2135702ljg.385.1614272653390; Thu, 25 Feb 2021 09:04:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614272653; cv=none; d=google.com; s=arc-20160816; b=Q6EHVEqXZtS6N5UulaJvPZOdg1mEuTNmHtJR8pVSGccMpztuYVCWH2MPrwpxrNWnVq e5kjcht5njdi83ZAv2z4MhaMtRC+ilMCVZsAVSdr2JQutzYM7tiiYX9Aj/hzgWilhknx L7qrDHknCj9jqdEyAIX/+pO4ujZxlettFevww5dT7hRKp4Tstyvg4tBW0uPHcOa0xve+ O4JMkPBMRkZxyIlyiRVnTyMBO9znbfr/sPKGFwGKze6wfgu0+W8JGFf3UcsE4aA/tYyh LrgyluIRMpJPBGLZAFuSRXQSxpKqpETuBsebqQJLKsuvW2D1XQRC/a3SiJqzOKfyCs7h y6Uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=e/iSON5QK+omS1XoqwWY7ETX5FXArOjI6pz19z6lB0I=; b=nKvjdQZgY5lmA6CkmOKl+bE21R1DvHI7wzgKb3cATqVINHTdYYMvpDwxzA+r5cl78A S92MUJ84kB42Akraqp1gTMNkkOU1s7GQJ/i8May8eiMSys6jFOPUbz1EeQydPhPC3u54 whrclw+qXZrTC7V1KN/rK2egzpK/VYWZ/iKFoSqaZiVcFuU71Iqv3NPV0nn9KrFDsj43 sNjMrBBuzzPDvyJxsMQ7uIKi3mrKttp9qpsMurlm/WJ+YEGyjwNp32g2F+YTQx/frFMz yz7jzjA6ISLz/uZYEvWC+vd+P9vk2CbL8jBwcofqJsiOnGRbKggN9vPqFsvGSpRPt0gM kR2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j6bY4H6k; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 6sor1480170lfy.50.2021.02.25.09.04.12 for (Google Transport Security); Thu, 25 Feb 2021 09:04:13 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j6bY4H6k; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e/iSON5QK+omS1XoqwWY7ETX5FXArOjI6pz19z6lB0I=; b=j6bY4H6kfrR0AN3pMN9cqLQivgCqUaS8EYdXbNzkj3DhKOys3gqvJdKERyEF7zKDvv BbFY5S8YB8Mfm18GmLWR7a+hGktWJflNKitgAKptY176lqfBwXP4Ej61uNqGS6p2HM34 GJqj7nc0IVINWxhrpON80l4Tl9IUj6YFL0xDRwhgfNiX28fm63EIuU2il+33zEJ2eSpe nKtOwu8KHwN6CHOp3Z/wc6sXdMMOShJYoL0R2kw3W7yS59Bze2AIWt0KSWixL8LDz31p h5asIv/FzpV+kqHv+3z+O432JbxBqIo8dj6M/jQWOgB6O1D/4ZmY+v8WCuxaVSvDlVW3 5YVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e/iSON5QK+omS1XoqwWY7ETX5FXArOjI6pz19z6lB0I=; b=HWg6UbLtBHiwlKqr55aMr6wyXQHRSC24vWDmwfhCETc8I11DJ+3vagMd17BbYJTdRi LjprXjgmcv/uY/1WkpK4MQG4N/K2cwHh68TjIaGEG/nQeDaTQnXenaYMqgx/DHYrZd0e kodD8s5hExdNEZox3rnhvjh9hHjawMGyHlIeSM+Xts4Gcj/18DTpkSNHwXCs/FlOtWBD 0tbGmRoguPaqNe1O3aNXAo2BTJXAFsPbSI5YUKo+19AUYiCWm6U7YAh5u7cOyAT8KoMe sfagzCklUDsfvRtrYyhIoB86kMn+uc9+BAd7nL+N97hwH+zYKKUFL3Kc4YK1TIrfZJYZ Rx2Q== X-Gm-Message-State: AOAM531EKFrF9DsHdB0tB+9J5V843xHjgr9aChpIFNMzZNsl3uElwMym 4qDyNHvuJRG4g/WnhKnX50/+UQBP X-Google-Smtp-Source: ABdhPJx+R9ayXorBaTSiwQJpj6otLXaJvnFpp+m0n+rGegnSlXrw1gvtGaes4gOSb//SiZkmcutOTw== X-Received: by 2002:a05:6512:398d:: with SMTP id j13mr2290695lfu.41.1614272652167; Thu, 25 Feb 2021 09:04:12 -0800 (PST) Return-Path: Received: from localhost.localdomain (h-155-4-129-234.NA.cust.bahnhof.se. [155.4.129.234]) by smtp.gmail.com with ESMTPSA id b39sm1103749ljf.68.2021.02.25.09.04.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Feb 2021 09:04:11 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: AKASHI Takahiro , Ben Chuang , greg.tu@genesyslogic.com.tw, Renius Chen , Masami Hiramatsu , Takao Orito , linux-kernel@vger.kernel.org Subject: [PATCH 4/4] mmc: core: Extend support for mmc regulators with a vqmmc2 Date: Thu, 25 Feb 2021 18:03:52 +0100 Message-Id: <20210225170352.76872-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210225170352.76872-1-ulf.hansson@linaro.org> References: <20210225170352.76872-1-ulf.hansson@linaro.org> MIME-Version: 1.0 To allow an additional external regulator to be controlled by an mmc host driver, let's add support for a vqmmc2 regulator to the mmc core. For an SD UHS-II interface the vqmmc2 regulator may correspond to the so called vdd2 supply, as described by the SD spec. Initially, only 1.8V is needed, hence limit the new helper function, mmc_regulator_set_vqmmc2() to this too. Note that, to allow for flexibility mmc host drivers need to manage the enable/disable of the vqmmc2 regulator themselves, while the regulator is looked up through the common mmc_regulator_get_supply(). Signed-off-by: Ulf Hansson --- drivers/mmc/core/regulator.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/mmc/host.h | 11 +++++++++++ 2 files changed, 45 insertions(+) -- 2.25.1 diff --git a/drivers/mmc/core/regulator.c b/drivers/mmc/core/regulator.c index 609201a467ef..3c189682797c 100644 --- a/drivers/mmc/core/regulator.c +++ b/drivers/mmc/core/regulator.c @@ -223,6 +223,33 @@ int mmc_regulator_set_vqmmc(struct mmc_host *mmc, struct mmc_ios *ios) } EXPORT_SYMBOL_GPL(mmc_regulator_set_vqmmc); +/** + * mmc_regulator_set_vqmmc2 - Set vqmmc2 as per the ios->vqmmc2_voltage + * @mmc: The mmc host to regulate + * @ios: The io bus settings + * + * Sets a new voltage level for the vqmmc2 regulator, which may correspond to + * the vdd2 regulator for an SD UHS-II interface. This function is expected to + * be called by mmc host drivers. + * + * Returns a negative error code on failure, zero if the voltage level was + * changed successfully or a positive value if the level didn't need to change. + */ +int mmc_regulator_set_vqmmc2(struct mmc_host *mmc, struct mmc_ios *ios) +{ + if (IS_ERR(mmc->supply.vqmmc2)) + return -EINVAL; + + switch (ios->vqmmc2_voltage) { + case MMC_VQMMC2_VOLTAGE_180: + return mmc_regulator_set_voltage_if_supported( + mmc->supply.vqmmc2, 1700000, 1800000, 1950000); + default: + return -EINVAL; + } +} +EXPORT_SYMBOL_GPL(mmc_regulator_set_vqmmc2); + #else static inline int mmc_regulator_get_ocrmask(struct regulator *supply) @@ -249,6 +276,7 @@ int mmc_regulator_get_supply(struct mmc_host *mmc) mmc->supply.vmmc = devm_regulator_get_optional(dev, "vmmc"); mmc->supply.vqmmc = devm_regulator_get_optional(dev, "vqmmc"); + mmc->supply.vqmmc2 = devm_regulator_get_optional(dev, "vqmmc2"); if (IS_ERR(mmc->supply.vmmc)) { if (PTR_ERR(mmc->supply.vmmc) == -EPROBE_DEFER) @@ -268,6 +296,12 @@ int mmc_regulator_get_supply(struct mmc_host *mmc) dev_dbg(dev, "No vqmmc regulator found\n"); } + if (IS_ERR(mmc->supply.vqmmc2)) { + if (PTR_ERR(mmc->supply.vqmmc2) == -EPROBE_DEFER) + return -EPROBE_DEFER; + dev_dbg(dev, "No vqmmc2 regulator found\n"); + } + return 0; } EXPORT_SYMBOL_GPL(mmc_regulator_get_supply); diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 0a777caaf7f3..ac9f45e3e203 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -65,6 +65,9 @@ struct mmc_ios { #define MMC_TIMING_SD_EXP_1_2V 12 #define MMC_TIMING_SD_UHS2 13 + unsigned char vqmmc2_voltage; +#define MMC_VQMMC2_VOLTAGE_180 0 + unsigned char signal_voltage; /* signalling voltage (1.8V or 3.3V) */ #define MMC_SIGNAL_VOLTAGE_330 0 @@ -299,6 +302,7 @@ struct mmc_pwrseq; struct mmc_supply { struct regulator *vmmc; /* Card power supply */ struct regulator *vqmmc; /* Optional Vccq supply */ + struct regulator *vqmmc2; /* Optional supply for phy */ }; struct mmc_ctx { @@ -579,6 +583,7 @@ int mmc_regulator_set_ocr(struct mmc_host *mmc, struct regulator *supply, unsigned short vdd_bit); int mmc_regulator_set_vqmmc(struct mmc_host *mmc, struct mmc_ios *ios); +int mmc_regulator_set_vqmmc2(struct mmc_host *mmc, struct mmc_ios *ios); #else static inline int mmc_regulator_set_ocr(struct mmc_host *mmc, struct regulator *supply, @@ -592,6 +597,12 @@ static inline int mmc_regulator_set_vqmmc(struct mmc_host *mmc, { return -EINVAL; } + +static inline int mmc_regulator_set_vqmmc2(struct mmc_host *mmc, + struct mmc_ios *ios) +{ + return -EINVAL; +} #endif int mmc_regulator_get_supply(struct mmc_host *mmc);