From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 555D11D6C7F; Fri, 13 Sep 2024 10:28:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223331; cv=none; b=ZpCqhE3wluh8ub+MO4f2VkCyQ8gfkqE9RpI5oUTogQzGC+GV/eukJKTY99PoDJz8kLmw989tUNWnh9XZ+GXs2bC8ZEPGudrwxAfHf005pw2UNDUwb+IJvpthVGNw6lyJirpRrVRFF+WueFAFtXHsiA7OaU2HER3L29OS11wTwtw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223331; c=relaxed/simple; bh=IQAZUlNPZoWpHJGkIKUhv6elpxjgoL6OEDDw8Puqvbs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Xp0dDBzZGuW2JuY0vkdEoAFK/jjclLAnNPFfincIrbwjOabbg+zRfF4WcT+kyCHp/MwJeDGboY5zrjlSXlk9CPZLUuRhqr09X25D8SmGb9LaV4vyMcyQuyDRy5K5W6taezu2EM7Hc1ldXez2miEk4jhSn4W7j+nhRxD++bvXeW0= 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=QmUPBEdK; arc=none smtp.client-ip=209.85.210.171 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="QmUPBEdK" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-718f4fd89e5so1814077b3a.0; Fri, 13 Sep 2024 03:28:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223329; x=1726828129; 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=21XTRS6Hwv0Mc2USbIbApfyvP84+Xjin/dyUCVlMQQw=; b=QmUPBEdKR6tlShvJ9EE1SP81XQLhU85weRHxOFzgVTigNvJ7u3WxOABXOdQi9ijCo7 MzhOXOqnTPF2wNnsPla4Y3fQvm+pGN+hqLC6Iy4e5qVwe56KuU0WVwoc7K5YG/uy5U3I ThBc3NH/ujnU+sTnz78HEfUFFx0iefPaNtM1bLqdVrI0lS/pnfuCzejDcuq1UtxhmjcG zgE/moKB0wKSIfI54LX3DG4npVHsWmtvTm6lTJr2QxR1JXOVec1vd2uJz2ep3WtZUZHn PGhy1se24ttWcfr86dQDAKmYsYiV/tSjVIYlv3yPhUIskqAKgqvM3OXY4pFJT6uz37fx RUig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223329; x=1726828129; 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=21XTRS6Hwv0Mc2USbIbApfyvP84+Xjin/dyUCVlMQQw=; b=gU6wSMKQ3K3h6ylqUPSOYqXvJxlyViKQxmS4Hljt8zE5oSRaQIpyOp5jKQ2FUd1oHe fxfRvbj5j39mXQaYL4aRuFAhj0bKjFOAcSIUkkaZqVWkdWCStG2Mmc/QJAOUrSPj3wOW v3Frj9L+JP3ra1xol6jounxsJvY3KPIr8fcRyYusW2JmF/A/l11neZj53hpZDXjMiJ+Y BKmOePc11vXfd3vb0KJSJKpc+Cut2/zV95pBLpKp7TDCNQLwnSb3nbfkacs2a/y9S9So UuEJdpSPxmodAlfz2aT/+TKD9Ix8T0zMxPBOaFKoIVKhsNQ5t95FM9jC3MnTwiku81ny 4/tA== X-Forwarded-Encrypted: i=1; AJvYcCX6/yKiIa+W4FIjyCbyj+uU8oQkqOOHJdJ4MjYcm28XLHRHv1bv7co/lG58CVlcFyUDDB/bGyiRUtZY18A=@vger.kernel.org X-Gm-Message-State: AOJu0YxVbparHZLvwklqT1ZOIqUuGXg7qJ+BhSSxJcHAPsIabApOCdwh WdRKZZF85u0G3i9WcS9KxD+tnzz7B/NZUACEJsNv5LU6CfDHMp+C X-Google-Smtp-Source: AGHT+IE98jVxFTMHaqMEevVMxdyJgriYN/ox/a+pTzi9hZJt1UpWEceEfTSEF4RtOts4rXxc3TxvhA== X-Received: by 2002:a05:6a21:394b:b0:1cf:5c1d:83f4 with SMTP id adf61e73a8af0-1cf75eee771mr8027481637.16.1726223329503; Fri, 13 Sep 2024 03:28: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.28.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:28: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 Subject: [PATCH V22 01/22] mmc: core: Cleanup printing of speed mode at card insertion Date: Fri, 13 Sep 2024 18:28:15 +0800 Message-Id: <20240913102836.6144-2-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: Ulf Hansson 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 Acked-by: Adrian Hunter --- drivers/mmc/core/bus.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c index 0ddaee0eae54..6731b46e855f 100644 --- a/drivers/mmc/core/bus.c +++ b/drivers/mmc/core/bus.c @@ -299,6 +299,7 @@ int mmc_add_card(struct mmc_card *card) { int ret; const char *type; + const char *speed_mode =3D ""; const char *uhs_bus_speed_mode =3D ""; static const char *const uhs_speeds[] =3D { [UHS_SDR12_BUS_SPEED] =3D "SDR12 ", @@ -340,27 +341,30 @@ int mmc_add_card(struct mmc_card *card) break; } =20 + if (mmc_card_hs(card)) + speed_mode =3D "high speed "; + else if (mmc_card_uhs(card)) + speed_mode =3D "ultra high speed "; + else if (mmc_card_ddr52(card)) + speed_mode =3D "high speed DDR "; + else if (mmc_card_hs200(card)) + speed_mode =3D "HS200 "; + else if (mmc_card_hs400es(card)) + speed_mode =3D "HS400 Enhanced strobe "; + else if (mmc_card_hs400(card)) + speed_mode =3D "HS400 "; + if (mmc_card_uhs(card) && (card->sd_bus_speed < ARRAY_SIZE(uhs_speeds))) uhs_bus_speed_mode =3D uhs_speeds[card->sd_bus_speed]; =20 - 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); - } =20 mmc_add_card_debugfs(card); card->dev.of_node =3D mmc_of_find_child_device(card->host, 0); --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (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 902E51D86D2; Fri, 13 Sep 2024 10:28:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223336; cv=none; b=PPJPZ9wam1AV7UsdiYIcWVta+Pu3c0NADhmafeS1Dul7sM3Flpub5EbviRYD7vbIqkWCw+1M0CbooNnp8oXzqAtKwwk04Dk4Oju17pomSj9KRMEE0Y/IgDpJyV1Nh4rapW+xalL2R0aEqb+fF4Y1EytazK4z23/79OYpEM0or18= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223336; c=relaxed/simple; bh=D0utnBjsKoMtx+O2SqzLRFVGeHptMAwUwvHSK4dbKDU=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=OKvfUTKRFfoQRnHdDuEOIWo7B5hIEG9f3kGj6RLyDjGOgK67GWQ/Md8/lgjPM2WLf+G0exmEzJo0mQCrziGTaaLRwLRxDUjvJlHtw+fSxCnhYtZCl8SQxFz2Uk/aJMJvTBoy4CKspxO9aYlJBejuJYj3XuhUtR5ihSLxH2X9wlY= 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=bx02/+PW; arc=none smtp.client-ip=209.85.215.171 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="bx02/+PW" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-7db233cef22so514858a12.0; Fri, 13 Sep 2024 03:28:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223334; x=1726828134; 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=EIm7/B6JKcy+vxXDucWyb4OAn1sfPoczDFEyRxGVXAk=; b=bx02/+PWKdutgB0rKbgAy/NewafXi2TNIPtC9r++27+GcZxBvNkBC5emC81KGeSTYP yPkZIVFc7kP+ueLV7qq/McggF/SQSyV5egMr/lnqK8XmiopLThQ76waQJFG9ishLhe1l 98DzN7dO85IufHCV7f/0ysQtDKykkWuMNH+XZUIzwvJJFP7mfwQfnb/r8jAA2OqAYYgR G8S7iBD6LBbU1zv8oC1I2y84wLefynnU7az3qL20DTFKGlW8J/XTgksldbO7mZt09Xch V1kvrPxPUmjqAkTjK7CK5LHDn9ACASwmKZ4IUq/1ei+YduGKVME2Vqn1TRBB5lMBnS3w GaOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223334; x=1726828134; 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=EIm7/B6JKcy+vxXDucWyb4OAn1sfPoczDFEyRxGVXAk=; b=mjJQ6kGTo7mqHlEg5VC2Tlg4BHdm1IYS3JWhsV2elxyvGpRVok+d+hKY+KMMxCofvV DeKOQyVfTIijekU8nKK27SJ9YI5iGuIZofTvNUmCl0odhGPRVVgD8VPZfr1sRno3rTTl 1BSEVzb5CRiZOfWuha7MeX6GEwxhUPXKdOAky9FofV5ljbHews8FibB/0gUlmPDISHfw AT+l6rB07Qke03gS/Zq9QhXdOFNUvn55jhf4qxESUTfbwlMnAYmB0qMCV/P2oTO4Pkg7 5I312eDDb59/qyfyFAjVLUvhny0PvetfmytRzl1pm/FGYYvLU5JsK4+InfQCjEjcI/rc uNXw== X-Forwarded-Encrypted: i=1; AJvYcCWDs315tc7ORLvGqu9NEZv9WSyksI/K+0KBwABIr0y+Skp4f1tGQnUANa4mP5t7YCYrYCJk/dofZWDKdUI=@vger.kernel.org X-Gm-Message-State: AOJu0YzEPqte0L8UFlsU2K/WwLRQ6TKt/u0aAM7QepP0rqqirWomwBHZ qZvjV6m9ZhreY2sDYD8KQwgIgeohqvRJs755NH6FmMj9vqQ978drWJA30om5 X-Google-Smtp-Source: AGHT+IG8vuVCjqKUwTEeH9IVvt7uVbH5b/6EvT8qZHtlXe9FXrLAligDCDOeHeDKFGtIRf2RXKNtYA== X-Received: by 2002:a05:6a20:e609:b0:1cf:6dd7:fa50 with SMTP id adf61e73a8af0-1d112b60ef1mr3471029637.11.1726223333505; Fri, 13 Sep 2024 03:28:53 -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.28.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:28:53 -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 Subject: [PATCH V22 02/22] mmc: core: Prepare to support SD UHS-II cards Date: Fri, 13 Sep 2024 18:28:16 +0800 Message-Id: <20240913102836.6144-3-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: Ulf Hansson 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 Acked-by: Adrian Hunter --- Updates in V10: - Drop unnecessary definitions and code. Updates in V9: - move sd_uhs2_operation definition of PatchV8[05/23] to PatchV9[02/23] for avoid compilation errors. - move uhs2_control definition of PatchV8[05/23] to PatchV9[02/23] for avoid compilation errors. - move mmc_host flags definition of PatchV8[05/23] to PatchV9[02/23] for avoid compilation errors. - move mmc_host flags MMC_UHS2_SUPPORT definition of PatchV8[05/23] to PatchV9[02/23] for avoid compilation errors. - move mmc_host flags MMC_UHS2_SD_TRAN definition of PatchV8[05/23] to PatchV9[02/23] for avoid compilation errors. Updates in V7: - Drop sd_uhs2_set_ios function. - Used ->uhs2_control() callback for uhs2_set_ios in sd_uhs2_power_up(). - Used ->uhs2_control() callback for uhs2_set_ios in sd_uhs2_power_off(). - Drop MMC_TIMING_SD_UHS2 in favor of MMC_TIMING_UHS2_SPEED_A. - Modify sd_uhs2_legacy_init to avoid sd_uhs2_reinit cycle issue. Updates in V4: - Re-based, updated a comment and removed white-space. - Moved MMC_VQMMC2_VOLTAGE_180 into a later patch in the series. =20 --- drivers/mmc/core/Makefile | 2 +- drivers/mmc/core/core.c | 17 ++- drivers/mmc/core/core.h | 1 + drivers/mmc/core/sd_uhs2.c | 292 +++++++++++++++++++++++++++++++++++++ include/linux/mmc/card.h | 7 + include/linux/mmc/host.h | 23 +++ 6 files changed, 340 insertions(+), 2 deletions(-) create mode 100644 drivers/mmc/core/sd_uhs2.c diff --git a/drivers/mmc/core/Makefile b/drivers/mmc/core/Makefile index 6a907736cd7a..15b067e8b0d1 100644 --- a/drivers/mmc/core/Makefile +++ b/drivers/mmc/core/Makefile @@ -7,7 +7,7 @@ obj-$(CONFIG_MMC) +=3D mmc_core.o mmc_core-y :=3D 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 \ + sdio_cis.o sdio_io.o sdio_irq.o sd_uhs2.o\ slot-gpio.o regulator.o mmc_core-$(CONFIG_OF) +=3D pwrseq.o obj-$(CONFIG_PWRSEQ_SIMPLE) +=3D pwrseq_simple.o diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index d6c819dd68ed..8b8aff131f8b 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2249,6 +2249,18 @@ void mmc_rescan(struct work_struct *work) goto out; } =20 + /* + * 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 =3D 0; i < ARRAY_SIZE(freqs); i++) { unsigned int freq =3D freqs[i]; if (freq > host->f_max) { @@ -2281,10 +2293,13 @@ void mmc_rescan(struct work_struct *work) =20 void mmc_start_host(struct mmc_host *host) { + bool power_up =3D !(host->caps2 & + (MMC_CAP2_NO_PRESCAN_POWERUP | MMC_CAP2_SD_UHS2)); + host->f_init =3D max(min(freqs[0], host->f_max), host->f_min); host->rescan_disable =3D 0; =20 - 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 37091a6589ed..920323faa834 100644 --- a/drivers/mmc/core/core.h +++ b/drivers/mmc/core/core.h @@ -81,6 +81,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); =20 /* 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..beb2541338ff --- /dev/null +++ b/drivers/mmc/core/sd_uhs2.c @@ -0,0 +1,292 @@ +// 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[] =3D { 52000000, 26000000 }; + +static int sd_uhs2_power_up(struct mmc_host *host) +{ + int err; + + if (host->ios.power_mode =3D=3D MMC_POWER_ON) + return 0; + + host->ios.vdd =3D fls(host->ocr_avail) - 1; + host->ios.clock =3D host->f_init; + host->ios.timing =3D MMC_TIMING_UHS2_SPEED_A; + host->ios.power_mode =3D MMC_POWER_ON; + + err =3D host->ops->uhs2_control(host, UHS2_SET_IOS); + + return err; +} + +static int sd_uhs2_power_off(struct mmc_host *host) +{ + if (host->ios.power_mode =3D=3D MMC_POWER_OFF) + return 0; + + host->ios.vdd =3D 0; + host->ios.clock =3D 0; + host->ios.timing =3D MMC_TIMING_LEGACY; + host->ios.power_mode =3D MMC_POWER_OFF; + + return host->ops->uhs2_control(host, UHS2_SET_IOS); +} + +/* + * 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 bro= adcast + * 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 car= d. + * Note that, we currently support only the point to point connection, whi= ch + * 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 sendi= ng it + * commands and by parsing the responses. Store a copy of the relevant dat= a in + * card->uhs2_config. + */ +static int sd_uhs2_config_read(struct mmc_host *host, struct mmc_card *car= d) +{ + 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 t= o a + * greater speed range/mode. Depending on the updated configuration, we ma= y need + * to do a soft reset of the card via sending it a GO_DORMANT_STATE comman= d. + * + * 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 *ca= rd) +{ + return 0; +} + +/* + * Initialize the UHS-II card through the SD-TRAN transport layer. This en= ables + * commands/requests to be backwards compatible through the legacy SD prot= ocol. + * UHS-II cards has a specific power limit specified for VDD1/VDD2, that s= hould + * be set through a legacy CMD6. Note that, the power limit that becomes s= et, + * survives a soft reset through the GO_DORMANT_STATE command. + */ +static int sd_uhs2_legacy_init(struct mmc_host *host, struct mmc_card *car= d) +{ + 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 =3D sd_uhs2_dev_init(host); + if (err) + return err; + + err =3D sd_uhs2_enum(host, &node_id); + if (err) + return err; + + card =3D mmc_alloc_card(host, &sd_type); + if (IS_ERR(card)) + return PTR_ERR(card); + + card->uhs2_config.node_id =3D node_id; + card->type =3D MMC_TYPE_SD; + + err =3D sd_uhs2_config_read(host, card); + if (err) + goto err; + + err =3D sd_uhs2_config_write(host, card); + if (err) + goto err; + + host->card =3D 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 =3D 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 =3D _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 =3D { + .remove =3D sd_uhs2_remove, + .alive =3D sd_uhs2_alive, + .detect =3D sd_uhs2_detect, + .suspend =3D sd_uhs2_suspend, + .resume =3D sd_uhs2_resume, + .runtime_suspend =3D sd_uhs2_runtime_suspend, + .runtime_resume =3D sd_uhs2_runtime_resume, + .shutdown =3D sd_uhs2_shutdown, + .hw_reset =3D sd_uhs2_hw_reset, +}; + +static int sd_uhs2_attach(struct mmc_host *host) +{ + int err; + + err =3D sd_uhs2_power_up(host); + if (err) + goto err; + + err =3D sd_uhs2_phy_init(host); + if (err) + goto err; + + err =3D sd_uhs2_init_card(host); + if (err) + goto err; + + err =3D sd_uhs2_legacy_init(host, host->card); + if (err) + goto err; + + mmc_attach_bus(host, &sd_uhs2_ops); + + mmc_release_host(host); + + err =3D 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 =3D 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 =3D 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 =3D 0; i < ARRAY_SIZE(sd_uhs2_freqs); i++) { + host->f_init =3D sd_uhs2_freqs[i]; + err =3D sd_uhs2_attach(host); + if (!err) + break; + } + + return err; +} diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index f34407cc2788..e256b1e70c6e 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -209,6 +209,11 @@ struct sd_ext_reg { #define SD_EXT_PERF_CMD_QUEUE (1<<4) }; =20 +struct sd_uhs2_config { + u32 node_id; + /* TODO: Extend with more register configs. */ +}; + struct sdio_cccr { unsigned int sdio_vsn; unsigned int sd_vsn; @@ -319,6 +324,8 @@ struct mmc_card { struct sd_ext_reg ext_power; /* SD extension reg for PM */ struct sd_ext_reg ext_perf; /* SD extension reg for PERF */ =20 + 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 */ struct sdio_cccr cccr; /* common card info */ diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 6a31ed02d3ff..21df3d6f7473 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -63,6 +63,10 @@ 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_UHS2_SPEED_A 13 +#define MMC_TIMING_UHS2_SPEED_A_HD 14 +#define MMC_TIMING_UHS2_SPEED_B 15 +#define MMC_TIMING_UHS2_SPEED_B_HD 16 =20 unsigned char signal_voltage; /* signalling voltage (1.8V or 3.3V) */ =20 @@ -91,6 +95,14 @@ struct mmc_clk_phase_map { struct mmc_clk_phase phase[MMC_NUM_CLK_PHASES]; }; =20 +struct sd_uhs2_caps { + /* TODO: Add UHS-II capabilities for the host. */ +}; + +enum sd_uhs2_operation { + UHS2_SET_IOS, +}; + struct mmc_host; =20 enum mmc_err_stat { @@ -218,6 +230,14 @@ struct mmc_host_ops { =20 /* Initialize an SD express card, mandatory for MMC_CAP2_SD_EXP. */ int (*init_sd_express)(struct mmc_host *host, struct mmc_ios *ios); + + /* + * The uhs2_control callback is used to execute SD UHS-II specific + * operations. It's mandatory to implement for hosts that supports the + * SD UHS-II interface (MMC_CAP2_SD_UHS2). Expected return values are a + * negative errno in case of a failure or zero for success. + */ + int (*uhs2_control)(struct mmc_host *host, enum sd_uhs2_operation op); }; =20 struct mmc_cqe_ops { @@ -378,6 +398,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 hig= h */ #define MMC_CAP2_RO_ACTIVE_HIGH (1 << 11) /* Write-protect signal active h= igh */ #define MMC_CAP2_NO_PRESCAN_POWERUP (1 << 14) /* Don't power up before sca= n */ @@ -404,6 +425,8 @@ struct mmc_host { #endif #define MMC_CAP2_ALT_GPT_TEGRA (1 << 28) /* Host with eMMC that has GPT en= try at a non-standard location */ =20 + struct sd_uhs2_caps uhs2_caps; /* Host UHS-II capabilities */ + int fixed_drv_type; /* fixed driver type for non-removable media */ =20 mmc_pm_flag_t pm_caps; /* supported pm features */ --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 DFCDD1D86EE; Fri, 13 Sep 2024 10:28:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223339; cv=none; b=aXBfirO8lyIvlEqjzWKDdGKuQ90gHwYD9NZs9by9LUJYzEg2/iv+3fwBYETmyI1ABWqDlkZHvCsG2TpsUXSBCxsxq9k2VMP+DD3FL7UBdLz34VxW9yy6SqL3qf9FNQ+PASvh0W2b31ziNjH/hTwqZEhnE8bP2q9VjLlvGgvpGoM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223339; c=relaxed/simple; bh=6+Nf5/9K+OHRrwoZr6U9n4pyW8vGxOX33Ds13iGam8c=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=f5A+3cIc0KdtN8P9WxrgV8Zu44kyzyhA1DH7lMB0Eevcgy+MEpPuesOAzyqh1edZdqTecDjifAS3SA71uOkVYpAZqrP+tEDytyE1Kvu2w7O0nNrNze6vjQ2096sTQDtGsRyUR+foRNWlOSazyjIkdKZ+zMMTmbwXihosLAT0NE0= 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=UVU0clXb; arc=none smtp.client-ip=209.85.214.177 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="UVU0clXb" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2053616fa36so23179735ad.0; Fri, 13 Sep 2024 03:28:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223337; x=1726828137; 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=5eNmn+upOObWpmwFmRKwEaFcUhxqumDAQxIm2bYLN7o=; b=UVU0clXbW2A2fb+N0cnf1oQSt3JMZNCFtLzyAkOKw3NKuOge4MdnfVDCxuUmddcTUf FO+FL4X2QZEByBKMc9WqD7O52/neu/VWNOxHhjYgOY/W4N3/aupOkkGIGdnxqGXPrvBr gKSK4Q59m4vDs4/fAsAP8fyL/SQlZrjiR3MIfHjVTVJU2UJEzT75bVzOAkxV02wk8G3n 9qDyECDy76UPs6tKz+rk0hZY3391ymWUI8aYVQ0Drgl4tGRrOvRO6KFdDKG1J2rUcZHI Iwd2x6Dq9xl/fYA8S4IrOtRe9n0ICObiUHIAPEXEYh6LRAcPPESZD5I9P/eObNpthujt 3o0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223337; x=1726828137; 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=5eNmn+upOObWpmwFmRKwEaFcUhxqumDAQxIm2bYLN7o=; b=OCCy3GNzdxPtTfKlVp7N1H1ajlSFStJLELEPEpXcuQ044zJliReMXYTf5CrmNU4PIU 93cN3KO0p8OPa2zmhevXfvnNgGB6LgnyzFWBWKtzRknOVltHfFxjP6LHJKqgDQAswlTk HpopApai8baax1wqAjC3yYcjN2kAbEzyNcDWwB3QQ3s4yc96U0L3iKAmX5K7SQqxfo3B NQnQauQndvZKkzCPTBeljPVnTWtIiI+vut6VwQvcyFChpmfK0TFSS58tqCGx+TXMAuw+ 9XZVnNMa7r1Oh8U1bosiXC+QDkT4G1zbKiADKfWGsf2XDFAsCQHVGk9dw8cueKb4Am2C /hBg== X-Forwarded-Encrypted: i=1; AJvYcCW6UGlIkHRUWgNtP/8FBmOCMImV2hOoSuQmIEWD91RrkbXeR56n/EK1PhVKULBlgQX13Yb5OBEDEYbIQ/U=@vger.kernel.org X-Gm-Message-State: AOJu0YwgUus3bGN9bHiqZpe4A3NlvqNueqXF+YeJO2Mc6RAi/kq0NnEJ /NVtwdo7WP6Kr53x0Q37tF+qTL+RZWiSIbgbHIyYpKEhPrPrh9it X-Google-Smtp-Source: AGHT+IFol6J4f8mKy5zxqL7tMcOKYqkpgoG/jO4MwSoZJByLiUku3W/KdxITPORce8ONPwY+lFxPfw== X-Received: by 2002:a17:903:18f:b0:205:810a:190a with SMTP id d9443c01a7336-2076e305f90mr98819225ad.2.1726223337170; Fri, 13 Sep 2024 03:28:57 -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.28.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:28:56 -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 Subject: [PATCH V22 03/22] mmc: core: Announce successful insertion of an SD UHS-II card Date: Fri, 13 Sep 2024 18:28:17 +0800 Message-Id: <20240913102836.6144-4-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: Ulf Hansson 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 Acked-by: Adrian Hunter --- Updates in V14: - Move mmc_card_uhs2() to include/linux/mmc/host.h, so that mmc_card_uhs2() can be available for host drivers. Updates in V10: - Modify the commit message. Updates in V7: - Drop MMC_TIMING_SD_UHS2 in favor of MMC_TIMING_UHS2_SPEED_A in mmc_card_uhs2 function. Updates in V4: - Make mmc_card_uhs2() take struct mmc_host* as in-param. --- drivers/mmc/core/bus.c | 4 +++- include/linux/mmc/host.h | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c index 6731b46e855f..f9a67beb68f0 100644 --- a/drivers/mmc/core/bus.c +++ b/drivers/mmc/core/bus.c @@ -344,7 +344,9 @@ int mmc_add_card(struct mmc_card *card) if (mmc_card_hs(card)) speed_mode =3D "high speed "; else if (mmc_card_uhs(card)) - speed_mode =3D "ultra high speed "; + speed_mode =3D "UHS-I speed "; + else if (mmc_card_uhs2(card->host)) + speed_mode =3D "UHS-II speed "; else if (mmc_card_ddr52(card)) speed_mode =3D "high speed DDR "; else if (mmc_card_hs200(card)) diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 21df3d6f7473..f1cf09ea1f72 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -637,6 +637,14 @@ static inline int mmc_card_uhs(struct mmc_card *card) card->host->ios.timing <=3D MMC_TIMING_UHS_DDR50; } =20 +static inline bool mmc_card_uhs2(struct mmc_host *host) +{ + return host->ios.timing =3D=3D MMC_TIMING_UHS2_SPEED_A || + host->ios.timing =3D=3D MMC_TIMING_UHS2_SPEED_A_HD || + host->ios.timing =3D=3D MMC_TIMING_UHS2_SPEED_B || + host->ios.timing =3D=3D MMC_TIMING_UHS2_SPEED_B_HD; +} + void mmc_retune_timer_stop(struct mmc_host *host); =20 static inline void mmc_retune_needed(struct mmc_host *host) --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.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 983801D88BB; Fri, 13 Sep 2024 10:29:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223343; cv=none; b=gesycLZ7jvbE+5x7QWUKv9gQAzjlwxzBLu8GYoX1S3Q8Sbt623HSRfZX6NZnpS/lczy1dQ4alm6F1VCIcM5D0i6OqnvBlurAf2bDK9OBVnySLYqzmw8lRs/y4FtKzUVSQCMTmbHfLRjGt4wPXgUQmcSeXiAqZqUwMlh6xCilz8M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223343; c=relaxed/simple; bh=9yNbvwz6yb/3G/OsIahUHIQ0tAuP/rL6iEJz54zI/s4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=O2yOJOIVXlM+CXq55kQLerzg+6m/cFxCM4qenRgunenYNMMo87vnpWnjCUYXBQ+otuD3YOkjt1v0mL5gO2/Lr/5lDa1mmII82faval0ZLwmpBcFUKDB1pmCvNgw+ueh+LI9Pd569h/FYnJssL/6Xb5pFAyJ5uIYsRH6y50WaY5E= 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=Y/SeJSFW; arc=none smtp.client-ip=209.85.214.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="Y/SeJSFW" Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-205659dc63aso21108225ad.1; Fri, 13 Sep 2024 03:29:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223341; x=1726828141; 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=BhL+kkVUd6coagoEa7icWXpPCycMAWuDumnQ5UDpr7U=; b=Y/SeJSFWv5DrpsI/lT2qYxtCKrMHoy/CEXOyGHDOR+Q+Rv0l90pQ2iTEiqpkG0J1oi MBFrOlVyf5bKUJOAcGzc3ILeiyV6Ezc9HyLyLqYgUH2/YPpodJbJLIupcj8PNatN/GBP bES+3KanCML5fP9aRnBiSWxULteP0h5tKCtji92ewd8mhMT6jkvCJdfDV/jiVX+jZiAp EK9n9jnV18SDBNeyXKMi3LIKsrBxkgsbyQ3ZS7IUfOpBGUyZe8osJSOeKhhlWFg3V8jJ 26LRrktfwTe3U8MWkxORqpEeTJIOEIe6j6sdgY0ojsoN4wgxQ3EPDtGbzYB1e87mzL+V AVxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223341; x=1726828141; 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=BhL+kkVUd6coagoEa7icWXpPCycMAWuDumnQ5UDpr7U=; b=XwgPiWHC78x7sWk81of8tGcMFS9HYJWyuPPkJ+M3fAwozDnyGgGWo/B4TfmY6UaLHC tWrYB6kxpBIH0oXtcCjfu8Xw8mt4YxHA8knG/SfC6f60cNNFXenJM5IyoGxxn32pxIto 1DrUFJyfH/7JCykTy2r3IhIJwxc528IaNOPIFXOiekSEXB6O+kjGi0ALa7LH0iJkyoyn gUow9Q3NWqM0mxk6FqGI9gxAAOr33ixasAtTvunBI4SOQ1FMzux/tD3MFnBeGuCHd+ka kcIDHuMhKgq13PE36NZu8nT3vTmz89fcHfoehP2JzwqsfWzodRc1gFqHiqzB5ACYhDL8 2RWg== X-Forwarded-Encrypted: i=1; AJvYcCU4Lr1dvJloHtekEr53sSx0ec8vs8uk15NOImKixyQ2YfaeuB9sFt/BHIzvmkk8XWdia0kSuSrQEd+lCmY=@vger.kernel.org X-Gm-Message-State: AOJu0YynYXU3tfUTze+cTWv1PYHt3PMyV+8c5USXLySUrizuphEHHfdc n62qQ64vx7slFFnawhU+e9LBzGOi5lbtJuiTK9cO8k4nHHc4/8Rb X-Google-Smtp-Source: AGHT+IHXDmmXAq084Qhqwaq8dB/jcaEjQvn0hfyom5ubAEt+G+LfWJYllFRr35Jxc6HLweHHscXARg== X-Received: by 2002:a17:902:ecc5:b0:205:43d8:710f with SMTP id d9443c01a7336-2076e4df8efmr62249875ad.58.1726223340766; Fri, 13 Sep 2024 03:29:00 -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.28.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:29:00 -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 Subject: [PATCH V22 04/22] mmc: core: Extend support for mmc regulators with a vqmmc2 Date: Fri, 13 Sep 2024 18:28:18 +0800 Message-Id: <20240913102836.6144-5-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: Ulf Hansson 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 Acked-by: Adrian Hunter --- Updates in V10: - Modify the commit message. Updates in V4: - Moved the voltage defines into this patch. --- drivers/mmc/core/regulator.c | 34 ++++++++++++++++++++++++++++++++++ include/linux/mmc/host.h | 11 +++++++++++ 2 files changed, 45 insertions(+) diff --git a/drivers/mmc/core/regulator.c b/drivers/mmc/core/regulator.c index 005247a49e51..208c27cfa505 100644 --- a/drivers/mmc/core/regulator.c +++ b/drivers/mmc/core/regulator.c @@ -226,6 +226,33 @@ int mmc_regulator_set_vqmmc(struct mmc_host *mmc, stru= ct mmc_ios *ios) } EXPORT_SYMBOL_GPL(mmc_regulator_set_vqmmc); =20 +/** + * 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 expecte= d 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 ch= ange. + */ +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 =20 static inline int mmc_regulator_get_ocrmask(struct regulator *supply) @@ -252,6 +279,7 @@ int mmc_regulator_get_supply(struct mmc_host *mmc) =20 mmc->supply.vmmc =3D devm_regulator_get_optional(dev, "vmmc"); mmc->supply.vqmmc =3D devm_regulator_get_optional(dev, "vqmmc"); + mmc->supply.vqmmc2 =3D devm_regulator_get_optional(dev, "vqmmc2"); =20 if (IS_ERR(mmc->supply.vmmc)) { if (PTR_ERR(mmc->supply.vmmc) =3D=3D -EPROBE_DEFER) @@ -271,6 +299,12 @@ int mmc_regulator_get_supply(struct mmc_host *mmc) dev_dbg(dev, "No vqmmc regulator found\n"); } =20 + if (IS_ERR(mmc->supply.vqmmc2)) { + if (PTR_ERR(mmc->supply.vqmmc2) =3D=3D -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 f1cf09ea1f72..841f0ba850aa 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -74,6 +74,9 @@ struct mmc_ios { #define MMC_SIGNAL_VOLTAGE_180 1 #define MMC_SIGNAL_VOLTAGE_120 2 =20 + unsigned char vqmmc2_voltage; +#define MMC_VQMMC2_VOLTAGE_180 0 + unsigned char drv_type; /* driver type (A, B, C, D) */ =20 #define MMC_SET_DRIVER_TYPE_B 0 @@ -307,6 +310,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 */ }; =20 struct mmc_ctx { @@ -589,6 +593,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, @@ -602,6 +607,12 @@ static inline int mmc_regulator_set_vqmmc(struct mmc_h= ost *mmc, { return -EINVAL; } + +static inline int mmc_regulator_set_vqmmc2(struct mmc_host *mmc, + struct mmc_ios *ios) +{ + return -EINVAL; +} #endif =20 int mmc_regulator_get_supply(struct mmc_host *mmc); --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pg1-f171.google.com (mail-pg1-f171.google.com [209.85.215.171]) (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 E069E1D9328; Fri, 13 Sep 2024 10:29:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223347; cv=none; b=EK8Q8JJ9NlFJHlnXwEIwMhwUkpjN51zE6Ldh7IUDnx7dvrMJmk+7+G27OcG/P7uafU4+wu7pAhdVXEuhPUXAOsX/AiuYTg0aHBXqKeabz8d2yaEozxsJyg57ZDzFEuTvjHw1+cTo1IwLZw5n6RmOd34oIoHqAVW8BKWTnRrJyK0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223347; c=relaxed/simple; bh=erm4A1seNgVAWLqHIqAQGtVo1qHP5jHWNZZUOY2etCM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=m49SwjBplR+qwOy7LuXJpvwDMmg5h+dY4IPUrQTnhTcIUu1fyvwB0L1+37mjX6xC8gD0PNzBknQgs0l+eLpTEeE8GzjHEi8XDkEbBR2PFk1fACxkC63lN4uswthgEvbl46lUuSym3ki8M7z8t9sGti5TLimbCUHZIpqmMEOmkIY= 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=XVARx4vQ; arc=none smtp.client-ip=209.85.215.171 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="XVARx4vQ" Received: by mail-pg1-f171.google.com with SMTP id 41be03b00d2f7-7d50e865b7aso1810604a12.0; Fri, 13 Sep 2024 03:29:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223345; x=1726828145; 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=zftKO8BKrAFq2Bb4XU29mujYmU+XCvQKFqRw2i9Et9s=; b=XVARx4vQokfey9SiwUXqGCiLyQMuO1CIXlcF0qCTntYwa6yBo0t/bGaU9Oc2Ykr5EK YyTTGeJq/ah5M02hdJBtwB87/NWE0m2ljt3LMFa4I3E09zVyulwA4ieDgDEwgYghen7j 12DHf7yCbwOkp8k14QAJ3WFlckYSfrcCbAZajVcG1ukIWlko+VaSe8hF5VA6IrYmxGtn WfUIJDEb6QOMcbtf9YiqCYKgX3/tr1atfl5+uiWR4zT+Adw3PahtOmbDPpKYOCOx4/oc 7JdljldXbZ2jmoKolmNEEiTSvcDqcAYe5nlOPYy5/Fg3dqv/wWCWo+QkYvq8urRErxiE XHng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223345; x=1726828145; 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=zftKO8BKrAFq2Bb4XU29mujYmU+XCvQKFqRw2i9Et9s=; b=Z3/pEJRHIMjFJV9oo6GuOy8whLscYRgFPSL5FDvPbxY0Rxavk+bHkFyuOMqn6js8ua uO3UvtNgyQhEL+gFwjj7Bexku9zi517B0rv6UQ0/kPmBMLcU9WSt9pWt/muqe+DcdNFr qUwKoS0YElacCQaA7sGxRsqbfuwEgYGw4UsnBWdRGviV4SMZWc5gYxeSYxzxAs4FfZK4 ieH3nHqLCvQ/Kdu6TU9rE+1GoaIJSe64HARBrMrtO57HFxh/oDivsKEY0XQCbFkhswbM 3fFjYuX3ZQvf4LpgTXyYiV5SpypkaOL66kNjj1+u2SEiMTDZNOXfd2KCSxBKOEMl7BAH fHTg== X-Forwarded-Encrypted: i=1; AJvYcCVbjPoYqLqoSlDwm0KLM0OlHnuNl0dWdZCtC3CvHHDg5B3ZOez/eWv8DF6Q6NkVQTzmKSSbnlZRzIZzoJk=@vger.kernel.org X-Gm-Message-State: AOJu0Yxu0mkw3oiSriVUkQSIJylYGZRpVkHOsP3G/aRFvZbASOzcg5wG VNc5K+MaPH88pOFq+lvs6CCZjnwEwWyKCHY67EEyHsCrHwRQC6Fas7OgMSG9 X-Google-Smtp-Source: AGHT+IHSsNNKTgKl10euNRNlKC3jgGdKybtnAPaYIMfbVAYqQXQk5Te2BrcJY6aUCgfaCKniJvIoLQ== X-Received: by 2002:a05:6a20:b598:b0:1cf:4ad8:83bc with SMTP id adf61e73a8af0-1cf7624b3b7mr8638518637.31.1726223345084; Fri, 13 Sep 2024 03:29:05 -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.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:29:04 -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 , Jason Lai , Victor Shih Subject: [PATCH V22 05/22] mmc: core: Add definitions for SD UHS-II cards Date: Fri, 13 Sep 2024 18:28:19 +0800 Message-Id: <20240913102836.6144-6-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 Add UHS-II specific data structures for commands and defines for registers, as described in Part 1 UHS-II Addendum Version 1.01. UHS-II related definitions are listed below: 1. UHS-II card capability: sd_uhs2_caps{} 2. UHS-II configuration: sd_uhs2_config{} 3. UHS-II register I/O address and register field definitions: sd_uhs2.h Signed-off-by: Ulf Hansson Signed-off-by: Jason Lai Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- Updates in V12: - Remove unused max_current_180_vdd2. Updates in V10: - Drop unnecessary definitions. Updates in V7: - Remove unnecessary definitions. Updates in V6: - Remove unnecessary definitions and functions. --- include/linux/mmc/card.h | 31 ++++- include/linux/mmc/host.h | 25 +++- include/linux/mmc/sd_uhs2.h | 240 ++++++++++++++++++++++++++++++++++++ 3 files changed, 294 insertions(+), 2 deletions(-) create mode 100644 include/linux/mmc/sd_uhs2.h diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index e256b1e70c6e..9b90d3467961 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -188,6 +188,12 @@ struct sd_switch_caps { #define SD_MAX_CURRENT_400 (1 << SD_SET_CURRENT_LIMIT_400) #define SD_MAX_CURRENT_600 (1 << SD_SET_CURRENT_LIMIT_600) #define SD_MAX_CURRENT_800 (1 << SD_SET_CURRENT_LIMIT_800) + +#define SD4_SET_POWER_LIMIT_0_72W 0 +#define SD4_SET_POWER_LIMIT_1_44W 1 +#define SD4_SET_POWER_LIMIT_2_16W 2 +#define SD4_SET_POWER_LIMIT_2_88W 3 +#define SD4_SET_POWER_LIMIT_1_80W 4 }; =20 struct sd_ext_reg { @@ -211,7 +217,30 @@ struct sd_ext_reg { =20 struct sd_uhs2_config { u32 node_id; - /* TODO: Extend with more register configs. */ + + u32 n_fcu; + u32 maxblk_len; + u8 n_lanes; + u8 dadr_len; + u8 app_type; + u8 phy_minor_rev; + u8 phy_major_rev; + u8 can_hibernate; + u8 n_lss_sync; + u8 n_lss_dir; + u8 link_minor_rev; + u8 link_major_rev; + u8 dev_type; + u8 n_data_gap; + + u32 n_fcu_set; + u32 maxblk_len_set; + u8 n_lanes_set; + u8 speed_range_set; + u8 n_lss_sync_set; + u8 n_lss_dir_set; + u8 n_data_gap_set; + u8 max_retry_set; }; =20 struct sdio_cccr { diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 841f0ba850aa..0e1112ee160e 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -16,6 +16,7 @@ #include #include #include +#include =20 struct mmc_ios { unsigned int clock; /* clock rate */ @@ -99,7 +100,29 @@ struct mmc_clk_phase_map { }; =20 struct sd_uhs2_caps { - /* TODO: Add UHS-II capabilities for the host. */ + u32 dap; + u32 gap; + u32 group_desc; + u32 maxblk_len; + u32 n_fcu; + u8 n_lanes; + u8 addr64; + u8 card_type; + u8 phy_rev; + u8 speed_range; + u8 n_lss_sync; + u8 n_lss_dir; + u8 link_rev; + u8 host_type; + u8 n_data_gap; + + u32 maxblk_len_set; + u32 n_fcu_set; + u8 n_lanes_set; + u8 n_lss_sync_set; + u8 n_lss_dir_set; + u8 n_data_gap_set; + u8 max_retry_set; }; =20 enum sd_uhs2_operation { diff --git a/include/linux/mmc/sd_uhs2.h b/include/linux/mmc/sd_uhs2.h new file mode 100644 index 000000000000..7abe9bd870c7 --- /dev/null +++ b/include/linux/mmc/sd_uhs2.h @@ -0,0 +1,240 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Header file for UHS-II packets, Host Controller registers and I/O + * accessors. + * + * Copyright (C) 2014 Intel Corp, All Rights Reserved. + */ +#ifndef LINUX_MMC_UHS2_H +#define LINUX_MMC_UHS2_H + +/* LINK Layer definition */ +/* + * UHS2 Header: + * Refer to UHS-II Addendum Version 1.02 Figure 5-2, the format of CCMD He= ader is described below: + * bit [3:0] : DID(Destination ID =3D Node ID of UHS2 card) + * bit [6:4] : TYP(Packet Type) + * 000b: CCMD(Control command packet) + * 001b: DCMD(Data command packet) + * 010b: RES(Response packet) + * 011b: DATA(Data payload packet) + * 111b: MSG(Message packet) + * Others: Reserved + * bit [7] : NP(Native Packet) + * bit [10:8] : TID(Transaction ID) + * bit [11] : Reserved + * bit [15:12]: SID(Source ID 0: Node ID of Host) + * + * Broadcast CCMD issued by Host is represented as DID=3DSID=3D0. + */ +/* + * UHS2 Argument: + * Refer to UHS-II Addendum Version 1.02 Figure 6-5, the format of CCMD Ar= gument is described below: + * bit [3:0] : MSB of IOADR + * bit [5:4] : PLEN(Payload Length) + * 00b: 0 byte + * 01b: 4 bytes + * 10b: 8 bytes + * 11b: 16 bytes + * bit [6] : Reserved + * bit [7] : R/W(Read/Write) + * 0: Control read command + * 1: Control write command + * bit [15:8] : LSB of IOADR + * + * I/O Address specifies the address of register in UHS-II I/O space acces= sed by CCMD. + * The unit of I/O Address is 4 Bytes. It is transmitted in MSB first, LSB= last. + */ +#define UHS2_NATIVE_PACKET_POS 7 +#define UHS2_NATIVE_PACKET (1 << UHS2_NATIVE_PACKET_POS) + +#define UHS2_PACKET_TYPE_POS 4 +#define UHS2_PACKET_TYPE_CCMD (0 << UHS2_PACKET_TYPE_POS) +#define UHS2_PACKET_TYPE_DCMD (1 << UHS2_PACKET_TYPE_POS) +#define UHS2_PACKET_TYPE_RES (2 << UHS2_PACKET_TYPE_POS) +#define UHS2_PACKET_TYPE_DATA (3 << UHS2_PACKET_TYPE_POS) +#define UHS2_PACKET_TYPE_MSG (7 << UHS2_PACKET_TYPE_POS) + +#define UHS2_DEST_ID_MASK 0x0F +#define UHS2_DEST_ID 0x1 + +#define UHS2_SRC_ID_POS 12 +#define UHS2_SRC_ID_MASK 0xF000 + +#define UHS2_TRANS_ID_POS 8 +#define UHS2_TRANS_ID_MASK 0x0700 + +/* UHS2 MSG */ +#define UHS2_MSG_CTG_POS 5 +#define UHS2_MSG_CTG_LMSG 0x00 +#define UHS2_MSG_CTG_INT 0x60 +#define UHS2_MSG_CTG_AMSG 0x80 + +#define UHS2_MSG_CTG_FCREQ 0x00 +#define UHS2_MSG_CTG_FCRDY 0x01 +#define UHS2_MSG_CTG_STAT 0x02 + +#define UHS2_MSG_CODE_POS 8 +#define UHS2_MSG_CODE_FC_UNRECOVER_ERR 0x8 +#define UHS2_MSG_CODE_STAT_UNRECOVER_ERR 0x8 +#define UHS2_MSG_CODE_STAT_RECOVER_ERR 0x1 + +/* TRANS Layer definition */ + +/* Native packets*/ +#define UHS2_NATIVE_CMD_RW_POS 7 +#define UHS2_NATIVE_CMD_WRITE (1 << UHS2_NATIVE_CMD_RW_POS) +#define UHS2_NATIVE_CMD_READ (0 << UHS2_NATIVE_CMD_RW_POS) + +#define UHS2_NATIVE_CMD_PLEN_POS 4 +#define UHS2_NATIVE_CMD_PLEN_4B (1 << UHS2_NATIVE_CMD_PLEN_POS) +#define UHS2_NATIVE_CMD_PLEN_8B (2 << UHS2_NATIVE_CMD_PLEN_POS) +#define UHS2_NATIVE_CMD_PLEN_16B (3 << UHS2_NATIVE_CMD_PLEN_POS) + +#define UHS2_NATIVE_CCMD_GET_MIOADR_MASK 0xF00 +#define UHS2_NATIVE_CCMD_MIOADR_MASK 0x0F + +#define UHS2_NATIVE_CCMD_LIOADR_POS 8 +#define UHS2_NATIVE_CCMD_GET_LIOADR_MASK 0x0FF + +#define UHS2_CCMD_DEV_INIT_COMPLETE_FLAG BIT(11) +#define UHS2_DEV_INIT_PAYLOAD_LEN 1 +#define UHS2_DEV_INIT_RESP_LEN 6 +#define UHS2_DEV_ENUM_PAYLOAD_LEN 1 +#define UHS2_DEV_ENUM_RESP_LEN 8 +#define UHS2_CFG_WRITE_PAYLOAD_LEN 2 +#define UHS2_CFG_WRITE_PHY_SET_RESP_LEN 4 +#define UHS2_CFG_WRITE_GENERIC_SET_RESP_LEN 5 +#define UHS2_GO_DORMANT_PAYLOAD_LEN 1 + +/* + * UHS2 Argument: + * Refer to UHS-II Addendum Version 1.02 Figure 6-8, the format of DCMD Ar= gument is described below: + * bit [3:0] : Reserved + * bit [6:3] : TMODE(Transfer Mode) + * bit 3: DAM(Data Access Mode) + * bit 4: TLUM(TLEN Unit Mode) + * bit 5: LM(Length Mode) + * bit 6: DM(Duplex Mode) + * bit [7] : R/W(Read/Write) + * 0: Control read command + * 1: Control write command + * bit [15:8] : Reserved + * + * I/O Address specifies the address of register in UHS-II I/O space acces= sed by CCMD. + * The unit of I/O Address is 4 Bytes. It is transmitted in MSB first, LSB= last. + */ +#define UHS2_DCMD_DM_POS 6 +#define UHS2_DCMD_2L_HD_MODE (1 << UHS2_DCMD_DM_POS) +#define UHS2_DCMD_LM_POS 5 +#define UHS2_DCMD_LM_TLEN_EXIST (1 << UHS2_DCMD_LM_POS) +#define UHS2_DCMD_TLUM_POS 4 +#define UHS2_DCMD_TLUM_BYTE_MODE (1 << UHS2_DCMD_TLUM_POS) +#define UHS2_NATIVE_DCMD_DAM_POS 3 +#define UHS2_NATIVE_DCMD_DAM_IO (1 << UHS2_NATIVE_DCMD_DAM_POS) + +#define UHS2_RES_NACK_POS 7 +#define UHS2_RES_NACK_MASK (0x1 << UHS2_RES_NACK_POS) + +#define UHS2_RES_ECODE_POS 4 +#define UHS2_RES_ECODE_MASK 0x7 +#define UHS2_RES_ECODE_COND 1 +#define UHS2_RES_ECODE_ARG 2 +#define UHS2_RES_ECODE_GEN 3 + +/* IOADR of device registers */ +#define UHS2_IOADR_GENERIC_CAPS 0x00 +#define UHS2_IOADR_PHY_CAPS 0x02 +#define UHS2_IOADR_LINK_CAPS 0x04 +#define UHS2_IOADR_RSV_CAPS 0x06 +#define UHS2_IOADR_GENERIC_SETTINGS 0x08 +#define UHS2_IOADR_PHY_SETTINGS 0x0A +#define UHS2_IOADR_LINK_SETTINGS 0x0C +#define UHS2_IOADR_PRESET 0x40 + +/* SD application packets */ +#define UHS2_SD_CMD_INDEX_POS 8 + +#define UHS2_SD_CMD_APP_POS 14 +#define UHS2_SD_CMD_APP (1 << UHS2_SD_CMD_APP_POS) + +/* UHS-II Device Registers */ +#define UHS2_DEV_CONFIG_REG 0x000 + +/* General Caps and Settings registers */ +#define UHS2_DEV_CONFIG_GEN_CAPS (UHS2_DEV_CONFIG_REG + 0x000) +#define UHS2_DEV_CONFIG_N_LANES_POS 8 +#define UHS2_DEV_CONFIG_N_LANES_MASK 0x3F +#define UHS2_DEV_CONFIG_2L_HD_FD 0x1 +#define UHS2_DEV_CONFIG_2D1U_FD 0x2 +#define UHS2_DEV_CONFIG_1D2U_FD 0x4 +#define UHS2_DEV_CONFIG_2D2U_FD 0x8 +#define UHS2_DEV_CONFIG_DADR_POS 14 +#define UHS2_DEV_CONFIG_DADR_MASK 0x1 +#define UHS2_DEV_CONFIG_APP_POS 16 +#define UHS2_DEV_CONFIG_APP_MASK 0xFF +#define UHS2_DEV_CONFIG_APP_SD_MEM 0x1 + +#define UHS2_DEV_CONFIG_GEN_SET (UHS2_DEV_CONFIG_REG + 0x008) +#define UHS2_DEV_CONFIG_GEN_SET_N_LANES_POS 8 +#define UHS2_DEV_CONFIG_GEN_SET_2L_FD_HD 0x0 +#define UHS2_DEV_CONFIG_GEN_SET_2D1U_FD 0x2 +#define UHS2_DEV_CONFIG_GEN_SET_1D2U_FD 0x3 +#define UHS2_DEV_CONFIG_GEN_SET_2D2U_FD 0x4 +#define UHS2_DEV_CONFIG_GEN_SET_CFG_COMPLETE BIT(31) + +/* PHY Caps and Settings registers */ +#define UHS2_DEV_CONFIG_PHY_CAPS (UHS2_DEV_CONFIG_REG + 0x002) +#define UHS2_DEV_CONFIG_PHY_MINOR_MASK 0xF +#define UHS2_DEV_CONFIG_PHY_MAJOR_POS 4 +#define UHS2_DEV_CONFIG_PHY_MAJOR_MASK 0x3 +#define UHS2_DEV_CONFIG_CAN_HIBER_POS 15 +#define UHS2_DEV_CONFIG_CAN_HIBER_MASK 0x1 +#define UHS2_DEV_CONFIG_PHY_CAPS1 (UHS2_DEV_CONFIG_REG + 0x003) +#define UHS2_DEV_CONFIG_N_LSS_SYN_MASK 0xF +#define UHS2_DEV_CONFIG_N_LSS_DIR_POS 4 +#define UHS2_DEV_CONFIG_N_LSS_DIR_MASK 0xF + +#define UHS2_DEV_CONFIG_PHY_SET (UHS2_DEV_CONFIG_REG + 0x00A) +#define UHS2_DEV_CONFIG_PHY_SET_SPEED_POS 6 +#define UHS2_DEV_CONFIG_PHY_SET_SPEED_A 0x0 +#define UHS2_DEV_CONFIG_PHY_SET_SPEED_B 0x1 + +/* LINK-TRAN Caps and Settings registers */ +#define UHS2_DEV_CONFIG_LINK_TRAN_CAPS (UHS2_DEV_CONFIG_REG + 0x004) +#define UHS2_DEV_CONFIG_LT_MINOR_MASK 0xF +#define UHS2_DEV_CONFIG_LT_MAJOR_POS 4 +#define UHS2_DEV_CONFIG_LT_MAJOR_MASK 0x3 +#define UHS2_DEV_CONFIG_N_FCU_POS 8 +#define UHS2_DEV_CONFIG_N_FCU_MASK 0xFF +#define UHS2_DEV_CONFIG_DEV_TYPE_POS 16 +#define UHS2_DEV_CONFIG_DEV_TYPE_MASK 0x7 +#define UHS2_DEV_CONFIG_MAX_BLK_LEN_POS 20 +#define UHS2_DEV_CONFIG_MAX_BLK_LEN_MASK 0xFFF +#define UHS2_DEV_CONFIG_LINK_TRAN_CAPS1 (UHS2_DEV_CONFIG_REG + 0x005) +#define UHS2_DEV_CONFIG_N_DATA_GAP_MASK 0xFF + +#define UHS2_DEV_CONFIG_LINK_TRAN_SET (UHS2_DEV_CONFIG_REG + 0x00C) +#define UHS2_DEV_CONFIG_LT_SET_MAX_BLK_LEN 0x200 +#define UHS2_DEV_CONFIG_LT_SET_MAX_RETRY_POS 16 + +/* Preset register */ +#define UHS2_DEV_CONFIG_PRESET (UHS2_DEV_CONFIG_REG + 0x040) + +#define UHS2_DEV_INT_REG 0x100 + +#define UHS2_DEV_STATUS_REG 0x180 + +#define UHS2_DEV_CMD_REG 0x200 +#define UHS2_DEV_CMD_FULL_RESET (UHS2_DEV_CMD_REG + 0x000) +#define UHS2_DEV_CMD_GO_DORMANT_STATE (UHS2_DEV_CMD_REG + 0x001) +#define UHS2_DEV_CMD_DORMANT_HIBER BIT(7) +#define UHS2_DEV_CMD_DEVICE_INIT (UHS2_DEV_CMD_REG + 0x002) +#define UHS2_DEV_INIT_COMPLETE_FLAG BIT(11) +#define UHS2_DEV_CMD_ENUMERATE (UHS2_DEV_CMD_REG + 0x003) +#define UHS2_DEV_CMD_TRANS_ABORT (UHS2_DEV_CMD_REG + 0x004) + +#define UHS2_RCLK_MAX 52000000 +#define UHS2_RCLK_MIN 26000000 + +#endif /* LINUX_MMC_UHS2_H */ --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pf1-f173.google.com (mail-pf1-f173.google.com [209.85.210.173]) (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 8DA931D933B; Fri, 13 Sep 2024 10:29:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223351; cv=none; b=M9J17JMO3rWyk9pyAH8lLWZzRSCFbgtU4tBa49cnEMP9mgxzWPkkB1ql+yVGBCUcw1Ww8uB0gVFpTefapFCaLkvoImuc8cgqG1bf5A++hWkUDbIXUbSlTU2Y9RaoyKWIe5KjlbmF8UebZWrqFgf3G7wsWNk2mgv/3Nz5juC9cq8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223351; c=relaxed/simple; bh=ItSyxu3z+cpuKQYpHT1VflweB01MjpYZ5FR4CmHMj+U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Z57I9ChAueHidK2nczyfXdr1pc+QoySq4YzCK1KUHZ6pRKG4z5hmn/FtD47HFyycfqfUONbjsWbKv6YTJMr/59eUmQxhDnV/ih9EyMVql2yhB/LckBsRtOLUU1JHQIBJtdcVvKZNGkz5Pdtr0H5g9j6sPgEXfkSKwKa1Prho7JI= 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=ZKLUGoX7; arc=none smtp.client-ip=209.85.210.173 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="ZKLUGoX7" Received: by mail-pf1-f173.google.com with SMTP id d2e1a72fcca58-718e285544fso620247b3a.1; Fri, 13 Sep 2024 03:29:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223349; x=1726828149; 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=sxDQEMkG0vSVZkGLeTe49B0S8pLWIGbl/FPUz9dZDz0=; b=ZKLUGoX7FL/TtdnnnHFnr1SkDA96vW7TpCA/J56w5Hc4NOrddDwr16tLzk8R6fZOEm AuUP7yYmYFow6fHVGkudrpxO4Gri7itegc4iHc/02dEHo9LRPkPtVQvFvjmBY/5S6onX h9Gq6mKiLy5mZQYAEOssox4o70lJaY6u4BwzxiP5isSl95+PbNomccgbhbXwtuNs86MO /RZ9JohCmRmM4K0m6axaGiMFLpp2/woLXSgUm38xkKsXlIq31kDHrOqRH3Ql0FXBD/NT 9ZX19/o4md6ykv1dNpBtE8gGS8lvOPJe75DXoHjYIX5h2f459ovfXxM//ZhVXcZyJcz/ tnpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223349; x=1726828149; 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=sxDQEMkG0vSVZkGLeTe49B0S8pLWIGbl/FPUz9dZDz0=; b=i+N2/fE4vYeKVAfVA9rBN+HlCkinFc8IPMiZtavcCuE0tvuZHDs+yuHtdPDu6ibVxM AY3SQHCbXLrxYFwR1kl9mxZNlMmeKlprWUUQJp4TJK2npQhRYBiezzuZjoPpUqLdB9/h Cx4YHo5Uy9/whRVFGvoDj9qLMeOROd5jCjxvvaEhVq+acBULBlP9hQd1OUsdA2sjtne7 MP8ojRYzQ+DIPgC0KfF3nHveFXT+aTMzki7Z1lKhoKP1hvu0bG5kkTaoIUmL4bBvOE5/ Sq4ozgzJbKfrhroLOLPrdVQB9s4gI29Pt0P7BcETdawdE5sRWgxpFUaVUzmatICZGdAL aJ/g== X-Forwarded-Encrypted: i=1; AJvYcCVhWSkKOd7yMOI2VJ8ms3276xnktDXCpF6mfmR45jMvvrSD2yGh+RT+CBoDuno0C/h0aqt2lTgF1ir8OT8=@vger.kernel.org X-Gm-Message-State: AOJu0YwDDjZOldrh02FS73UEEclZ02C4mD3g2XH6hBQfJKi02omswAfv W0JAc9W256MNuG59pxrez3BuyELzAdxcr14Buwl8KIfCyyjOt5CJ X-Google-Smtp-Source: AGHT+IFJXxSoQGqEc+wCI3vDO0B2QBm8O7yvnla8p5nopbp/FYMfCi6VpHfoFD5NlixywPlt5XFwdQ== X-Received: by 2002:a05:6a21:6f83:b0:1cf:5d45:3b29 with SMTP id adf61e73a8af0-1d112e8bfb9mr3445999637.35.1726223348935; Fri, 13 Sep 2024 03:29:08 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:29:08 -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 , Victor Shih Subject: [PATCH V22 06/22] mmc: core: Add New function to re-factoring the code Date: Fri, 13 Sep 2024 18:28:20 +0800 Message-Id: <20240913102836.6144-7-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 Add __mmc_go_idle function to re-factoring mmc_go_idle function. Signed-off-by: Ulf Hansson Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- drivers/mmc/core/mmc_ops.c | 24 ++++++++++++++++-------- drivers/mmc/core/mmc_ops.h | 1 + 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 3b3adbddf664..5c8e62e8f331 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -144,10 +144,24 @@ int mmc_set_dsr(struct mmc_host *host) return mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); } =20 +int __mmc_go_idle(struct mmc_host *host) +{ + struct mmc_command cmd =3D {}; + int err; + + cmd.opcode =3D MMC_GO_IDLE_STATE; + cmd.arg =3D 0; + cmd.flags =3D MMC_RSP_SPI_R1 | MMC_RSP_NONE | MMC_CMD_BC; + + err =3D mmc_wait_for_cmd(host, &cmd, 0); + mmc_delay(1); + + return err; +} + int mmc_go_idle(struct mmc_host *host) { int err; - struct mmc_command cmd =3D {}; =20 /* * Non-SPI hosts need to prevent chipselect going active during @@ -163,13 +177,7 @@ int mmc_go_idle(struct mmc_host *host) mmc_delay(1); } =20 - cmd.opcode =3D MMC_GO_IDLE_STATE; - cmd.arg =3D 0; - cmd.flags =3D MMC_RSP_SPI_R1 | MMC_RSP_NONE | MMC_CMD_BC; - - err =3D mmc_wait_for_cmd(host, &cmd, 0); - - mmc_delay(1); + err =3D __mmc_go_idle(host); =20 if (!mmc_host_is_spi(host)) { mmc_set_chip_select(host, MMC_CS_DONTCARE); diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h index 06017110e1b0..0df3ebd900d1 100644 --- a/drivers/mmc/core/mmc_ops.h +++ b/drivers/mmc/core/mmc_ops.h @@ -25,6 +25,7 @@ struct mmc_command; int mmc_select_card(struct mmc_card *card); int mmc_deselect_cards(struct mmc_host *host); int mmc_set_dsr(struct mmc_host *host); +int __mmc_go_idle(struct mmc_host *host); int mmc_go_idle(struct mmc_host *host); int mmc_send_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr); int mmc_set_relative_addr(struct mmc_card *card); --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 AF0A31D86D6; Fri, 13 Sep 2024 10:29:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223357; cv=none; b=IODFkMIUyMi//tb5qJDMR/SdU/4bGbyvGRs4mnjlFUmdDq0O8PfR75TB48v6hz1EzoCghBEXmoJBRxsjcKCcNyr7cxQa8Uk5EJaTlzi4vFiT3dR1yAqiJcVZfedosnLv+bCYe/DCVDoh21BVpZdNEAISFAgugNO7KVjCZlz3kwY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223357; c=relaxed/simple; bh=zRef6mPBfqeedyCONpzl8GnqRecxpBK1jPu9OZCN/s8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ip1Spu0SiQfbJKKsuWJlzlvrHI0w4sCLA10cXXnvsyFKduSNKjtxex5ITtFpTq6LFSSF0E8T1Xnju6NizAm0+OYDEsjUeGx4XIJ2xw/j/eWOAiSN7ei09Ddl+iIXxjOVfU2bRZxoaLqiZTO56BHIwRzC3oUD2hJQi0fTQQigG2U= 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=KqlVfsK/; arc=none smtp.client-ip=209.85.214.181 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="KqlVfsK/" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2053525bd90so6737205ad.0; Fri, 13 Sep 2024 03:29:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223354; x=1726828154; 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=/sk+SRT20aUCkisPhWNhj+XRCKkchDvOQveIRHdHuMo=; b=KqlVfsK/wumGorVcOpr2iR0aB09lLGfbFC3ypMXFnH8ImUHvLrXht2zSTmXnIOO9Xo /C/yFK8UJkAzCqn/1A6DYSpDe2M19rLXGTsg8o7PF2UYIiVKyb17nvIr5FQ7HkdBRWPj 26etp1fMwXJYjiDe4c2jpE9Hs5X2XRTKDvImJvlm5RLAAgmnCqULKCNa3gfUJdOVXLNT wPyYLeztkH3xuSaYvitnj8Tet+3nKh/FvPGiFPHOZl6X9/AgEVjlG9C111VcZ9wx2KeW E3zJzowXgUzIJBhoSX01hpHLfS/+jmhx/4GuEossutAbLrkc0PaPgsf3SW8t2iMGxcT+ 2D7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223354; x=1726828154; 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=/sk+SRT20aUCkisPhWNhj+XRCKkchDvOQveIRHdHuMo=; b=at23xjOj+AbCkVfXP/suKkTJWrO9MW4A6wcmkzUHUZjq7Jx1tHuXHhAw4YtP2Mc3vg A3K466LyalkvkQeI/XePgpdsUaT4MfaOtNUo9M8R8MjJ69v4xAVn0GxqWNWc7e4nDDMm hlvugbqLZkZTu9XaLAfg+KMm9zJi4SMeY8NWqXQPdqPqW+TmEmXZ9ouIcZAG+VrzgibF ZtcGWPfni/gJsmXyvZ1Mv5dnVmM9VMP/OATJkn4Tc22vb6tgTjCowvIJEQsRZBJ2kyZG 1zkM6PXRXKIzorm2J9/vjssIxnT0zDrEL450EfLtJNtTn11Mi7zrEAoullKWMZziBO0s 1A/g== X-Forwarded-Encrypted: i=1; AJvYcCWtmxZ1hzRT2p3f+hT66BwVN5laC9IHMVXjPBV2n6fE3MTOEvNjadpnGXHtgUEdc2tHE/AVLC3oCrzmXmI=@vger.kernel.org X-Gm-Message-State: AOJu0Yzij6v2++TVPWgBX7rDA6sC9pBtYQe1EE4b60Gk4t9sBMpCOE77 M00s69Uemyg9Z1VDcaXjJkppyy6q173jJCMUkKl+2yVVRJHUOmpc X-Google-Smtp-Source: AGHT+IFRnXauZOoG1C3OuZ1jXMk/AVEVvB/AHTHyNkJNQdJVwvR9f/4kwSrxGND4n9prnk8Iom6BWw== X-Received: by 2002:a17:902:f604:b0:206:64b4:3088 with SMTP id d9443c01a7336-20782434766mr33983325ad.29.1726223353519; Fri, 13 Sep 2024 03:29:13 -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.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:29:13 -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 , Jason Lai , Victor Shih Subject: [PATCH V22 07/22] mmc: core: Support UHS-II card control and access Date: Fri, 13 Sep 2024 18:28:21 +0800 Message-Id: <20240913102836.6144-8-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 Embed UHS-II access/control functionality into the MMC request processing flow. Signed-off-by: Ulf Hansson Signed-off-by: Jason Lai Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- Updates in V16: - Separate the Error Recovery mechanism into a separate patch#8. Updates in V15: - Move struct uhs2_command uhs2_cmd to struct mmc_request and modify whatever other changers to make it work. - Refer the SD Host Controller Standard Specification Section 3.10 to add Error Recovery mechanism to recover the command error. Updates in V13: - Separate __mmc_go_idle() into one patch for re-factorring the code. - Move mmc_decode_scr declaration to sd.h. - Ues uhs2_sd_tran to stead MMC_UHS2_SD_TRAN.=20 - Drop unnecessary comment. Updates in V12: - Use mmc_op_multi() to check DCMD which supports multi read/write in mmc_uhs2_prepare_cmd(). Updates in V10: - Move some definitions of PatchV9[02/23] to PatchV10[06/23]. - Move some definitions of PatchV9[05/23] to PatchV10[06/23]. - Drop do_multi in the mmc_blk_rw_rq_prep(). - Use tmode_half_duplex to instead of uhs2_tmode0_flag. - Move entire control of the tmode into mmc_uhs2_prepare_cmd(). Updates in V8: - Add MMC_UHS2_SUPPORT to be cleared in sd_uhs2_detect(). - Modify return value in sd_uhs2_attach(). Updates in V7: - Add mmc_uhs2_card_prepare_cmd helper function in sd_ops.h. - Drop uhs2_state in favor of ios->timing. - Remove unnecessary functions. --- drivers/mmc/core/core.c | 6 +- drivers/mmc/core/sd.c | 10 +- drivers/mmc/core/sd.h | 5 + drivers/mmc/core/sd_ops.c | 9 + drivers/mmc/core/sd_ops.h | 13 + drivers/mmc/core/sd_uhs2.c | 1100 ++++++++++++++++++++++++++++++++++-- include/linux/mmc/core.h | 17 + include/linux/mmc/host.h | 15 + 8 files changed, 1136 insertions(+), 39 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 8b8aff131f8b..1841a2190571 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -351,6 +351,8 @@ int mmc_start_request(struct mmc_host *host, struct mmc= _request *mrq) if (err) return err; =20 + mmc_uhs2_card_prepare_cmd(host, mrq); + led_trigger_event(host->led, LED_FULL); __mmc_start_request(host, mrq); =20 @@ -450,6 +452,8 @@ int mmc_cqe_start_req(struct mmc_host *host, struct mmc= _request *mrq) if (err) goto out_err; =20 + mmc_uhs2_card_prepare_cmd(host, mrq); + err =3D host->cqe_ops->cqe_request(host, mrq); if (err) goto out_err; @@ -1132,7 +1136,7 @@ u32 mmc_select_voltage(struct mmc_host *host, u32 ocr) return 0; } =20 - if (host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) { + if (!mmc_card_uhs2(host) && host->caps2 & MMC_CAP2_FULL_PWR_CYCLE) { bit =3D ffs(ocr) - 1; ocr &=3D 3 << bit; mmc_power_cycle(host, ocr); diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 12fe282bea77..d5576a2f4435 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -194,7 +194,7 @@ static int mmc_decode_csd(struct mmc_card *card) /* * Given a 64-bit response, decode to our card SCR structure. */ -static int mmc_decode_scr(struct mmc_card *card) +int mmc_decode_scr(struct mmc_card *card) { struct sd_scr *scr =3D &card->scr; unsigned int scr_struct; @@ -894,7 +894,7 @@ int mmc_sd_get_csd(struct mmc_card *card) return 0; } =20 -static int mmc_sd_get_ro(struct mmc_host *host) +int mmc_sd_get_ro(struct mmc_host *host) { int ro; =20 @@ -1623,7 +1623,7 @@ static void mmc_sd_detect(struct mmc_host *host) } } =20 -static int sd_can_poweroff_notify(struct mmc_card *card) +int sd_can_poweroff_notify(struct mmc_card *card) { return card->ext_power.feature_support & SD_EXT_POWER_OFF_NOTIFY; } @@ -1651,7 +1651,7 @@ static int sd_busy_poweroff_notify_cb(void *cb_data, = bool *busy) return 0; } =20 -static int sd_poweroff_notify(struct mmc_card *card) +int sd_poweroff_notify(struct mmc_card *card) { struct sd_busy_data cb_data; u8 *reg_buf; @@ -1699,7 +1699,7 @@ static int _mmc_sd_suspend(struct mmc_host *host) if (mmc_card_suspended(card)) goto out; =20 - if (sd_can_poweroff_notify(card)) + if (mmc_sd_can_poweroff_notify(card)) err =3D sd_poweroff_notify(card); else if (!mmc_host_is_spi(host)) err =3D mmc_deselect_cards(host); diff --git a/drivers/mmc/core/sd.h b/drivers/mmc/core/sd.h index fe6dd46927a4..49afaef269cd 100644 --- a/drivers/mmc/core/sd.h +++ b/drivers/mmc/core/sd.h @@ -11,10 +11,15 @@ struct mmc_card; =20 int mmc_sd_get_cid(struct mmc_host *host, u32 ocr, u32 *cid, u32 *rocr); int mmc_sd_get_csd(struct mmc_card *card); +int mmc_decode_scr(struct mmc_card *card); +int mmc_sd_get_ro(struct mmc_host *host); void mmc_decode_cid(struct mmc_card *card); int mmc_sd_setup_card(struct mmc_host *host, struct mmc_card *card, bool reinit); unsigned mmc_sd_get_max_clock(struct mmc_card *card); int mmc_sd_switch_hs(struct mmc_card *card); =20 +int sd_can_poweroff_notify(struct mmc_card *card); +int sd_poweroff_notify(struct mmc_card *card); + #endif diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c index f93c392040ae..5cd1216edf0d 100644 --- a/drivers/mmc/core/sd_ops.c +++ b/drivers/mmc/core/sd_ops.c @@ -41,6 +41,15 @@ int mmc_app_cmd(struct mmc_host *host, struct mmc_card *= card) if (WARN_ON(card && card->host !=3D host)) return -EINVAL; =20 + /* + * UHS2 packet has APP bit so only set APP_CMD flag here. + * Will set the APP bit when assembling UHS2 packet. + */ + if (host->uhs2_sd_tran) { + host->uhs2_app_cmd =3D true; + return 0; + } + cmd.opcode =3D MMC_APP_CMD; =20 if (card) { diff --git a/drivers/mmc/core/sd_ops.h b/drivers/mmc/core/sd_ops.h index 7667fc223b74..e3af68a52de8 100644 --- a/drivers/mmc/core/sd_ops.h +++ b/drivers/mmc/core/sd_ops.h @@ -11,6 +11,7 @@ #include =20 struct mmc_card; +struct mmc_command; struct mmc_host; =20 int mmc_app_set_bus_width(struct mmc_card *card, int width); @@ -21,6 +22,18 @@ int mmc_send_relative_addr(struct mmc_host *host, unsign= ed int *rca); int mmc_app_send_scr(struct mmc_card *card); int mmc_app_sd_status(struct mmc_card *card, void *ssr); int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card); +void mmc_uhs2_prepare_cmd(struct mmc_host *host, struct mmc_request *mrq); + +static inline void mmc_uhs2_card_prepare_cmd(struct mmc_host *host, struct= mmc_request *mrq) +{ + if (host->uhs2_sd_tran) + mmc_uhs2_prepare_cmd(host, mrq); +} + +static inline int mmc_sd_can_poweroff_notify(struct mmc_card *card) +{ + return card->ext_power.feature_support & SD_EXT_POWER_OFF_NOTIFY; +} =20 #endif =20 diff --git a/drivers/mmc/core/sd_uhs2.c b/drivers/mmc/core/sd_uhs2.c index beb2541338ff..85939a2582dc 100644 --- a/drivers/mmc/core/sd_uhs2.c +++ b/drivers/mmc/core/sd_uhs2.c @@ -1,23 +1,51 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2021 Linaro Ltd - * * Author: Ulf Hansson * + * Copyright (C) 2014 Intel Corp, All Rights Reserved. + * Author: Yi Sun + * + * Copyright (C) 2020 Genesys Logic, Inc. + * Authors: Ben Chuang + * + * Copyright (C) 2020 Linaro Limited + * Author: AKASHI Takahiro + * + * Copyright (C) 2022 Genesys Logic, Inc. + * Authors: Jason Lai + * + * Copyright (C) 2023 Genesys Logic, Inc. + * Authors: Victor Shih + * * Support for SD UHS-II cards */ #include +#include =20 #include #include +#include +#include +#include =20 +#include "card.h" #include "core.h" #include "bus.h" #include "sd.h" +#include "sd_ops.h" #include "mmc_ops.h" =20 +#define UHS2_WAIT_CFG_COMPLETE_PERIOD_US (1 * 1000) +#define UHS2_WAIT_CFG_COMPLETE_TIMEOUT_MS 100 + static const unsigned int sd_uhs2_freqs[] =3D { 52000000, 26000000 }; =20 +struct sd_uhs2_wait_active_state_data { + struct mmc_host *host; + struct mmc_command *cmd; +}; + static int sd_uhs2_power_up(struct mmc_host *host) { int err; @@ -42,12 +70,46 @@ static int sd_uhs2_power_off(struct mmc_host *host) =20 host->ios.vdd =3D 0; host->ios.clock =3D 0; - host->ios.timing =3D MMC_TIMING_LEGACY; + /* Must set UHS2 timing to identify UHS2 mode */ + host->ios.timing =3D MMC_TIMING_UHS2_SPEED_A; host->ios.power_mode =3D MMC_POWER_OFF; + host->uhs2_sd_tran =3D false; =20 return host->ops->uhs2_control(host, UHS2_SET_IOS); } =20 +/* + * sd_uhs2_cmd_assemble() - build up UHS-II command packet which is embedd= ed in + * mmc_command structure + * @cmd: MMC command to executed + * @uhs2_cmd: UHS2 command corresponded to MMC command + * @header: Header field of UHS-II command cxpacket + * @arg: Argument field of UHS-II command packet + * @payload: Payload field of UHS-II command packet + * @plen: Payload length + * @resp: Response buffer is allocated by caller and it is used to keep + * the response of CM-TRAN command. For SD-TRAN command, uhs2= _resp + * should be null and SD-TRAN command response should be stor= ed in + * resp of mmc_command. + * @resp_len: Response buffer length + * + * The uhs2_command structure contains message packets which are transmite= d/ + * received on UHS-II bus. This function fills in the contents of uhs2_com= mand + * structure and embededs UHS2 command into mmc_command structure, which i= s used + * in legacy SD operation functions. + * + */ +static void sd_uhs2_cmd_assemble(struct mmc_command *cmd, + struct uhs2_command *uhs2_cmd, + u8 plen, u8 resp_len) +{ + uhs2_cmd->payload_len =3D plen * sizeof(u32); + uhs2_cmd->packet_len =3D uhs2_cmd->payload_len + 4; + + cmd->uhs2_cmd =3D uhs2_cmd; + cmd->uhs2_cmd->uhs2_resp_len =3D resp_len; +} + /* * 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 @@ -55,7 +117,15 @@ static int sd_uhs2_power_off(struct mmc_host *host) */ static int sd_uhs2_phy_init(struct mmc_host *host) { - return 0; + int err; + + err =3D host->ops->uhs2_control(host, UHS2_PHY_INIT); + if (err) { + pr_err("%s: failed to initial phy for UHS-II!\n", + mmc_hostname(host)); + } + + return err; } =20 /* @@ -64,6 +134,83 @@ static int sd_uhs2_phy_init(struct mmc_host *host) */ static int sd_uhs2_dev_init(struct mmc_host *host) { + struct mmc_command cmd =3D {0}; + struct uhs2_command uhs2_cmd =3D {}; + u32 cnt; + u32 dap, gap, resp_gap; + u8 gd =3D 0; + int err; + + dap =3D host->uhs2_caps.dap; + gap =3D host->uhs2_caps.gap; + + /* + * Refer to UHS-II Addendum Version 1.02 Figure 6-21 to see DEVICE_INIT C= CMD format. + * Head: + * - Control Write(R/W=3D1) with 4-Byte payload(PLEN=3D01b). + * - IOADR =3D CMD_BASE + 002h + * Payload: + * - bit [3:0] : GAP(Group Allocated Power) + * - bit [7:4] : GD(Group Descriptor) + * - bit [11] : Complete Flag + * - bit [15:12]: DAP(Device Allocated Power) + */ + uhs2_cmd.header =3D UHS2_NATIVE_PACKET | UHS2_PACKET_TYPE_CCMD; + uhs2_cmd.arg =3D ((UHS2_DEV_CMD_DEVICE_INIT & 0xFF) << 8) | + UHS2_NATIVE_CMD_WRITE | + UHS2_NATIVE_CMD_PLEN_4B | + (UHS2_DEV_CMD_DEVICE_INIT >> 8); + + /* + * Refer to UHS-II Addendum Version 1.02 section 6.3.1. + * Max. time from DEVICE_INIT CCMD EOP reception on Device + * Rx to its SOP transmission on Device Tx(Tfwd_init_cmd) is + * 1 second. + */ + cmd.busy_timeout =3D 1000; + + /* + * Refer to UHS-II Addendum Version 1.02 section 6.2.6.3. + * Let's retry the DEVICE_INIT command no more than 30 times. + */ + for (cnt =3D 0; cnt < 30; cnt++) { + uhs2_cmd.payload[0] =3D ((dap & 0xF) << 12) | + UHS2_DEV_INIT_COMPLETE_FLAG | + ((gd & 0xF) << 4) | + (gap & 0xF); + + sd_uhs2_cmd_assemble(&cmd, &uhs2_cmd, UHS2_DEV_INIT_PAYLOAD_LEN, + UHS2_DEV_INIT_RESP_LEN); + + err =3D mmc_wait_for_cmd(host, &cmd, 0); + + if (err) { + pr_err("%s: %s: UHS2 CMD send fail, err=3D 0x%x!\n", + mmc_hostname(host), __func__, err); + continue; + } + + if (uhs2_cmd.uhs2_resp[3] !=3D (UHS2_DEV_CMD_DEVICE_INIT & 0xFF)) { + pr_err("%s: DEVICE_INIT response is wrong!\n", + mmc_hostname(host)); + return -EIO; + } + + if (uhs2_cmd.uhs2_resp[5] & 0x8) { + host->uhs2_caps.group_desc =3D gd; + return 0; + } + resp_gap =3D uhs2_cmd.uhs2_resp[4] & 0x0F; + if (gap =3D=3D resp_gap) + gd++; + } + + if (err) { + pr_err("%s: %s: UHS2 CMD send fail, err=3D 0x%x!\n", + mmc_hostname(host), __func__, err); + return err; + } + return 0; } =20 @@ -74,6 +221,48 @@ static int sd_uhs2_dev_init(struct mmc_host *host) */ static int sd_uhs2_enum(struct mmc_host *host, u32 *node_id) { + struct mmc_command cmd =3D {0}; + struct uhs2_command uhs2_cmd =3D {}; + u8 id_f =3D 0xF, id_l =3D 0x0; + int err; + + /* + * Refer to UHS-II Addendum Version 1.02 Figure 6-28 to see ENUMERATE CCM= D format. + * Header: + * - Control Write(R/W=3D1) with 4-Byte payload(PLEN=3D01b). + * - IOADR =3D CMD_BASE + 003h + * Payload: + * - bit [3:0]: ID_L(Last Node ID) + * - bit [7:4]: ID_F(First Node ID) + */ + uhs2_cmd.header =3D UHS2_NATIVE_PACKET | UHS2_PACKET_TYPE_CCMD; + uhs2_cmd.arg =3D ((UHS2_DEV_CMD_ENUMERATE & 0xFF) << 8) | + UHS2_NATIVE_CMD_WRITE | + UHS2_NATIVE_CMD_PLEN_4B | + (UHS2_DEV_CMD_ENUMERATE >> 8); + + uhs2_cmd.payload[0] =3D (id_f << 4) | id_l; + uhs2_cmd.payload[0] =3D cpu_to_be32(uhs2_cmd.payload[0]); + + sd_uhs2_cmd_assemble(&cmd, &uhs2_cmd, UHS2_DEV_ENUM_PAYLOAD_LEN, UHS2_DEV= _ENUM_RESP_LEN); + + err =3D mmc_wait_for_cmd(host, &cmd, 0); + if (err) { + pr_err("%s: %s: UHS2 CMD send fail, err=3D 0x%x!\n", + mmc_hostname(host), __func__, err); + return err; + } + + if (uhs2_cmd.uhs2_resp[3] !=3D (UHS2_DEV_CMD_ENUMERATE & 0xFF)) { + pr_err("%s: ENUMERATE response is wrong!\n", + mmc_hostname(host)); + return -EIO; + } + + id_f =3D (uhs2_cmd.uhs2_resp[4] >> 4) & 0xF; + id_l =3D uhs2_cmd.uhs2_resp[4] & 0xF; + *node_id =3D id_f; + return 0; } =20 @@ -84,6 +273,180 @@ static int sd_uhs2_enum(struct mmc_host *host, u32 *no= de_id) */ static int sd_uhs2_config_read(struct mmc_host *host, struct mmc_card *car= d) { + struct mmc_command cmd =3D {0}; + struct uhs2_command uhs2_cmd =3D {}; + u32 cap; + int err; + + /* + * Use Control Read CCMD to read Generic Capability from Configuration Re= gister. + * - Control Write(R/W=3D1) with 4-Byte payload(PLEN=3D01b). + * - IOADR =3D Generic Capability Register(CFG_BASE + 000h) + */ + uhs2_cmd.header =3D UHS2_NATIVE_PACKET | UHS2_PACKET_TYPE_CCMD | card->uh= s2_config.node_id; + uhs2_cmd.arg =3D ((UHS2_DEV_CONFIG_GEN_CAPS & 0xFF) << 8) | + UHS2_NATIVE_CMD_READ | + UHS2_NATIVE_CMD_PLEN_4B | + (UHS2_DEV_CONFIG_GEN_CAPS >> 8); + + /* + * There is no payload because per spec, there should be + * no payload field for read CCMD. + * Plen is set in arg. Per spec, plen for read CCMD + * represents the len of read data which is assigned in payload + * of following RES (p136). + */ + sd_uhs2_cmd_assemble(&cmd, &uhs2_cmd, 0, 0); + + err =3D mmc_wait_for_cmd(host, &cmd, 0); + if (err) { + pr_err("%s: %s: UHS2 CMD send fail, err=3D 0x%x!\n", + mmc_hostname(host), __func__, err); + return err; + } + + /* + * Generic Capability Register: + * bit [7:0] : Reserved + * bit [13:8] : Device-Specific Number of Lanes and Functionality + * bit 8: 2L-HD + * bit 9: 2D-1U FD + * bit 10: 1D-2U FD + * bit 11: 2D-2U FD + * Others: Reserved + * bit [14] : DADR Length + * 0: 4 bytes + * 1: Reserved + * bit [23:16]: Application Type + * bit 16: 0=3DNon-SD memory, 1=3DSD memory + * bit 17: 0=3DNon-SDIO, 1=3DSDIO + * bit 18: 0=3DCard, 1=3DEmbedded + * bit [63:24]: Reserved + */ + cap =3D cmd.resp[0]; + card->uhs2_config.n_lanes =3D + (cap >> UHS2_DEV_CONFIG_N_LANES_POS) & + UHS2_DEV_CONFIG_N_LANES_MASK; + card->uhs2_config.dadr_len =3D + (cap >> UHS2_DEV_CONFIG_DADR_POS) & + UHS2_DEV_CONFIG_DADR_MASK; + card->uhs2_config.app_type =3D + (cap >> UHS2_DEV_CONFIG_APP_POS) & + UHS2_DEV_CONFIG_APP_MASK; + + /* + * Use Control Read CCMD to read PHY Capability from Configuration Regist= er. + * - Control Write(R/W=3D1) with 8-Byte payload(PLEN=3D10b). + * - IOADR =3D PHY Capability Register(CFG_BASE + 002h) + */ + uhs2_cmd.arg =3D ((UHS2_DEV_CONFIG_PHY_CAPS & 0xFF) << 8) | + UHS2_NATIVE_CMD_READ | + UHS2_NATIVE_CMD_PLEN_8B | + (UHS2_DEV_CONFIG_PHY_CAPS >> 8); + + sd_uhs2_cmd_assemble(&cmd, &uhs2_cmd, 0, 0); + + err =3D mmc_wait_for_cmd(host, &cmd, 0); + if (err) { + pr_err("%s: %s: UHS2 CMD send fail, err=3D 0x%x!\n", + mmc_hostname(host), __func__, err); + return err; + } + + /* + * PHY Capability Register: + * bit [3:0] : PHY Minor Revision + * bit [5:4] : PHY Major Revision + * bit [15] : Support Hibernate Mode + * 0: Not support Hibernate Mode + * 1: Support Hibernate Mode + * bit [31:16]: Reserved + * bit [35:32]: Device-Specific N_LSS_SYN + * bit [39:36]: Device-Specific N_LSS_DIR + * bit [63:40]: Reserved + */ + cap =3D cmd.resp[0]; + card->uhs2_config.phy_minor_rev =3D + cap & UHS2_DEV_CONFIG_PHY_MINOR_MASK; + card->uhs2_config.phy_major_rev =3D + (cap >> UHS2_DEV_CONFIG_PHY_MAJOR_POS) & + UHS2_DEV_CONFIG_PHY_MAJOR_MASK; + card->uhs2_config.can_hibernate =3D + (cap >> UHS2_DEV_CONFIG_CAN_HIBER_POS) & + UHS2_DEV_CONFIG_CAN_HIBER_MASK; + + cap =3D cmd.resp[1]; + card->uhs2_config.n_lss_sync =3D + cap & UHS2_DEV_CONFIG_N_LSS_SYN_MASK; + card->uhs2_config.n_lss_dir =3D + (cap >> UHS2_DEV_CONFIG_N_LSS_DIR_POS) & + UHS2_DEV_CONFIG_N_LSS_DIR_MASK; + if (card->uhs2_config.n_lss_sync =3D=3D 0) + card->uhs2_config.n_lss_sync =3D 16 << 2; + else + card->uhs2_config.n_lss_sync <<=3D 2; + + if (card->uhs2_config.n_lss_dir =3D=3D 0) + card->uhs2_config.n_lss_dir =3D 16 << 3; + else + card->uhs2_config.n_lss_dir <<=3D 3; + + /* + * Use Control Read CCMD to read LINK/TRAN Capability from Configuration = Register. + * - Control Write(R/W=3D1) with 8-Byte payload(PLEN=3D10b). + * - IOADR =3D LINK/TRAN Capability Register(CFG_BASE + 004h) + */ + uhs2_cmd.arg =3D ((UHS2_DEV_CONFIG_LINK_TRAN_CAPS & 0xFF) << 8) | + UHS2_NATIVE_CMD_READ | + UHS2_NATIVE_CMD_PLEN_8B | + (UHS2_DEV_CONFIG_LINK_TRAN_CAPS >> 8); + + sd_uhs2_cmd_assemble(&cmd, &uhs2_cmd, 0, 0); + + err =3D mmc_wait_for_cmd(host, &cmd, 0); + if (err) { + pr_err("%s: %s: UHS2 CMD send fail, err=3D 0x%x!\n", + mmc_hostname(host), __func__, err); + return err; + } + + /* + * LINK/TRAN Capability Register: + * bit [3:0] : LINK_TRAN Minor Revision + * bit [5:4] : LINK/TRAN Major Revision + * bit [7:6] : Reserved + * bit [15:8] : Device-Specific N_FCU + * bit [18:16]: Device Type + * 001b=3DHost + * 010b=3DDevice + * 011b=3DReserved for CMD issuable Device + * bit [19] : Reserved + * bit [31:20]: Device-Specific MAX_BLKLEN + * bit [39:32]: Device-Specific N_DATA_GAP + * bit [63:40]: Reserved + */ + cap =3D cmd.resp[0]; + card->uhs2_config.link_minor_rev =3D + cap & UHS2_DEV_CONFIG_LT_MINOR_MASK; + card->uhs2_config.link_major_rev =3D + (cap >> UHS2_DEV_CONFIG_LT_MAJOR_POS) & + UHS2_DEV_CONFIG_LT_MAJOR_MASK; + card->uhs2_config.n_fcu =3D + (cap >> UHS2_DEV_CONFIG_N_FCU_POS) & + UHS2_DEV_CONFIG_N_FCU_MASK; + card->uhs2_config.dev_type =3D + (cap >> UHS2_DEV_CONFIG_DEV_TYPE_POS) & + UHS2_DEV_CONFIG_DEV_TYPE_MASK; + card->uhs2_config.maxblk_len =3D + (cap >> UHS2_DEV_CONFIG_MAX_BLK_LEN_POS) & + UHS2_DEV_CONFIG_MAX_BLK_LEN_MASK; + + cap =3D cmd.resp[1]; + card->uhs2_config.n_data_gap =3D + cap & UHS2_DEV_CONFIG_N_DATA_GAP_MASK; + if (card->uhs2_config.n_fcu =3D=3D 0) + card->uhs2_config.n_fcu =3D 256; + return 0; } =20 @@ -98,26 +461,350 @@ static int sd_uhs2_config_read(struct mmc_host *host,= struct mmc_card *card) */ static int sd_uhs2_config_write(struct mmc_host *host, struct mmc_card *ca= rd) { + struct mmc_command cmd =3D {0}; + struct uhs2_command uhs2_cmd =3D {}; + u8 nMinDataGap; + int err; + + /* + * Use Control Write CCMD to set Generic Setting in Configuration Registe= r. + * - Control Write(R/W=3D1) with 8-Byte payload(PLEN=3D10b). + * - IOADR =3D Generic Setting Register(CFG_BASE + 008h) + * - Payload =3D New contents to be written to Generic Setting Register + */ + uhs2_cmd.header =3D UHS2_NATIVE_PACKET | UHS2_PACKET_TYPE_CCMD | card->uh= s2_config.node_id; + uhs2_cmd.arg =3D ((UHS2_DEV_CONFIG_GEN_SET & 0xFF) << 8) | + UHS2_NATIVE_CMD_WRITE | + UHS2_NATIVE_CMD_PLEN_8B | + (UHS2_DEV_CONFIG_GEN_SET >> 8); + + /* + * Most UHS-II cards only support FD and 2L-HD mode. Other lane numbers + * defined in UHS-II addendem Ver1.01 are optional. + */ + host->uhs2_caps.n_lanes_set =3D UHS2_DEV_CONFIG_GEN_SET_2L_FD_HD; + card->uhs2_config.n_lanes_set =3D UHS2_DEV_CONFIG_GEN_SET_2L_FD_HD; + + uhs2_cmd.payload[0] =3D card->uhs2_config.n_lanes_set << UHS2_DEV_CONFIG_= N_LANES_POS; + uhs2_cmd.payload[1] =3D 0; + uhs2_cmd.payload[0] =3D cpu_to_be32(uhs2_cmd.payload[0]); + uhs2_cmd.payload[1] =3D cpu_to_be32(uhs2_cmd.payload[1]); + + /* + * There is no payload because per spec, there should be + * no payload field for read CCMD. + * Plen is set in arg. Per spec, plen for read CCMD + * represents the len of read data which is assigned in payload + * of following RES (p136). + */ + sd_uhs2_cmd_assemble(&cmd, &uhs2_cmd, UHS2_CFG_WRITE_PAYLOAD_LEN, 0); + + err =3D mmc_wait_for_cmd(host, &cmd, 0); + if (err) { + pr_err("%s: %s: UHS2 CMD send fail, err=3D 0x%x!\n", + mmc_hostname(host), __func__, err); + return err; + } + + /* + * Use Control Write CCMD to set PHY Setting in Configuration Register. + * - Control Write(R/W=3D1) with 8-Byte payload(PLEN=3D10b). + * - IOADR =3D PHY Setting Register(CFG_BASE + 00Ah) + * - Payload =3D New contents to be written to PHY Setting Register + */ + uhs2_cmd.arg =3D ((UHS2_DEV_CONFIG_PHY_SET & 0xFF) << 8) | + UHS2_NATIVE_CMD_WRITE | + UHS2_NATIVE_CMD_PLEN_8B | + (UHS2_DEV_CONFIG_PHY_SET >> 8); + + if (host->uhs2_caps.speed_range =3D=3D UHS2_DEV_CONFIG_PHY_SET_SPEED_B) { + if (card->uhs2_config.n_lanes =3D=3D UHS2_DEV_CONFIG_2L_HD_FD && + host->uhs2_caps.n_lanes =3D=3D UHS2_DEV_CONFIG_2L_HD_FD) { + /* Support HD */ + host->ios.timing =3D MMC_TIMING_UHS2_SPEED_B_HD; + nMinDataGap =3D 1; + } else { + /* Only support 2L-FD so far */ + host->ios.timing =3D MMC_TIMING_UHS2_SPEED_B; + nMinDataGap =3D 3; + } + card->uhs2_config.speed_range_set =3D UHS2_DEV_CONFIG_PHY_SET_SPEED_B; + } else { + if (card->uhs2_config.n_lanes =3D=3D UHS2_DEV_CONFIG_2L_HD_FD && + host->uhs2_caps.n_lanes =3D=3D UHS2_DEV_CONFIG_2L_HD_FD) { + /* Support HD */ + host->ios.timing =3D MMC_TIMING_UHS2_SPEED_A_HD; + nMinDataGap =3D 1; + } else { + /* Only support 2L-FD so far */ + host->ios.timing =3D MMC_TIMING_UHS2_SPEED_A; + nMinDataGap =3D 3; + } + card->uhs2_config.speed_range_set =3D UHS2_DEV_CONFIG_PHY_SET_SPEED_A; + } + + uhs2_cmd.payload[0] =3D + card->uhs2_config.speed_range_set << UHS2_DEV_CONFIG_PHY_SET_SPEED_POS; + + card->uhs2_config.n_lss_sync_set =3D (max(card->uhs2_config.n_lss_sync, + host->uhs2_caps.n_lss_sync) >> 2) & + UHS2_DEV_CONFIG_N_LSS_SYN_MASK; + host->uhs2_caps.n_lss_sync_set =3D card->uhs2_config.n_lss_sync_set; + + card->uhs2_config.n_lss_dir_set =3D (max(card->uhs2_config.n_lss_dir, + host->uhs2_caps.n_lss_dir) >> 3) & + UHS2_DEV_CONFIG_N_LSS_DIR_MASK; + host->uhs2_caps.n_lss_dir_set =3D card->uhs2_config.n_lss_dir_set; + + uhs2_cmd.payload[1] =3D (card->uhs2_config.n_lss_dir_set << UHS2_DEV_CONF= IG_N_LSS_DIR_POS) | + card->uhs2_config.n_lss_sync_set; + uhs2_cmd.payload[0] =3D cpu_to_be32(uhs2_cmd.payload[0]); + uhs2_cmd.payload[1] =3D cpu_to_be32(uhs2_cmd.payload[1]); + + memset(uhs2_cmd.uhs2_resp, 0, sizeof(uhs2_cmd.uhs2_resp)); + + sd_uhs2_cmd_assemble(&cmd, &uhs2_cmd, UHS2_CFG_WRITE_PAYLOAD_LEN, + UHS2_CFG_WRITE_PHY_SET_RESP_LEN); + + err =3D mmc_wait_for_cmd(host, &cmd, 0); + if (err) { + pr_err("%s: %s: UHS2 CMD send fail, err=3D 0x%x!\n", + mmc_hostname(host), __func__, err); + return err; + } + + if ((uhs2_cmd.uhs2_resp[2] & 0x80)) { + pr_err("%s: %s: UHS2 CMD not accepted, resp=3D 0x%x!\n", + mmc_hostname(host), __func__, uhs2_cmd.uhs2_resp[2]); + return -EIO; + } + + /* + * Use Control Write CCMD to set LINK/TRAN Setting in Configuration Regis= ter. + * - Control Write(R/W=3D1) with 8-Byte payload(PLEN=3D10b). + * - IOADR =3D LINK/TRAN Setting Register(CFG_BASE + 00Ch) + * - Payload =3D New contents to be written to LINK/TRAN Setting Register + */ + uhs2_cmd.arg =3D ((UHS2_DEV_CONFIG_LINK_TRAN_SET & 0xFF) << 8) | + UHS2_NATIVE_CMD_WRITE | + UHS2_NATIVE_CMD_PLEN_8B | + (UHS2_DEV_CONFIG_LINK_TRAN_SET >> 8); + + if (card->uhs2_config.app_type =3D=3D UHS2_DEV_CONFIG_APP_SD_MEM) + card->uhs2_config.maxblk_len_set =3D UHS2_DEV_CONFIG_LT_SET_MAX_BLK_LEN; + else + card->uhs2_config.maxblk_len_set =3D min(card->uhs2_config.maxblk_len, + host->uhs2_caps.maxblk_len); + host->uhs2_caps.maxblk_len_set =3D card->uhs2_config.maxblk_len_set; + + card->uhs2_config.n_fcu_set =3D min(card->uhs2_config.n_fcu, host->uhs2_c= aps.n_fcu); + host->uhs2_caps.n_fcu_set =3D card->uhs2_config.n_fcu_set; + + card->uhs2_config.n_data_gap_set =3D max(nMinDataGap, card->uhs2_config.n= _data_gap); + host->uhs2_caps.n_data_gap_set =3D card->uhs2_config.n_data_gap_set; + + host->uhs2_caps.max_retry_set =3D 3; + card->uhs2_config.max_retry_set =3D host->uhs2_caps.max_retry_set; + + uhs2_cmd.payload[0] =3D + (card->uhs2_config.maxblk_len_set << UHS2_DEV_CONFIG_MAX_BLK_LEN_POS) | + (card->uhs2_config.max_retry_set << UHS2_DEV_CONFIG_LT_SET_MAX_RETRY_PO= S) | + (card->uhs2_config.n_fcu_set << UHS2_DEV_CONFIG_N_FCU_POS); + uhs2_cmd.payload[1] =3D card->uhs2_config.n_data_gap_set; + uhs2_cmd.payload[0] =3D cpu_to_be32(uhs2_cmd.payload[0]); + uhs2_cmd.payload[1] =3D cpu_to_be32(uhs2_cmd.payload[1]); + + sd_uhs2_cmd_assemble(&cmd, &uhs2_cmd, UHS2_CFG_WRITE_PAYLOAD_LEN, 0); + + err =3D mmc_wait_for_cmd(host, &cmd, 0); + if (err) { + pr_err("%s: %s: UHS2 CMD send fail, err=3D 0x%x!\n", + mmc_hostname(host), __func__, err); + return err; + } + + /* + * Use Control Write CCMD to set Config Completion(payload bit 63) in Gen= eric Setting + * Register. + * Header: + * - Control Write(R/W=3D1) with 8-Byte payload(PLEN=3D10b). + * - IOADR =3D PGeneric Setting Register(CFG_BASE + 008h) + * Payload: + * - bit [63]: Config Completion + * + * DLSM transits to Active state immediately when Config Completion is se= t to 1. + */ + uhs2_cmd.arg =3D ((UHS2_DEV_CONFIG_GEN_SET & 0xFF) << 8) | + UHS2_NATIVE_CMD_WRITE | + UHS2_NATIVE_CMD_PLEN_8B | + (UHS2_DEV_CONFIG_GEN_SET >> 8); + + uhs2_cmd.payload[0] =3D 0; + uhs2_cmd.payload[1] =3D UHS2_DEV_CONFIG_GEN_SET_CFG_COMPLETE; + uhs2_cmd.payload[0] =3D cpu_to_be32(uhs2_cmd.payload[0]); + uhs2_cmd.payload[1] =3D cpu_to_be32(uhs2_cmd.payload[1]); + + memset(uhs2_cmd.uhs2_resp, 0, sizeof(uhs2_cmd.uhs2_resp)); + sd_uhs2_cmd_assemble(&cmd, &uhs2_cmd, UHS2_CFG_WRITE_PAYLOAD_LEN, + UHS2_CFG_WRITE_GENERIC_SET_RESP_LEN); + + err =3D mmc_wait_for_cmd(host, &cmd, 0); + if (err) { + pr_err("%s: %s: UHS2 CMD send fail, err=3D 0x%x!\n", + mmc_hostname(host), __func__, err); + return err; + } + + /* Set host Config Setting registers */ + err =3D host->ops->uhs2_control(host, UHS2_SET_CONFIG); + if (err) { + pr_err("%s: %s: UHS2 SET_CONFIG fail!\n", mmc_hostname(host), __func__); + return err; + } + return 0; } =20 -/* - * Initialize the UHS-II card through the SD-TRAN transport layer. This en= ables - * commands/requests to be backwards compatible through the legacy SD prot= ocol. - * UHS-II cards has a specific power limit specified for VDD1/VDD2, that s= hould - * be set through a legacy CMD6. Note that, the power limit that becomes s= et, - * survives a soft reset through the GO_DORMANT_STATE command. - */ -static int sd_uhs2_legacy_init(struct mmc_host *host, struct mmc_card *car= d) +static int sd_uhs2_go_dormant(struct mmc_host *host, u32 node_id) +{ + struct mmc_command cmd =3D {0}; + struct uhs2_command uhs2_cmd =3D {}; + int err; + + /* Disable Normal INT */ + err =3D host->ops->uhs2_control(host, UHS2_DISABLE_INT); + if (err) { + pr_err("%s: %s: UHS2 DISABLE_INT fail!\n", + mmc_hostname(host), __func__); + return err; + } + + /* + * Refer to UHS-II Addendum Version 1.02 Figure 6-17 to see GO_DORMANT_ST= ATE CCMD format. + * Header: + * - Control Write(R/W=3D1) with 4-Byte payload(PLEN=3D01b). + * - IOADR =3D CMD_BASE + 001h + * Payload: + * - bit [7]: HBR(Entry to Hibernate Mode) + * 1: Host intends to enter Hibernate mode during Dormant= state. + * The default setting is 0 because hibernate is currentl= y not supported. + */ + uhs2_cmd.header =3D UHS2_NATIVE_PACKET | UHS2_PACKET_TYPE_CCMD | node_id; + uhs2_cmd.arg =3D ((UHS2_DEV_CMD_GO_DORMANT_STATE & 0xFF) << 8) | + UHS2_NATIVE_CMD_WRITE | + UHS2_NATIVE_CMD_PLEN_4B | + (UHS2_DEV_CMD_GO_DORMANT_STATE >> 8); + + sd_uhs2_cmd_assemble(&cmd, &uhs2_cmd, UHS2_GO_DORMANT_PAYLOAD_LEN, 0); + + err =3D mmc_wait_for_cmd(host, &cmd, 0); + if (err) { + pr_err("%s: %s: UHS2 CMD send fail, err=3D 0x%x!\n", + mmc_hostname(host), __func__, err); + return err; + } + + /* Check Dormant State in Present */ + err =3D host->ops->uhs2_control(host, UHS2_CHECK_DORMANT); + if (err) + return err; + + /* Disable UHS2 card clock */ + err =3D host->ops->uhs2_control(host, UHS2_DISABLE_CLK); + if (err) + return err; + + /* Restore sd clock */ + mmc_delay(5); + err =3D host->ops->uhs2_control(host, UHS2_ENABLE_CLK); + if (err) + return err; + + /* Enable Normal INT */ + err =3D host->ops->uhs2_control(host, UHS2_ENABLE_INT); + if (err) + return err; + + /* Detect UHS2 */ + err =3D host->ops->uhs2_control(host, UHS2_PHY_INIT); + if (err) + return err; + + return 0; +} + +static int sd_uhs2_wait_active_state_cb(void *cb_data, bool *busy) +{ + struct sd_uhs2_wait_active_state_data *data =3D cb_data; + struct mmc_host *host =3D data->host; + struct mmc_command *cmd =3D data->cmd; + int err; + + err =3D mmc_wait_for_cmd(host, cmd, 0); + if (err) + return err; + + if (cmd->resp[1] & UHS2_DEV_CONFIG_GEN_SET_CFG_COMPLETE) + *busy =3D false; + else + *busy =3D true; + + return 0; +} + +static int sd_uhs2_go_dormant_state(struct mmc_host *host, u32 node_id) { + struct mmc_command cmd =3D {0}; + struct uhs2_command uhs2_cmd =3D {}; + int err; + struct sd_uhs2_wait_active_state_data cb_data =3D { + .host =3D host, + .cmd =3D &cmd + }; + + err =3D sd_uhs2_go_dormant(host, node_id); + if (err) { + pr_err("%s: %s: UHS2 GO_DORMANT_STATE fail, err=3D 0x%x!\n", + mmc_hostname(host), __func__, err); + return err; + } + + /* + * Use Control Read CCMD to check Config Completion(bit 63) in Generic Se= tting Register. + * - Control Read(R/W=3D0) with 8-Byte payload(PLEN=3D10b). + * - IOADR =3D Generic Setting Register(CFG_BASE + 008h) + * + * When UHS-II card been switched to new speed mode, it will set Config C= ompletion to 1. + */ + uhs2_cmd.header =3D UHS2_NATIVE_PACKET | UHS2_PACKET_TYPE_CCMD | node_id; + uhs2_cmd.arg =3D ((UHS2_DEV_CONFIG_GEN_SET & 0xFF) << 8) | + UHS2_NATIVE_CMD_READ | + UHS2_NATIVE_CMD_PLEN_8B | + (UHS2_DEV_CONFIG_GEN_SET >> 8); + + sd_uhs2_cmd_assemble(&cmd, &uhs2_cmd, 0, 0); + err =3D __mmc_poll_for_busy(host, UHS2_WAIT_CFG_COMPLETE_PERIOD_US, + UHS2_WAIT_CFG_COMPLETE_TIMEOUT_MS, + &sd_uhs2_wait_active_state_cb, &cb_data); + if (err) { + pr_err("%s: %s: Not switch to Active in 100 ms\n", mmc_hostname(host), _= _func__); + return err; + } + return 0; } =20 +static void sd_uhs2_remove(struct mmc_host *host) +{ + mmc_remove_card(host->card); + host->card =3D NULL; +} + /* * 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) +static int sd_uhs2_init_card(struct mmc_host *host, struct mmc_card *oldca= rd) { struct mmc_card *card; u32 node_id; @@ -131,9 +818,14 @@ static int sd_uhs2_init_card(struct mmc_host *host) if (err) return err; =20 - card =3D mmc_alloc_card(host, &sd_type); - if (IS_ERR(card)) - return PTR_ERR(card); + if (oldcard) { + card =3D oldcard; + } else { + card =3D mmc_alloc_card(host, &sd_type); + if (IS_ERR(card)) + return PTR_ERR(card); + } + host->card =3D card; =20 card->uhs2_config.node_id =3D node_id; card->type =3D MMC_TYPE_SD; @@ -146,18 +838,189 @@ static int sd_uhs2_init_card(struct mmc_host *host) if (err) goto err; =20 - host->card =3D card; + /* If change speed to Range B, need to GO_DORMANT_STATE */ + if (host->ios.timing =3D=3D MMC_TIMING_UHS2_SPEED_B || + host->ios.timing =3D=3D MMC_TIMING_UHS2_SPEED_B_HD) { + err =3D sd_uhs2_go_dormant_state(host, node_id); + if (err) + goto err; + } + + host->uhs2_sd_tran =3D true; + return 0; =20 err: - mmc_remove_card(card); + if (!oldcard) + mmc_remove_card(card); + else + sd_uhs2_remove(host); return err; } =20 -static void sd_uhs2_remove(struct mmc_host *host) +/* + * Initialize the UHS-II card through the SD-TRAN transport layer. This en= ables + * commands/requests to be backwards compatible through the legacy SD prot= ocol. + * UHS-II cards has a specific power limit specified for VDD1/VDD2, that s= hould + * be set through a legacy CMD6. Note that, the power limit that becomes s= et, + * survives a soft reset through the GO_DORMANT_STATE command. + */ +static int sd_uhs2_legacy_init(struct mmc_host *host, struct mmc_card *car= d) { - mmc_remove_card(host->card); - host->card =3D NULL; + int err; + u32 cid[4]; + u32 ocr; + u32 rocr; + u8 *status; + int ro; + + /* Send CMD0 to reset SD card */ + err =3D __mmc_go_idle(host); + if (err) + return err; + + mmc_delay(1); + + /* Send CMD8 to communicate SD interface operation condition */ + err =3D mmc_send_if_cond(host, host->ocr_avail); + if (err) { + dev_warn(mmc_dev(host), "CMD8 error\n"); + goto err; + } + + /* + * Probe SD card working voltage. + */ + err =3D mmc_send_app_op_cond(host, 0, &ocr); + if (err) + goto err; + + card->ocr =3D ocr; + + /* + * Some SD cards claims an out of spec VDD voltage range. Let's treat + * these bits as being in-valid and especially also bit7. + */ + ocr &=3D ~0x7FFF; + rocr =3D mmc_select_voltage(host, ocr); + /* + * Some cards have zero value of rocr in UHS-II mode. Assign host's + * ocr value to rocr. + */ + if (!rocr) + rocr =3D host->ocr_avail; + + rocr |=3D (SD_OCR_CCS | SD_OCR_XPC); + + /* Wait SD power on ready */ + ocr =3D rocr; + + err =3D mmc_send_app_op_cond(host, ocr, &rocr); + if (err) + goto err; + + err =3D mmc_send_cid(host, cid); + if (err) + goto err; + + memcpy(card->raw_cid, cid, sizeof(card->raw_cid)); + mmc_decode_cid(card); + + /* + * For native busses: get card RCA and quit open drain mode. + */ + err =3D mmc_send_relative_addr(host, &card->rca); + if (err) + goto err; + + err =3D mmc_sd_get_csd(card); + if (err) + goto err; + + /* + * Select card, as all following commands rely on that. + */ + err =3D mmc_select_card(card); + if (err) + goto err; + + /* + * Fetch SCR from card. + */ + err =3D mmc_app_send_scr(card); + if (err) + goto err; + + err =3D mmc_decode_scr(card); + if (err) + goto err; + + /* + * Switch to high power consumption mode. + * Even switch failed, sd card can still work at lower power consumption = mode, but + * performance will be lower than high power consumption mode. + */ + status =3D kmalloc(64, GFP_KERNEL); + if (!status) + return -ENOMEM; + + if (!(card->csd.cmdclass & CCC_SWITCH)) { + pr_warn("%s: card lacks mandatory switch function, performance might suf= fer\n", + mmc_hostname(card->host)); + } else { + /* send CMD6 to set Maximum Power Consumption to get better performance = */ + err =3D mmc_sd_switch(card, 0, 3, SD4_SET_POWER_LIMIT_1_80W, status); + if (!err) + err =3D mmc_sd_switch(card, 1, 3, SD4_SET_POWER_LIMIT_1_80W, status); + + err =3D 0; + } + + /* + * Check if read-only switch is active. + */ + ro =3D mmc_sd_get_ro(host); + if (ro < 0) { + pr_warn("%s: host does not support read-only switch, assuming write-enab= le\n", + mmc_hostname(host)); + } else if (ro > 0) { + mmc_card_set_readonly(card); + } + + /* + * NOTE: + * Should we read Externsion Register to check power notification feature= here? + */ + + kfree(status); + + return 0; + +err: + sd_uhs2_remove(host); + return err; +} + +static int sd_uhs2_reinit(struct mmc_host *host) +{ + struct mmc_card *card =3D host->card; + int err; + + sd_uhs2_power_up(host); + err =3D sd_uhs2_phy_init(host); + if (err) + return err; + + err =3D sd_uhs2_init_card(host, card); + if (err) + return err; + + err =3D sd_uhs2_legacy_init(host, card); + if (err) + return err; + + mmc_card_set_present(card); + return err; } =20 static int sd_uhs2_alive(struct mmc_host *host) @@ -179,38 +1042,194 @@ static void sd_uhs2_detect(struct mmc_host *host) mmc_claim_host(host); mmc_detach_bus(host); sd_uhs2_power_off(host); + /* Remove UHS2 timing to indicate the end of UHS2 mode */ + host->ios.timing =3D MMC_TIMING_LEGACY; mmc_release_host(host); } } =20 +static int _sd_uhs2_suspend(struct mmc_host *host) +{ + struct mmc_card *card =3D host->card; + int err =3D 0; + + mmc_claim_host(host); + + if (mmc_card_suspended(card)) + goto out; + + if (mmc_sd_can_poweroff_notify(card)) + err =3D sd_poweroff_notify(card); + + if (!err) { + sd_uhs2_power_off(host); + mmc_card_set_suspended(card); + } + +out: + mmc_release_host(host); + return err; +} + +/* + * Callback for suspend + */ static int sd_uhs2_suspend(struct mmc_host *host) { - return 0; + int err; + + err =3D _sd_uhs2_suspend(host); + if (!err) { + pm_runtime_disable(&host->card->dev); + pm_runtime_set_suspended(&host->card->dev); + } + + return err; +} + +/* + * This function tries to determine if the same card is still present + * and, if so, restore all state to it. + */ +static int _mmc_sd_uhs2_resume(struct mmc_host *host) +{ + int err =3D 0; + + mmc_claim_host(host); + + if (!mmc_card_suspended(host->card)) + goto out; + + /* Power up UHS2 SD card and re-initialize it. */ + err =3D sd_uhs2_reinit(host); + mmc_card_clr_suspended(host->card); + +out: + mmc_release_host(host); + return err; } =20 +/* + * Callback for resume + */ static int sd_uhs2_resume(struct mmc_host *host) { + pm_runtime_enable(&host->card->dev); return 0; } =20 +/* + * Callback for runtime_suspend. + */ static int sd_uhs2_runtime_suspend(struct mmc_host *host) { - return 0; + int err; + + if (!(host->caps & MMC_CAP_AGGRESSIVE_PM)) + return 0; + + err =3D _sd_uhs2_suspend(host); + if (err) + pr_err("%s: error %d doing aggressive suspend\n", mmc_hostname(host), er= r); + + return err; } =20 static int sd_uhs2_runtime_resume(struct mmc_host *host) { - return 0; + int err; + + err =3D _mmc_sd_uhs2_resume(host); + if (err && err !=3D -ENOMEDIUM) + pr_err("%s: error %d doing runtime resume\n", mmc_hostname(host), err); + + return err; } =20 -static int sd_uhs2_shutdown(struct mmc_host *host) +static int sd_uhs2_hw_reset(struct mmc_host *host) { - return 0; + int err; + + sd_uhs2_power_off(host); + /* Wait at least 1 ms according to SD spec */ + mmc_delay(1); + sd_uhs2_power_up(host); + + err =3D sd_uhs2_reinit(host); + + return err; } =20 -static int sd_uhs2_hw_reset(struct mmc_host *host) +/* + * mmc_uhs2_prepare_cmd - prepare for SD command packet + * @host: MMC host + * @mrq: MMC request + * + * Initialize and fill in a header and a payload of SD command packet. + * The caller should allocate uhs2_command in host->cmd->uhs2_cmd in + * advance. + * + * Return: 0 on success, non-zero error on failure + */ +void mmc_uhs2_prepare_cmd(struct mmc_host *host, struct mmc_request *mrq) { - return 0; + struct mmc_command *cmd; + struct uhs2_command *uhs2_cmd; + u8 plen; + + cmd =3D mrq->cmd; + cmd->uhs2_cmd =3D &mrq->uhs2_cmd; + uhs2_cmd =3D cmd->uhs2_cmd; + uhs2_cmd->header =3D host->card->uhs2_config.node_id; + if ((cmd->flags & MMC_CMD_MASK) =3D=3D MMC_CMD_ADTC) + uhs2_cmd->header |=3D UHS2_PACKET_TYPE_DCMD; + else + uhs2_cmd->header |=3D UHS2_PACKET_TYPE_CCMD; + + uhs2_cmd->arg =3D cmd->opcode << UHS2_SD_CMD_INDEX_POS; + if (host->uhs2_app_cmd) { + uhs2_cmd->arg |=3D UHS2_SD_CMD_APP; + host->uhs2_app_cmd =3D false; + } + + /* + * UHS-II Addendum 7.2.1.2 + * Host may set DM to 1 for DCMD which supports multi-block read/write re= gardless of + * data transfer length (e.g., CMD18, CMD25). Otherwise, it shall not set= DM to 1. + * (e.g., CMD6, CMD17, CMD24). These rules are also applied to other mult= i-block read/write + * commands defined in other Part of SD specifications (for example, Host= may set DM to 1 + * for ACMD18 or ACMD25). + */ + if (mmc_op_multi(cmd->opcode)) + cmd->uhs2_cmd->tmode_half_duplex =3D mmc_card_uhs2_hd_mode(host); + else + cmd->uhs2_cmd->tmode_half_duplex =3D 0; + + uhs2_cmd =3D cmd->uhs2_cmd; + plen =3D 2; /* at the maximum */ + + if ((cmd->flags & MMC_CMD_MASK) =3D=3D MMC_CMD_ADTC && + cmd->uhs2_cmd->tmode_half_duplex) { + if (mmc_card_uhs2_hd_mode(host)) + uhs2_cmd->arg |=3D UHS2_DCMD_2L_HD_MODE; + + uhs2_cmd->arg |=3D UHS2_DCMD_LM_TLEN_EXIST; + + if (cmd->data->blocks =3D=3D 1 && + cmd->data->blksz !=3D 512 && + cmd->opcode !=3D MMC_READ_SINGLE_BLOCK && + cmd->opcode !=3D MMC_WRITE_BLOCK) { + uhs2_cmd->arg |=3D UHS2_DCMD_TLUM_BYTE_MODE; + uhs2_cmd->payload[1] =3D cpu_to_be32(cmd->data->blksz); + } else { + uhs2_cmd->payload[1] =3D cpu_to_be32(cmd->data->blocks); + } + } else { + plen =3D 1; + } + + uhs2_cmd->payload[0] =3D cpu_to_be32(cmd->arg); + sd_uhs2_cmd_assemble(cmd, uhs2_cmd, plen, 0); } =20 static const struct mmc_bus_ops sd_uhs2_ops =3D { @@ -221,7 +1240,7 @@ static const struct mmc_bus_ops sd_uhs2_ops =3D { .resume =3D sd_uhs2_resume, .runtime_suspend =3D sd_uhs2_runtime_suspend, .runtime_resume =3D sd_uhs2_runtime_resume, - .shutdown =3D sd_uhs2_shutdown, + .shutdown =3D sd_uhs2_suspend, .hw_reset =3D sd_uhs2_hw_reset, }; =20 @@ -237,7 +1256,7 @@ static int sd_uhs2_attach(struct mmc_host *host) if (err) goto err; =20 - err =3D sd_uhs2_init_card(host); + err =3D sd_uhs2_init_card(host, NULL); if (err) goto err; =20 @@ -254,21 +1273,33 @@ static int sd_uhs2_attach(struct mmc_host *host) goto remove_card; =20 mmc_claim_host(host); + return 0; =20 remove_card: - mmc_remove_card(host->card); - host->card =3D NULL; + sd_uhs2_remove(host); mmc_claim_host(host); - mmc_detach_bus(host); + err: + mmc_detach_bus(host); sd_uhs2_power_off(host); + /* Remove UHS2 timing to indicate the end of UHS2 mode */ + host->ios.timing =3D MMC_TIMING_LEGACY; return err; } =20 +/** + * mmc_attach_sd_uhs2 - select UHS2 interface + * @host: MMC host + * + * Try to select UHS2 interface and initialize the bus for a given + * frequency, @freq. + * + * Return: 0 on success, non-zero error on failure + */ int mmc_attach_sd_uhs2(struct mmc_host *host) { - int i, err =3D 0; + int i, err; =20 if (!(host->caps2 & MMC_CAP2_SD_UHS2)) return -EOPNOTSUPP; @@ -283,6 +1314,9 @@ int mmc_attach_sd_uhs2(struct mmc_host *host) */ for (i =3D 0; i < ARRAY_SIZE(sd_uhs2_freqs); i++) { host->f_init =3D sd_uhs2_freqs[i]; + pr_debug("%s: %s: trying to init UHS-II card at %u Hz\n", + mmc_hostname(host), __func__, host->f_init); + err =3D sd_uhs2_attach(host); if (!err) break; diff --git a/include/linux/mmc/core.h b/include/linux/mmc/core.h index f0ac2e469b32..291f89e12c65 100644 --- a/include/linux/mmc/core.h +++ b/include/linux/mmc/core.h @@ -11,6 +11,20 @@ struct mmc_data; struct mmc_request; =20 +#define UHS2_MAX_PAYLOAD_LEN 2 +#define UHS2_MAX_RESP_LEN 20 + +struct uhs2_command { + u16 header; + u16 arg; + __be32 payload[UHS2_MAX_PAYLOAD_LEN]; + u8 payload_len; + u8 packet_len; + u8 tmode_half_duplex; + u8 uhs2_resp[UHS2_MAX_RESP_LEN]; /* UHS2 native cmd resp */ + u8 uhs2_resp_len; /* UHS2 native cmd resp len */ +}; + struct mmc_command { u32 opcode; u32 arg; @@ -96,6 +110,8 @@ struct mmc_command { unsigned int busy_timeout; /* busy detect timeout in ms */ struct mmc_data *data; /* data segment associated with cmd */ struct mmc_request *mrq; /* associated request */ + + struct uhs2_command *uhs2_cmd; /* UHS2 command */ }; =20 struct mmc_data { @@ -154,6 +170,7 @@ struct mmc_request { const struct bio_crypt_ctx *crypto_ctx; int crypto_key_slot; #endif + struct uhs2_command uhs2_cmd; }; =20 struct mmc_card; diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 0e1112ee160e..4b9e23f2afee 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -126,6 +126,13 @@ struct sd_uhs2_caps { }; =20 enum sd_uhs2_operation { + UHS2_PHY_INIT =3D 0, + UHS2_SET_CONFIG, + UHS2_ENABLE_INT, + UHS2_DISABLE_INT, + UHS2_ENABLE_CLK, + UHS2_DISABLE_CLK, + UHS2_CHECK_DORMANT, UHS2_SET_IOS, }; =20 @@ -452,6 +459,8 @@ struct mmc_host { #endif #define MMC_CAP2_ALT_GPT_TEGRA (1 << 28) /* Host with eMMC that has GPT en= try at a non-standard location */ =20 + bool uhs2_sd_tran; + bool uhs2_app_cmd; /* Host UHS-II APP Command */ struct sd_uhs2_caps uhs2_caps; /* Host UHS-II capabilities */ =20 int fixed_drv_type; /* fixed driver type for non-removable media */ @@ -713,6 +722,12 @@ static inline void mmc_debugfs_err_stats_inc(struct mm= c_host *host, host->err_stats[stat] +=3D 1; } =20 +static inline int mmc_card_uhs2_hd_mode(struct mmc_host *host) +{ + return host->ios.timing =3D=3D MMC_TIMING_UHS2_SPEED_A_HD || + host->ios.timing =3D=3D MMC_TIMING_UHS2_SPEED_B_HD; +} + int mmc_sd_switch(struct mmc_card *card, bool mode, int group, u8 value, u8 *resp); int mmc_send_status(struct mmc_card *card, u32 *status); --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pf1-f177.google.com (mail-pf1-f177.google.com [209.85.210.177]) (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 F30C61D86CE; Fri, 13 Sep 2024 10:29:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223360; cv=none; b=PBJzD8e0qXbxZMjjH8RHYfUClYr+ETI4CodBBOQyD0CHKFqg+pJoylTmbpHFkaUJ/UPNNA+t3jkM32gfX+B3ZnuVZLTyctsvu0zu4UyV7NIh+Y0LqoFCasapVl6NpspwXlOXyJmQp/VAyGoSy0fguSTuWNm7szGxQq0Fo1HtPnU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223360; c=relaxed/simple; bh=+sXmC7kyTGMKohOvh+2960PDmDNpZmnGORRSwgB2iKg=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=cVLjpOoymOAqsFJ+DwrppXkj33LmOwDACqX5U4Hy2F7AUvnkaCnJrN8XxnU6IF3KsIanqcpj107gue2gSv3il8HEUHWE9g1urMc7RDU3JqnaaVpXG47wvdxRZKYbhEbsoA4ZNVEJEABa8H8hBmjTQ3xcyxrYCBc7jgl32olBr4M= 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=ksRF2Ni0; arc=none smtp.client-ip=209.85.210.177 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="ksRF2Ni0" Received: by mail-pf1-f177.google.com with SMTP id d2e1a72fcca58-718e285544fso620333b3a.1; Fri, 13 Sep 2024 03:29:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223358; x=1726828158; 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=2BiV+abCFUR4wsdfncjsvsUIyTpX7pruMJBcr6f4UWM=; b=ksRF2Ni03ZHkpWMOtehqI6big2HjwP6+mHG1/gvouNrONt9L+iHvqycCVBcrg4HfR/ H5lYqH+x1fW3mSbnPY1FATKiNH0EY7Q8glYtnzh0JkVx/LdvIyIkUEMjgQGvTFhMFOBG PYzAyZhhuEmehfeu3+WpSoq0n37NE+agJ5EzcickUQzDtIC9yw2DxSNiPTf9M/ORG6rW OBR4R315zL8uYCPF2T9jgDkAzFPJekCfmnfhXkf9AhVKoixkRwGTIi7L0iwRPAmuEE1b lVpQNOE35eT3l9C3R3wfksL95MKkZbonTp/CacyZriHBoy0QCIScp5w5d6zt/KcQR85m ix/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223358; x=1726828158; 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=2BiV+abCFUR4wsdfncjsvsUIyTpX7pruMJBcr6f4UWM=; b=VkABmCnK+lJ3pQOjA+QLRGOMsbZXjUAQ5l0/kU1p2nSow/FtU21CTGAtKpLHQvQn1e JGEodJum2iWBLS8Vz3u8y5CC2XP4Du+uUIU6Wq8Z6GEhVjNLolv79IVkKT1tBsJIL4r3 n5SXmP24IN0+FqZOM3j/wakpchOBgs/ZUmSlNG2l+N2B6gNnAXGnUdlZIMf+epRXY+o6 JhAL4yM7iAHSHpWwVgOvE74TlGtY+K+6EvBF62LvO2cY2BVFtYHXhoercUbvEV8ayeER sCuibKIUdSbsTT4Wn9izndQ8yzpBXER9xr1OClGQia8M15Rh6A45B3x5r3a+aOci5YPc 1/jA== X-Forwarded-Encrypted: i=1; AJvYcCVB/qY0BIkwzWaT1QywVtiGXVOqKsUMgNlzJAmbKlICwlJWmMu9sKA+jM8tobVISMjgnP8rknfRildH6XM=@vger.kernel.org X-Gm-Message-State: AOJu0YxeSfGOaZE5rCGD/jAJJIJVTcSheF1+hEctkucLxow8eaDf1IfW DKPqVot2d66Zpza5D5vGrCTUdZoyqcDHnyK9ELuiUJHbwEBiiY6G X-Google-Smtp-Source: AGHT+IGA6ae2c9aFqL5+HDjed5cukjg1wq59XQqPiQjPY8zb/FB9T24lkDOtIFcKyRaPpRsLg10YgA== X-Received: by 2002:a05:6a00:39aa:b0:714:160e:8f5f with SMTP id d2e1a72fcca58-71936a4f533mr4284643b3a.11.1726223358013; Fri, 13 Sep 2024 03:29:18 -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.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:29:17 -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 08/22] mmc: sdhci: add UHS-II related definitions in headers Date: Fri, 13 Sep 2024 18:28:22 +0800 Message-Id: <20240913102836.6144-9-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 Add UHS-II related definitions in sdhci.h and sdhci-uhs2.h. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- Updates in V9: - Modify the commit message. Updates in V8: - Use tabs instead of spaces. Updates in V7: - Reorder values and positions of definitions. Updates in V6: - Rename definitions. - Use BIT() GENMASK() instead of bitwise operations. --- drivers/mmc/host/sdhci-uhs2.h | 177 ++++++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci.h | 54 ++++++++++- 2 files changed, 230 insertions(+), 1 deletion(-) create mode 100644 drivers/mmc/host/sdhci-uhs2.h diff --git a/drivers/mmc/host/sdhci-uhs2.h b/drivers/mmc/host/sdhci-uhs2.h new file mode 100644 index 000000000000..e993f41ffb7f --- /dev/null +++ b/drivers/mmc/host/sdhci-uhs2.h @@ -0,0 +1,177 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * linux/drivers/mmc/host/sdhci-uhs2.h - Secure Digital Host Controller I= nterface driver + * + * Header file for Host Controller UHS2 related registers. + * + * Copyright (C) 2014 Intel Corp, All Rights Reserved. + */ +#ifndef __SDHCI_UHS2_H +#define __SDHCI_UHS2_H + +#include + +/* SDHCI Category C registers : UHS2 usage */ + +#define SDHCI_UHS2_CM_TRAN_RESP 0x10 +#define SDHCI_UHS2_SD_TRAN_RESP 0x18 +#define SDHCI_UHS2_SD_TRAN_RESP_1 0x1C + +/* SDHCI Category B registers : UHS2 only */ + +#define SDHCI_UHS2_BLOCK_SIZE 0x80 +#define SDHCI_UHS2_MAKE_BLKSZ(dma, blksz) ((((dma) & 0x7) << 12) | ((blks= z) & 0xFFF)) + +#define SDHCI_UHS2_BLOCK_COUNT 0x84 + +#define SDHCI_UHS2_CMD_PACKET 0x88 +#define SDHCI_UHS2_CMD_PACK_MAX_LEN 20 + +#define SDHCI_UHS2_TRANS_MODE 0x9C +#define SDHCI_UHS2_TRNS_DMA BIT(0) +#define SDHCI_UHS2_TRNS_BLK_CNT_EN BIT(1) +#define SDHCI_UHS2_TRNS_DATA_TRNS_WRT BIT(4) +#define SDHCI_UHS2_TRNS_BLK_BYTE_MODE BIT(5) +#define SDHCI_UHS2_TRNS_RES_R5 BIT(6) +#define SDHCI_UHS2_TRNS_RES_ERR_CHECK_EN BIT(7) +#define SDHCI_UHS2_TRNS_RES_INT_DIS BIT(8) +#define SDHCI_UHS2_TRNS_WAIT_EBSY BIT(14) +#define SDHCI_UHS2_TRNS_2L_HD BIT(15) + +#define SDHCI_UHS2_CMD 0x9E +#define SDHCI_UHS2_CMD_SUB_CMD BIT(2) +#define SDHCI_UHS2_CMD_DATA BIT(5) +#define SDHCI_UHS2_CMD_TRNS_ABORT BIT(6) +#define SDHCI_UHS2_CMD_CMD12 BIT(7) +#define SDHCI_UHS2_CMD_DORMANT GENMASK(7, 6) +#define SDHCI_UHS2_CMD_PACK_LEN_MASK GENMASK(12, 8) + +#define SDHCI_UHS2_RESPONSE 0xA0 +#define SDHCI_UHS2_RESPONSE_MAX_LEN 20 + +#define SDHCI_UHS2_MSG_SELECT 0xB4 +#define SDHCI_UHS2_MSG_SELECT_CURR 0x0 +#define SDHCI_UHS2_MSG_SELECT_ONE 0x1 +#define SDHCI_UHS2_MSG_SELECT_TWO 0x2 +#define SDHCI_UHS2_MSG_SELECT_THREE 0x3 + +#define SDHCI_UHS2_MSG 0xB8 + +#define SDHCI_UHS2_DEV_INT_STATUS 0xBC + +#define SDHCI_UHS2_DEV_SELECT 0xBE +#define SDHCI_UHS2_DEV_SEL_MASK GENMASK(3, 0) +#define SDHCI_UHS2_DEV_SEL_INT_MSG_EN BIT(7) + +#define SDHCI_UHS2_DEV_INT_CODE 0xBF + +#define SDHCI_UHS2_SW_RESET 0xC0 +#define SDHCI_UHS2_SW_RESET_FULL BIT(0) +#define SDHCI_UHS2_SW_RESET_SD BIT(1) + +#define SDHCI_UHS2_TIMER_CTRL 0xC2 +#define SDHCI_UHS2_TIMER_CTRL_DEADLOCK_MASK GENMASK(7, 4) + +#define SDHCI_UHS2_INT_STATUS 0xC4 +#define SDHCI_UHS2_INT_STATUS_ENABLE 0xC8 +#define SDHCI_UHS2_INT_SIGNAL_ENABLE 0xCC +#define SDHCI_UHS2_INT_HEADER_ERR BIT(0) +#define SDHCI_UHS2_INT_RES_ERR BIT(1) +#define SDHCI_UHS2_INT_RETRY_EXP BIT(2) +#define SDHCI_UHS2_INT_CRC BIT(3) +#define SDHCI_UHS2_INT_FRAME_ERR BIT(4) +#define SDHCI_UHS2_INT_TID_ERR BIT(5) +#define SDHCI_UHS2_INT_UNRECOVER BIT(7) +#define SDHCI_UHS2_INT_EBUSY_ERR BIT(8) +#define SDHCI_UHS2_INT_ADMA_ERROR BIT(15) +#define SDHCI_UHS2_INT_CMD_TIMEOUT BIT(16) +#define SDHCI_UHS2_INT_DEADLOCK_TIMEOUT BIT(17) +#define SDHCI_UHS2_INT_VENDOR_ERR BIT(27) +#define SDHCI_UHS2_INT_ERROR_MASK ( \ + SDHCI_UHS2_INT_HEADER_ERR | \ + SDHCI_UHS2_INT_RES_ERR | \ + SDHCI_UHS2_INT_RETRY_EXP | \ + SDHCI_UHS2_INT_CRC | \ + SDHCI_UHS2_INT_FRAME_ERR | \ + SDHCI_UHS2_INT_TID_ERR | \ + SDHCI_UHS2_INT_UNRECOVER | \ + SDHCI_UHS2_INT_EBUSY_ERR | \ + SDHCI_UHS2_INT_ADMA_ERROR | \ + SDHCI_UHS2_INT_CMD_TIMEOUT | \ + SDHCI_UHS2_INT_DEADLOCK_TIMEOUT) +#define SDHCI_UHS2_INT_CMD_ERR_MASK ( \ + SDHCI_UHS2_INT_HEADER_ERR | \ + SDHCI_UHS2_INT_RES_ERR | \ + SDHCI_UHS2_INT_FRAME_ERR | \ + SDHCI_UHS2_INT_TID_ERR | \ + SDHCI_UHS2_INT_CMD_TIMEOUT) +/* CRC Error occurs during a packet receiving */ +#define SDHCI_UHS2_INT_DATA_ERR_MASK ( \ + SDHCI_UHS2_INT_RETRY_EXP | \ + SDHCI_UHS2_INT_CRC | \ + SDHCI_UHS2_INT_UNRECOVER | \ + SDHCI_UHS2_INT_EBUSY_ERR | \ + SDHCI_UHS2_INT_ADMA_ERROR | \ + SDHCI_UHS2_INT_DEADLOCK_TIMEOUT) + +#define SDHCI_UHS2_SETTINGS_PTR 0xE0 +#define SDHCI_UHS2_GEN_SETTINGS_POWER_LOW BIT(0) +#define SDHCI_UHS2_GEN_SETTINGS_N_LANES_MASK GENMASK(11, 8) +#define SDHCI_UHS2_FD_OR_2L_HD 0x0 /* 2 lanes */ +#define SDHCI_UHS2_2D1U_FD 0x2 /* 3 lanes, 2 down, 1 up, full duplex */ +#define SDHCI_UHS2_1D2U_FD 0x3 /* 3 lanes, 1 down, 2 up, full duplex */ +#define SDHCI_UHS2_2D2U_FD 0x4 /* 4 lanes, 2 down, 2 up, full duplex */ + +#define SDHCI_UHS2_PHY_SET_SPEED_B BIT(6) +#define SDHCI_UHS2_PHY_HIBERNATE_EN BIT(12) +#define SDHCI_UHS2_PHY_N_LSS_SYN_MASK GENMASK(19, 16) +#define SDHCI_UHS2_PHY_N_LSS_DIR_MASK GENMASK(23, 20) + +#define SDHCI_UHS2_TRAN_N_FCU_MASK GENMASK(15, 8) +#define SDHCI_UHS2_TRAN_RETRY_CNT_MASK GENMASK(17, 16) +#define SDHCI_UHS2_TRAN_1_N_DAT_GAP_MASK GENMASK(7, 0) + +#define SDHCI_UHS2_CAPS_PTR 0xE2 +#define SDHCI_UHS2_CAPS_OFFSET 0 +#define SDHCI_UHS2_CAPS_DAP_MASK GENMASK(3, 0) +#define SDHCI_UHS2_CAPS_GAP_MASK GENMASK(7, 4) +#define SDHCI_UHS2_CAPS_GAP(gap) ((gap) * 360) +#define SDHCI_UHS2_CAPS_LANE_MASK GENMASK(13, 8) +#define SDHCI_UHS2_CAPS_2L_HD_FD 1 +#define SDHCI_UHS2_CAPS_2D1U_FD 2 +#define SDHCI_UHS2_CAPS_1D2U_FD 4 +#define SDHCI_UHS2_CAPS_2D2U_FD 8 +#define SDHCI_UHS2_CAPS_ADDR_64 BIT(14) +#define SDHCI_UHS2_CAPS_BOOT BIT(15) +#define SDHCI_UHS2_CAPS_DEV_TYPE_MASK GENMASK(17, 16) +#define SDHCI_UHS2_CAPS_DEV_TYPE_RMV 0 +#define SDHCI_UHS2_CAPS_DEV_TYPE_EMB 1 +#define SDHCI_UHS2_CAPS_DEV_TYPE_EMB_RMV 2 +#define SDHCI_UHS2_CAPS_NUM_DEV_MASK GENMASK(21, 18) +#define SDHCI_UHS2_CAPS_BUS_TOPO_MASK GENMASK(23, 22) +#define SDHCI_UHS2_CAPS_BUS_TOPO_SHIFT 22 +#define SDHCI_UHS2_CAPS_BUS_TOPO_P2P 0 +#define SDHCI_UHS2_CAPS_BUS_TOPO_RING 1 +#define SDHCI_UHS2_CAPS_BUS_TOPO_HUB 2 +#define SDHCI_UHS2_CAPS_BUS_TOPO_HUB_RING 3 + +#define SDHCI_UHS2_CAPS_PHY_OFFSET 4 +#define SDHCI_UHS2_CAPS_PHY_REV_MASK GENMASK(5, 0) +#define SDHCI_UHS2_CAPS_PHY_RANGE_MASK GENMASK(7, 6) +#define SDHCI_UHS2_CAPS_PHY_RANGE_A 0 +#define SDHCI_UHS2_CAPS_PHY_RANGE_B 1 +#define SDHCI_UHS2_CAPS_PHY_N_LSS_SYN_MASK GENMASK(19, 16) +#define SDHCI_UHS2_CAPS_PHY_N_LSS_DIR_MASK GENMASK(23, 20) +#define SDHCI_UHS2_CAPS_TRAN_OFFSET 8 +#define SDHCI_UHS2_CAPS_TRAN_LINK_REV_MASK GENMASK(5, 0) +#define SDHCI_UHS2_CAPS_TRAN_N_FCU_MASK GENMASK(15, 8) +#define SDHCI_UHS2_CAPS_TRAN_HOST_TYPE_MASK GENMASK(18, 16) +#define SDHCI_UHS2_CAPS_TRAN_BLK_LEN_MASK GENMASK(31, 20) + +#define SDHCI_UHS2_CAPS_TRAN_1_OFFSET 12 +#define SDHCI_UHS2_CAPS_TRAN_1_N_DATA_GAP_MASK GENMASK(7, 0) + +#define SDHCI_UHS2_EMBED_CTRL_PTR 0xE6 +#define SDHCI_UHS2_VENDOR_PTR 0xE8 + +#endif /* __SDHCI_UHS2_H */ diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index f531b617f28d..e1013925e91e 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -43,8 +43,23 @@ #define SDHCI_TRNS_READ 0x10 #define SDHCI_TRNS_MULTI 0x20 =20 +/* + * Defined in Host Version 4.0. + */ +#define SDHCI_TRNS_RES_TYPE 0x40 +#define SDHCI_TRNS_RES_ERR_CHECK 0x80 +#define SDHCI_TRNS_RES_INT_DIS 0x0100 + #define SDHCI_COMMAND 0x0E #define SDHCI_CMD_RESP_MASK 0x03 + +/* + * Host Version 4.10 adds this bit to distinguish a main command or + * sub command. + * For example with SDIO, CMD52 (sub command) issued during CMD53 (main co= mmand). + */ +#define SDHCI_CMD_SUB_CMD 0x04 + #define SDHCI_CMD_CRC 0x08 #define SDHCI_CMD_INDEX 0x10 #define SDHCI_CMD_DATA 0x20 @@ -65,6 +80,9 @@ #define SDHCI_PRESENT_STATE 0x24 #define SDHCI_CMD_INHIBIT 0x00000001 #define SDHCI_DATA_INHIBIT 0x00000002 + +#define SDHCI_DAT_4_TO_7_LVL_MASK 0x000000F0 + #define SDHCI_DOING_WRITE 0x00000100 #define SDHCI_DOING_READ 0x00000200 #define SDHCI_SPACE_AVAILABLE 0x00000400 @@ -80,6 +98,15 @@ #define SDHCI_DATA_0_LVL_MASK 0x00100000 #define SDHCI_CMD_LVL 0x01000000 =20 +/* Host Version 4.10 */ + +#define SDHCI_HOST_REGULATOR_STABLE 0x02000000 +#define SDHCI_CMD_NOT_ISSUED_ERR 0x08000000 +#define SDHCI_SUB_CMD_STATUS 0x10000000 +#define SDHCI_UHS2_IN_DORMANT_STATE 0x20000000 +#define SDHCI_UHS2_LANE_SYNC 0x40000000 +#define SDHCI_UHS2_IF_DETECT 0x80000000 + #define SDHCI_HOST_CONTROL 0x28 #define SDHCI_CTRL_LED 0x01 #define SDHCI_CTRL_4BITBUS 0x02 @@ -117,7 +144,7 @@ #define SDHCI_CLOCK_CONTROL 0x2C #define SDHCI_DIVIDER_SHIFT 8 #define SDHCI_DIVIDER_HI_SHIFT 6 -#define SDHCI_DIV_MASK 0xFF +#define SDHCI_DIV_MASK 0xFF #define SDHCI_DIV_MASK_LEN 8 #define SDHCI_DIV_HI_MASK 0x300 #define SDHCI_PROG_CLOCK_MODE 0x0020 @@ -146,6 +173,10 @@ #define SDHCI_INT_CARD_REMOVE 0x00000080 #define SDHCI_INT_CARD_INT 0x00000100 #define SDHCI_INT_RETUNE 0x00001000 + +/* Host Version 4.10 */ +#define SDHCI_INT_FX_EVENT 0x00002000 + #define SDHCI_INT_CQE 0x00004000 #define SDHCI_INT_ERROR 0x00008000 #define SDHCI_INT_TIMEOUT 0x00010000 @@ -160,6 +191,9 @@ #define SDHCI_INT_ADMA_ERROR 0x02000000 #define SDHCI_INT_TUNING_ERROR 0x04000000 =20 +/* Host Version 4.0 */ +#define SDHCI_INT_RESP_ERR 0x08000000 + #define SDHCI_INT_NORMAL_MASK 0x00007FFF #define SDHCI_INT_ERROR_MASK 0xFFFF8000 =20 @@ -186,6 +220,9 @@ #define SDHCI_AUTO_CMD_END_BIT 0x00000008 #define SDHCI_AUTO_CMD_INDEX 0x00000010 =20 +/* Host Version 4.10 */ +#define SDHCI_AUTO_CMD_RESP_ERR 0x0020 + #define SDHCI_HOST_CONTROL2 0x3E #define SDHCI_CTRL_UHS_MASK 0x0007 #define SDHCI_CTRL_UHS_SDR12 0x0000 @@ -194,6 +231,7 @@ #define SDHCI_CTRL_UHS_SDR104 0x0003 #define SDHCI_CTRL_UHS_DDR50 0x0004 #define SDHCI_CTRL_HS400 0x0005 /* Non-standard */ +#define SDHCI_CTRL_UHS2 0x0007 #define SDHCI_CTRL_VDD_180 0x0008 #define SDHCI_CTRL_DRV_TYPE_MASK 0x0030 #define SDHCI_CTRL_DRV_TYPE_B 0x0000 @@ -202,9 +240,12 @@ #define SDHCI_CTRL_DRV_TYPE_D 0x0030 #define SDHCI_CTRL_EXEC_TUNING 0x0040 #define SDHCI_CTRL_TUNED_CLK 0x0080 +#define SDHCI_CTRL_UHS2_ENABLE 0x0100 +#define SDHCI_CTRL_ADMA2_LEN_MODE 0x0400 #define SDHCI_CMD23_ENABLE 0x0800 #define SDHCI_CTRL_V4_MODE 0x1000 #define SDHCI_CTRL_64BIT_ADDR 0x2000 +#define SDHCI_CTRL_ASYNC_INT_ENABLE 0x4000 #define SDHCI_CTRL_PRESET_VAL_ENABLE 0x8000 =20 #define SDHCI_CAPABILITIES 0x40 @@ -227,11 +268,13 @@ #define SDHCI_CAN_VDD_180 0x04000000 #define SDHCI_CAN_64BIT_V4 0x08000000 #define SDHCI_CAN_64BIT 0x10000000 +#define SDHCI_CAN_ASYNC_INT 0x20000000 =20 #define SDHCI_CAPABILITIES_1 0x44 #define SDHCI_SUPPORT_SDR50 0x00000001 #define SDHCI_SUPPORT_SDR104 0x00000002 #define SDHCI_SUPPORT_DDR50 0x00000004 +#define SDHCI_SUPPORT_UHS2 0x00000008 #define SDHCI_DRIVER_TYPE_A 0x00000010 #define SDHCI_DRIVER_TYPE_C 0x00000020 #define SDHCI_DRIVER_TYPE_D 0x00000040 @@ -240,6 +283,7 @@ #define SDHCI_RETUNING_MODE_MASK GENMASK(15, 14) #define SDHCI_CLOCK_MUL_MASK GENMASK(23, 16) #define SDHCI_CAN_DO_ADMA3 0x08000000 +#define SDHCI_CAN_VDD2_180 0x10000000 /* UHS-2 1.8V VDD2 */ #define SDHCI_SUPPORT_HS400 0x80000000 /* Non-standard */ =20 #define SDHCI_MAX_CURRENT 0x48 @@ -247,11 +291,14 @@ #define SDHCI_MAX_CURRENT_330_MASK GENMASK(7, 0) #define SDHCI_MAX_CURRENT_300_MASK GENMASK(15, 8) #define SDHCI_MAX_CURRENT_180_MASK GENMASK(23, 16) +#define SDHCI_MAX_CURRENT_1 0x4C +#define SDHCI_MAX_CURRENT_VDD2_180_MASK GENMASK(7, 0) /* UHS2 */ #define SDHCI_MAX_CURRENT_MULTIPLIER 4 =20 /* 4C-4F reserved for more max current */ =20 #define SDHCI_SET_ACMD12_ERROR 0x50 +/* Host Version 4.10 */ #define SDHCI_SET_INT_ERROR 0x52 =20 #define SDHCI_ADMA_ERROR 0x54 @@ -270,10 +317,15 @@ #define SDHCI_PRESET_FOR_SDR104 0x6C #define SDHCI_PRESET_FOR_DDR50 0x6E #define SDHCI_PRESET_FOR_HS400 0x74 /* Non-standard */ + +/* UHS2 */ +#define SDHCI_PRESET_FOR_UHS2 0x74 #define SDHCI_PRESET_DRV_MASK GENMASK(15, 14) #define SDHCI_PRESET_CLKGEN_SEL BIT(10) #define SDHCI_PRESET_SDCLK_FREQ_MASK GENMASK(9, 0) =20 +#define SDHCI_ADMA3_ADDRESS 0x78 + #define SDHCI_SLOT_INT_STATUS 0xFC =20 #define SDHCI_HOST_VERSION 0xFE --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 A42C01DA2E7; Fri, 13 Sep 2024 10:29:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223365; cv=none; b=QNiy06B11Ng99A3RA9tFW2HSjvSsV9IaUK2D6SO0cANCVaPJ6khWWmmxUlx65ChoUXsnVDUaFq/nvh2gWwtpVd/M+HVrNGc0r3L9WY70Mg8xdG0AVL67bhCtVKzCQleUXd7FUxzMW0SDK7766dVVn1ww3eM7XWKx0tv0gBEYzkE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223365; c=relaxed/simple; bh=cPTPqssbzIZVfDNGZdIYNAFD7BVSVTBiliWw762LKXY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aUrDvy7Ivs3DO3N/HGEcJ6Mj3wmZKQWsi+GDjTVAlfRe69T6BNZ4X4d90KQ+qKIkPymQZYI4xyKGcAZOylEhMs3V9NqsZH6lQNAvS81OqJaRNyJQM4l3iiqP6H0MqIOnJaXTSoiD7ui/FFPfidsjcx5UWJbNqfDUh9/gmnOHeMg= 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=Dn5NsaBd; arc=none smtp.client-ip=209.85.210.169 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="Dn5NsaBd" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-718e9c8bd83so2241316b3a.1; Fri, 13 Sep 2024 03:29:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223363; x=1726828163; 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=ZB/r5QcrC2W23fyVv+wkCCFI69L0021XWlE3anCdksM=; b=Dn5NsaBdJzVtcgKIRigOEu4qt38waDvgFrvPN4PDoAZQ/pe7f82GZTbus8zdejzWlk 8kG7MMaDPC2XGQLFSOQZzPI57kdSzydlVxDRUEGwm518XHC5GCp1edkJqxzFAEazMGJa nnvQKfRVtH8hFI7XzYwQ4ByQj7Vt9CrMREloJDlguhkNoH0x51yyK5CFhaVm4oU0e1OP mDqPUuxJ77fw6QCju3pb1W8oCSu4sgqKAnIkocwDnmmG6l05eAVdV//4I6XoDAPIRVbS xx5oDTZOCx+vGrcBdAZjKe0joxBiGn518R7cC3HxiV8rxaAxW9zqKzTWEb0vfMeH+fS9 WySw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223363; x=1726828163; 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=ZB/r5QcrC2W23fyVv+wkCCFI69L0021XWlE3anCdksM=; b=hrXQ6f5e1sJ85ieKfP66MbZmwy4yUXiRLH/FQ29HhcTmN0w/y/Y50XY5SjEA0/NiFv lQFqY2ovtZ4p+bIZRg3jR9DXO8WcudJxo3iM2YPpIoa/y3IaR4aLFSflkGYc9k2oZs+F tHoS76rQpikx+ngxZa3LvrRFi0Glo52JES5K3nF3P2qCQ/MjMeTJi1cttmKRJhl6XAGU l4boPfsWNO9l6PlS7PhqmVbYN6ioZ9oE96J9+E1GDMUGf0G90rbQorJohUQayc5XoTwN fbwqayYro8hz2Hi+6hKmWguPMxJ0PkF7/gpiOROEY+Wn2Hhd20LirrlUCWZh0G/irYYq 3Ycw== X-Forwarded-Encrypted: i=1; AJvYcCXVvSAiVMX8IV3R0DomfN2Ui67M1vpCagzqazu8av+0PM2n+CcACxgsdRZ4UYLcNpzOl9NFuRGDidGEOdc=@vger.kernel.org X-Gm-Message-State: AOJu0YzeFRKTgPHKuTwh96u522iuS3TRsIyL/YkKWYDrfXMtCXE9nWWv gEJx+kMK4VRDvM1jyNeYeRb17UXkGLfyXb/BbTDcm6IQPy1e/Vjo2Yhfi47W X-Google-Smtp-Source: AGHT+IHTAbI+3Vu6byLJC1cBH8090LasgimQD5C2vIVWAY/r2a7dr5+mINI5eTsyKhCEFJFp6B7ISg== X-Received: by 2002:a05:6a20:c799:b0:1cf:38cf:dfb6 with SMTP id adf61e73a8af0-1cf756c3ea6mr9423792637.20.1726223362578; Fri, 13 Sep 2024 03:29:22 -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.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:29:22 -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 09/22] mmc: sdhci: add UHS-II module and add a kernel configuration Date: Fri, 13 Sep 2024 18:28:23 +0800 Message-Id: <20240913102836.6144-10-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 patch adds sdhci-uhs2.c as a module for UHS-II support. This is a skeleton for further development in this patch series. This kernel configuration, CONFIG_MMC_SDHCI_UHS2, will be used in the following commits to indicate UHS-II specific code in sdhci controllers. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- Updates in V22: - Remove defined but not used code. Updates in V9: - Modify the commit message. Updates in V8: - Modify MODULE_LICENSE from "GPL v2" to "GPL". Updates in V6: - Merage V5 of patch[7] and patch[9] in to V6 of patch[8]. --- drivers/mmc/host/Kconfig | 9 ++++++++ drivers/mmc/host/Makefile | 1 + drivers/mmc/host/sdhci-uhs2.c | 41 +++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 drivers/mmc/host/sdhci-uhs2.c diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig index 7199cb0bd0b9..f636af8a98df 100644 --- a/drivers/mmc/host/Kconfig +++ b/drivers/mmc/host/Kconfig @@ -98,6 +98,15 @@ config MMC_SDHCI_BIG_ENDIAN_32BIT_BYTE_SWAPPER =20 This is the case for the Nintendo Wii SDHCI. =20 +config MMC_SDHCI_UHS2 + tristate "UHS2 support on SDHCI controller" + depends on MMC_SDHCI + help + This option is selected by SDHCI controller drivers that want to + support UHS2-capable devices. + + If you have a controller with this feature, say Y or M here. + config MMC_SDHCI_PCI tristate "SDHCI support on PCI bus" depends on MMC_SDHCI && PCI diff --git a/drivers/mmc/host/Makefile b/drivers/mmc/host/Makefile index 3ccffebbe59b..5147467ec825 100644 --- a/drivers/mmc/host/Makefile +++ b/drivers/mmc/host/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_MMC_PXA) +=3D pxamci.o obj-$(CONFIG_MMC_MXC) +=3D mxcmmc.o obj-$(CONFIG_MMC_MXS) +=3D mxs-mmc.o obj-$(CONFIG_MMC_SDHCI) +=3D sdhci.o +obj-$(CONFIG_MMC_SDHCI_UHS2) +=3D sdhci-uhs2.o obj-$(CONFIG_MMC_SDHCI_PCI) +=3D sdhci-pci.o sdhci-pci-y +=3D sdhci-pci-core.o sdhci-pci-o2micro.o sdhci-pci-arasan.o= \ sdhci-pci-dwc-mshc.o sdhci-pci-gli.o diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c new file mode 100644 index 000000000000..9ec1d6abb47c --- /dev/null +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * linux/drivers/mmc/host/sdhci_uhs2.c - Secure Digital Host Controller + * Interface driver + * + * Copyright (C) 2014 Intel Corp, All Rights Reserved. + * Copyright (C) 2020 Genesys Logic, Inc. + * Authors: Ben Chuang + * Copyright (C) 2020 Linaro Limited + * Author: AKASHI Takahiro + */ + +#include + +#include "sdhci.h" +#include "sdhci-uhs2.h" + +#define DRIVER_NAME "sdhci_uhs2" +#define DBG(f, x...) \ + pr_debug(DRIVER_NAME " [%s()]: " f, __func__, ## x) + +/*************************************************************************= ****\ + * = * + * Driver init/exit = * + * = * +\*************************************************************************= ****/ + +static int __init sdhci_uhs2_mod_init(void) +{ + return 0; +} +module_init(sdhci_uhs2_mod_init); + +static void __exit sdhci_uhs2_mod_exit(void) +{ +} +module_exit(sdhci_uhs2_mod_exit); + +MODULE_AUTHOR("Intel, Genesys Logic, Linaro"); +MODULE_DESCRIPTION("MMC UHS-II Support"); +MODULE_LICENSE("GPL"); --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 0AE271DB524; Fri, 13 Sep 2024 10:29:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223369; cv=none; b=KHV4rPNqSqlSU0tednTN0A8C2gBn4aOpoLjC9rzCZUE705cBTyU//q5QLPOTdK/Np6XK/BBjMQpmuERh02ZmBEEBgK0NwNeWYm68ea0JlVvEtlzTIYcW+8ENokmvSrUh+JKTT16jI4iQZWRYGA2iW6Y4hr8abFGJ45FER8+A7Ks= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223369; c=relaxed/simple; bh=xwFiWQ5tOpWStPyh3+9Y+jsJxfVLG9TjYX8BQUYRy6U=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=TTxvNwtWJ2TpForBA1kIdtUNPqx2+yENk2D8ELXHHcLfdGUBvbjH7DEgwNEJRmqdsE78L0cSY/Fe9MlsRZH2LvdvgxgrgJ4ZJTb3KIzio+/0pcJzp+J5WGA8Or1Y+MwBnkM/HYx++5JhZL4CFLaFlBbwhtB42Y4bBD6Vu2di+KY= 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=I8ZjNb5t; arc=none smtp.client-ip=209.85.215.170 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="I8ZjNb5t" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-7d666fb3fb9so1014534a12.0; Fri, 13 Sep 2024 03:29:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223367; x=1726828167; 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=tY1jYPZ8EM+61uC7VsYBzo9x1mBBtiuwXTRSGcxof4I=; b=I8ZjNb5tPTrg/xSmg9gQvA1ZxALVAPAQNzoFBzI90kF10Q3ION/7PgiQMYR7LnzTzv UsfefPix+GA14jYdjT2djUIcfZqQuULTMKU3WIwTX5oBkVxISn4jQTxAUx+xWU2d12TC fnxXOPMMyoJ2mIIBPuSyXKJkWGS5/mpJ7nGLhrtK2EiMMDWvbKnjrXhTd6ons///dI9b S9wLQVPtPjBCczKLcBWDfUgz1yOJ8a3ZcwOe+HxjHlsghOyoD/dcpiBoBeJVa+ZFF/DV VDQNx4105FPvhBvVIVa4SKh8dROoZyYL5xCI7KoytvXJ8TQaPrdNV4c5aOsTyPhsus2R k04g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223367; x=1726828167; 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=tY1jYPZ8EM+61uC7VsYBzo9x1mBBtiuwXTRSGcxof4I=; b=Fc5czWkZ4p9vRK2/89EH8G3yPGFp8XHqQaRDy6oP0r2cKhTsg0J39/e4iO5tkAM3KY DBTObTtY91eklhnRQ2cKs18pHPX7X9NbL8n0LZATK7LUQn28C20+ry2Qpex1AWOGypkh 8Tn0Y7SqtFF/Vv3tPAWCp3crK3u4VhFYIAD/BKjCu5pfRlh/h/6BIJ7BjcBXqEPo09da S0+BEk8QV/jCyGQJIxAeroWKWdji9pKQ9z9AWTyQkEnw2LtEBGpKDzufTnhzEoxXFygv 0BleYg0FrsQY7MR8WbOUrcbNn/LwHKXimNcdRLLDEkuMAju560igQx8uWh0+8ysk1mOC CWhA== X-Forwarded-Encrypted: i=1; AJvYcCUBXBhqQKz8UPyUPJKmHN5/bX6W8FZ6FiMIoNbbSCW7FNz2KE9tqcN2ooxjCAeeeqgeRETgOAbHZ3z2OU8=@vger.kernel.org X-Gm-Message-State: AOJu0YxPQN9xogVsH9Tkg7UZHqfK6upf4SsM6Xls2bIQJ3ub8MhXhNv6 m8rI51L9LJeIZUbgpIYaG6cM6ORcrY275cYB48uCMpXTiV56F79r X-Google-Smtp-Source: AGHT+IF3IOhB6XMUv1oqL/RItOlKQeXIKx/ijb6DPPFRRPbetQOO0yqBxvKcQvLiH2/MIo/lhKOQbQ== X-Received: by 2002:a05:6a20:c70b:b0:1cf:359b:1a31 with SMTP id adf61e73a8af0-1cf756c404bmr9945813637.19.1726223367091; Fri, 13 Sep 2024 03:29:27 -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.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:29:26 -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 10/22] mmc: sdhci-uhs2: dump UHS-II registers Date: Fri, 13 Sep 2024 18:28:24 +0800 Message-Id: <20240913102836.6144-11-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 Dump UHS-II specific registers, if available, in sdhci_dumpregs() for informative/debugging use. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- Updates in V14: - Use mmc_card_uhs2() to stead sdhci_uhs2_mode() in the sdhci_uhs2_dump_regs(). Updates in V7: - Use sdhci_uhs2_mode() to simplify code. Updates in V6: - Remove unnecessary code. --- drivers/mmc/host/sdhci-uhs2.c | 30 ++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci-uhs2.h | 4 ++++ drivers/mmc/host/sdhci.c | 3 +++ drivers/mmc/host/sdhci.h | 1 + 4 files changed, 38 insertions(+) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index 9ec1d6abb47c..14514710e763 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -18,6 +18,36 @@ #define DRIVER_NAME "sdhci_uhs2" #define DBG(f, x...) \ pr_debug(DRIVER_NAME " [%s()]: " f, __func__, ## x) +#define SDHCI_UHS2_DUMP(f, x...) \ + pr_err("%s: " DRIVER_NAME ": " f, mmc_hostname(host->mmc), ## x) + +void sdhci_uhs2_dump_regs(struct sdhci_host *host) +{ + if (!(mmc_card_uhs2(host->mmc))) + return; + + SDHCI_UHS2_DUMP("=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D UHS2 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D\n"); + SDHCI_UHS2_DUMP("Blk Size: 0x%08x | Blk Cnt: 0x%08x\n", + sdhci_readw(host, SDHCI_UHS2_BLOCK_SIZE), + sdhci_readl(host, SDHCI_UHS2_BLOCK_COUNT)); + SDHCI_UHS2_DUMP("Cmd: 0x%08x | Trn mode: 0x%08x\n", + sdhci_readw(host, SDHCI_UHS2_CMD), + sdhci_readw(host, SDHCI_UHS2_TRANS_MODE)); + SDHCI_UHS2_DUMP("Int Stat: 0x%08x | Dev Sel : 0x%08x\n", + sdhci_readw(host, SDHCI_UHS2_DEV_INT_STATUS), + sdhci_readb(host, SDHCI_UHS2_DEV_SELECT)); + SDHCI_UHS2_DUMP("Dev Int Code: 0x%08x\n", + sdhci_readb(host, SDHCI_UHS2_DEV_INT_CODE)); + SDHCI_UHS2_DUMP("Reset: 0x%08x | Timer: 0x%08x\n", + sdhci_readw(host, SDHCI_UHS2_SW_RESET), + sdhci_readw(host, SDHCI_UHS2_TIMER_CTRL)); + SDHCI_UHS2_DUMP("ErrInt: 0x%08x | ErrIntEn: 0x%08x\n", + sdhci_readl(host, SDHCI_UHS2_INT_STATUS), + sdhci_readl(host, SDHCI_UHS2_INT_STATUS_ENABLE)); + SDHCI_UHS2_DUMP("ErrSigEn: 0x%08x\n", + sdhci_readl(host, SDHCI_UHS2_INT_SIGNAL_ENABLE)); +} +EXPORT_SYMBOL_GPL(sdhci_uhs2_dump_regs); =20 /*************************************************************************= ****\ * = * diff --git a/drivers/mmc/host/sdhci-uhs2.h b/drivers/mmc/host/sdhci-uhs2.h index e993f41ffb7f..2bfe18d29bca 100644 --- a/drivers/mmc/host/sdhci-uhs2.h +++ b/drivers/mmc/host/sdhci-uhs2.h @@ -174,4 +174,8 @@ #define SDHCI_UHS2_EMBED_CTRL_PTR 0xE6 #define SDHCI_UHS2_VENDOR_PTR 0xE8 =20 +struct sdhci_host; + +void sdhci_uhs2_dump_regs(struct sdhci_host *host); + #endif /* __SDHCI_UHS2_H */ diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 4b91c9e96635..5a5fe3528bb4 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -110,6 +110,9 @@ void sdhci_dumpregs(struct sdhci_host *host) } } =20 + if (host->ops->dump_uhs2_regs) + host->ops->dump_uhs2_regs(host); + if (host->ops->dump_vendor_regs) host->ops->dump_vendor_regs(host); =20 diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index e1013925e91e..66ab90bd4017 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -719,6 +719,7 @@ struct sdhci_ops { void (*request_done)(struct sdhci_host *host, struct mmc_request *mrq); void (*dump_vendor_regs)(struct sdhci_host *host); + void (*dump_uhs2_regs)(struct sdhci_host *host); }; =20 #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.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 CC01D1D88A5; Fri, 13 Sep 2024 10:29:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223374; cv=none; b=qVgnip81JXUvC5unPhG56Eo2EPWoITYC/gzR9cGc6ox2OzsPeqA01PdorOR4PSgFUNIe3K4grGtGYq5vBU5dOW1GiRbVEnvNgXMsZkVJdp3DeAZx8LJOS+rDyGfnEk59EqlgyvikjfauqF1oy5sASNVUzYdCCzjnTyPHqtrRWoY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223374; c=relaxed/simple; bh=CdA3SI06ubeqqm9CRejDKr9MVIb3Sm3bm+DpHuLlSdk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=qAG96JkeKUsDQnqNX6li++uiAao+lZrnDFazb8nVAG/hJIcjNIBVYIFWhsxZ1Tt4nWxtAKMvsjAOPv+eSn8LiOfeBs3fHZZdfSVSoKb2KYu5n36sBuj+tqazebP7QVjFXhK4XUwQMoVnu1ljHu5jARZmbpK6STVvV8IT82eidTo= 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=NztmgmO5; arc=none smtp.client-ip=209.85.215.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="NztmgmO5" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-7c6b4222fe3so1287323a12.3; Fri, 13 Sep 2024 03:29:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223372; x=1726828172; 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=tpaYtlLd3mQ+A9z10aDKxE+hmD+tiwgrXgbBd5u7JA4=; b=NztmgmO5detAdMVa8QbDWShVj3dN4ktpI0Syi22dmpAnK6FenDU3/Lm+xz4msOzeKO U00iTl0Vl5Ujokb03WzDwjYbW/e0xGcwyqMpPrHpE2fAtAfgvDZJpnKP/vWwXuLNy5A2 2PvP8mGJuFIE2SdGoS1igdjbSgDnFny7v52ygQ32dH2nAxaxhzoZ4PntQpxAQgPiz1oV LECQpJJoevF1UFiylpNiX1bMMFSF0zQ5RKvPxw8pKx9lOZy/6oWmBgdVLYPsOijIcFtD SrA9EUfxp9QG97Nv3wkc3HkI717JDzZW/M8+6cwLdPvfZ5IVQHpxRtCPTEPuT515MSt3 VDGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223372; x=1726828172; 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=tpaYtlLd3mQ+A9z10aDKxE+hmD+tiwgrXgbBd5u7JA4=; b=CmQfW9fyu6uDGV+bazkEp5VP+R4gn3xo9oeC4kTN4BZcXiwcEL9Ei2RjzJj4owgKr6 vRz/njOw/FqeslCHXoeiZbPw6NYZ5jIq97eRL4iW05sAe0W1uosdTf+Po26DzXeYwfC0 1OvaoKasu+Bt/siEa3kekc9Et1QEgZrzCY5fXeaZQ337e3NPqmOIf+jvc8Gn1k7K7vmt K/PCgv2+vqngFudEE3MezRU7TFGCxQ61YR1bdI3DUhkKCCA07uUWKHQ187cv9ixnL3rF epgsfvh5Np/atd8KHfvfmdq5TO6YsHl512IQePFRyW/PNzg2CZ+7L6wRBkOTfy6acIuA QYVQ== X-Forwarded-Encrypted: i=1; AJvYcCXMJoHpLebYPepsWL8RiQ8/4s8PiQH/zCr5QJ0agFNYKVAf1qfxKLUhs3rdF3o5GarKS7S7DrqLwcQ/eWc=@vger.kernel.org X-Gm-Message-State: AOJu0Yy3B0upL5OG4Co2GZJSIM4UQys2ocvj3lAhK4rOsV4qH3tyRgKo uIEfc9N3HhwKcUNhmNXrHkuLpGNQInFG6IVxx3b4NBxHav/UjAu0 X-Google-Smtp-Source: AGHT+IEX9bEXtXQssY/4gcsnjdhpsxIGNHx+af2LsZULDcnkegPgwYTY88BJ288Gia0noSgq/gB0LQ== X-Received: by 2002:a05:6a21:9d91:b0:1cf:2931:727b with SMTP id adf61e73a8af0-1cf761e5546mr7707540637.31.1726223371876; Fri, 13 Sep 2024 03:29:31 -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.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:29:31 -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 11/22] mmc: sdhci-uhs2: add reset function Date: Fri, 13 Sep 2024 18:28:25 +0800 Message-Id: <20240913102836.6144-12-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 Sdhci_uhs2_reset() does a UHS-II specific reset operation. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- Updates in V17: - Move the sdhci_uhs2_reset_cmd_data() to the other patch it was used for the first time. Updates in V16: - Add sdhci_uhs2_reset_cmd_data() function. Updates in V15: - Refer the SD Host Controller Standard Specification Section 3.10 to add reset command data mechanism. Updates in V14: - Since mmc_card_uhs2() is the same as sdhci_uhs2_mode(), so drop sdhci_uhs2_mode() and use mmc_card_uhs2() instead of sdhci_uhs2_mode(). Updates in V13: - Use ios timing to stead MMC_UHS2_SUPPORT for indicate the UHS2 mode. Updates in V8: - Adjust the position of matching brackets. Updates in V6: - Remove unnecessary functions and simplify code. --- drivers/mmc/host/sdhci-uhs2.c | 37 +++++++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci-uhs2.h | 1 + 2 files changed, 38 insertions(+) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index 14514710e763..71c60952a40a 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -10,7 +10,9 @@ * Author: AKASHI Takahiro */ =20 +#include #include +#include =20 #include "sdhci.h" #include "sdhci-uhs2.h" @@ -21,6 +23,8 @@ #define SDHCI_UHS2_DUMP(f, x...) \ pr_err("%s: " DRIVER_NAME ": " f, mmc_hostname(host->mmc), ## x) =20 +#define UHS2_RESET_TIMEOUT_100MS 100000 + void sdhci_uhs2_dump_regs(struct sdhci_host *host) { if (!(mmc_card_uhs2(host->mmc))) @@ -49,6 +53,39 @@ void sdhci_uhs2_dump_regs(struct sdhci_host *host) } EXPORT_SYMBOL_GPL(sdhci_uhs2_dump_regs); =20 +/*************************************************************************= ****\ + * = * + * Low level functions = * + * = * +\*************************************************************************= ****/ + +/** + * sdhci_uhs2_reset - invoke SW reset + * @host: SDHCI host + * @mask: Control mask + * + * Invoke SW reset, depending on a bit in @mask and wait for completion. + */ +void sdhci_uhs2_reset(struct sdhci_host *host, u16 mask) +{ + u32 val; + + sdhci_writew(host, mask, SDHCI_UHS2_SW_RESET); + + if (mask & SDHCI_UHS2_SW_RESET_FULL) + host->clock =3D 0; + + /* hw clears the bit when it's done */ + if (read_poll_timeout_atomic(sdhci_readw, val, !(val & mask), 10, + UHS2_RESET_TIMEOUT_100MS, true, host, SDHCI_UHS2_SW_RESET)) { + pr_warn("%s: %s: Reset 0x%x never completed. %s: clean reset bit.\n", __= func__, + mmc_hostname(host->mmc), (int)mask, mmc_hostname(host->mmc)); + sdhci_writeb(host, 0, SDHCI_UHS2_SW_RESET); + return; + } +} +EXPORT_SYMBOL_GPL(sdhci_uhs2_reset); + /*************************************************************************= ****\ * = * * Driver init/exit = * diff --git a/drivers/mmc/host/sdhci-uhs2.h b/drivers/mmc/host/sdhci-uhs2.h index 2bfe18d29bca..caaf9fba4975 100644 --- a/drivers/mmc/host/sdhci-uhs2.h +++ b/drivers/mmc/host/sdhci-uhs2.h @@ -177,5 +177,6 @@ struct sdhci_host; =20 void sdhci_uhs2_dump_regs(struct sdhci_host *host); +void sdhci_uhs2_reset(struct sdhci_host *host, u16 mask); =20 #endif /* __SDHCI_UHS2_H */ --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pg1-f170.google.com (mail-pg1-f170.google.com [209.85.215.170]) (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 1691A1DB555; Fri, 13 Sep 2024 10:29:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.170 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223378; cv=none; b=H0N1qtaPedpVtxsWELdXky4nlOgroM4s9yZ1YAiGeGpAn8C399zT+FVzvb0iL6NG9U/MyHkZ8F3LnCn5jMyGsqq0hhry977Zv5z85WXEc2ruRkj3jIIZNb+UVweO4en9kKSNrMC4p9/ZSvuEVCZOH0LPfOYM/doT+/+3lc9cPoA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223378; c=relaxed/simple; bh=fQDWYr+jQmoqQTUgp8mWV6Y4NfpYcaQOSSQVxtmALkc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=jOBeFMvJmGhZ3EinLtYD5qqLtt5EKzY+cuKh2hTgiD9nSPyg85rYLLYpCbgBt8L3UanrP4znNiUhyEwnvcG0SLENJhcl2sGmzOvv+GB+EU/B8DJUxnjl830v4n05CoM9bNSh44CwmZNlEvH5JeWGpuNCZirACC25UVT8R8MC7iM= 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=GrOox6e3; arc=none smtp.client-ip=209.85.215.170 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="GrOox6e3" Received: by mail-pg1-f170.google.com with SMTP id 41be03b00d2f7-7d4fa972cbeso1623112a12.2; Fri, 13 Sep 2024 03:29:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223376; x=1726828176; 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=KkFVFuS/YN350pgqfr+BTG2ZvmKtP6VzC+KxRi2hVRs=; b=GrOox6e3V4+XBqlZZPZigD58LuUoNESQgs3m6bE/ERJy9swas3fqZZCheIsJ+bq8pW 3FybEHAKbnJFsAx/yuVD2JgJ1SxEeoARrbx4JItu4zu1TbqkPtBksQNLfbIyc1QFMOnm kzgrdtkpHN4D29b0QjyzSQo1WWjaS53o5aVLYU8x08QAcHNHKT6uIFj3BYzHkX5LP+s2 +Cp5F+9TBVrUulMOhxIgsyPUNDgemgPmRZESaVqeD1AIiPrUuFvGCv+GvcHm8iD6Jmn+ 5MtNQ3DZY0d4eO2ZqwC2Wlm1Ut25kXS6LDSLyF1pSkxo7XquBZg2B3OyiL8GXFdRBLay MVqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223376; x=1726828176; 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=KkFVFuS/YN350pgqfr+BTG2ZvmKtP6VzC+KxRi2hVRs=; b=uj1jfik3hbFsFGuQC+Q+jAALqU0+yV/uCrwiBmZdqRD6YlD/lm1rHQey8LSa+v4khL NQL4DS6SX2jMWT2MyPEiTb0cIX3TmaAb671d3I7CYym0DAOO74rcg+8YgYVq4umXQ8T5 aVZqXmM9XwcloOSGjRxMB5XMcbXPIXztoWadfOp60AMCaX4XCsS1oFOl3/iHTGmI5gD8 /zghJCO3nzojGyV9lEyVqhH0AdrH+DEVRnVEM5nP6aud+43vnVcxJjsYwmE2cNSm5BWC yNfN+Amzmx8hjzvphpKZdUgaq3XhFIRVGqmweJ3jOUFawR/zHLr8XAsRi0CUh+ZLVJvh zKrQ== X-Forwarded-Encrypted: i=1; AJvYcCW9DgCXsWkYDU3trHobkKt33pFCT6N8WT6volCj0XrILsbjfJyGeGilLmBv0JJ4teX3PKhchilxN3z8Mn0=@vger.kernel.org X-Gm-Message-State: AOJu0YyNBisM8CH/Sjzm8VjdFSpB39DJfwuzBoxLdDGDqxhQu7SD0ilI 3dxR/nC1mBG+ubLpUgBojG67E7pTgdz1vOP6YtTXsnmGSdeMhRjh X-Google-Smtp-Source: AGHT+IFLxNRIw6AcvJEMd3FlZaxIN2Iu8xBbjog7G8aYkEfsQB7BSMwZ0gBhXPjHOLFPydsLUAEO1Q== X-Received: by 2002:a05:6a21:398b:b0:1cf:658e:50fe with SMTP id adf61e73a8af0-1cf75efe88dmr7252847637.29.1726223376391; Fri, 13 Sep 2024 03:29:36 -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.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:29:36 -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 12/22] mmc: sdhci-uhs2: add set_power() to support vdd2 Date: Fri, 13 Sep 2024 18:28:26 +0800 Message-Id: <20240913102836.6144-13-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 UHS-II version of sdhci's set_power operation. Use sdhci_uhs2_set_power() to set VDD2 for support UHS2 interface. VDD2, as well as VDD, is handled here. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- Updates in V17: - Export sdhci_uhs2_set_power() function. Updates in V13: - Drop use vmmc2. - Modify comment message. Updates in V10: - Move some definitions of PatchV9[05/23] to PatchV10[11/23]. Updates in V9: - Modify annotations in sdhci_get_vdd_value(). Updates in V8: - Adjust the position of matching brackets. - Add the initial value of the pwr in sdhci_uhs2_set_power(). Updates in V7: - Add clear the power reg before setting a new value in sdhci_uhs2_set_power(). - Add MMC_VDD_34_35 case and MMC_VDD_35_36 case in sdhci_get_vdd_value(). - Drop pwr variable in sdhci_get_vdd_value(). Updates in V6: - Add mmc_opt_regulator_set_ocr(). - Remove unnecessary functions. --- drivers/mmc/host/sdhci-uhs2.c | 49 ++++++++++++++++++++++++++++ drivers/mmc/host/sdhci-uhs2.h | 1 + drivers/mmc/host/sdhci.c | 61 +++++++++++++++++++---------------- drivers/mmc/host/sdhci.h | 1 + 4 files changed, 84 insertions(+), 28 deletions(-) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index 71c60952a40a..756e44d84b87 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -59,6 +59,13 @@ EXPORT_SYMBOL_GPL(sdhci_uhs2_dump_regs); * = * \*************************************************************************= ****/ =20 +static inline int mmc_opt_regulator_set_ocr(struct mmc_host *mmc, + struct regulator *supply, + unsigned short vdd_bit) +{ + return IS_ERR_OR_NULL(supply) ? 0 : mmc_regulator_set_ocr(mmc, supply, vd= d_bit); +} + /** * sdhci_uhs2_reset - invoke SW reset * @host: SDHCI host @@ -86,6 +93,48 @@ void sdhci_uhs2_reset(struct sdhci_host *host, u16 mask) } EXPORT_SYMBOL_GPL(sdhci_uhs2_reset); =20 +void sdhci_uhs2_set_power(struct sdhci_host *host, unsigned char mode, uns= igned short vdd) +{ + struct mmc_host *mmc =3D host->mmc; + u8 pwr =3D 0; + + if (mode !=3D MMC_POWER_OFF) { + pwr =3D sdhci_get_vdd_value(vdd); + if (!pwr) + WARN(1, "%s: Invalid vdd %#x\n", + mmc_hostname(host->mmc), vdd); + pwr |=3D SDHCI_VDD2_POWER_180; + } + + if (host->pwr =3D=3D pwr) + return; + host->pwr =3D pwr; + + if (pwr =3D=3D 0) { + sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); + + mmc_opt_regulator_set_ocr(mmc, mmc->supply.vmmc, 0); + mmc_regulator_set_vqmmc2(mmc, &mmc->ios); + } else { + mmc_opt_regulator_set_ocr(mmc, mmc->supply.vmmc, vdd); + /* support 1.8v only for now */ + mmc_regulator_set_vqmmc2(mmc, &mmc->ios); + + /* Clear the power reg before setting a new value */ + sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); + + /* vdd first */ + pwr |=3D SDHCI_POWER_ON; + sdhci_writeb(host, pwr & 0xf, SDHCI_POWER_CONTROL); + mdelay(5); + + pwr |=3D SDHCI_VDD2_POWER_ON; + sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); + mdelay(5); + } +} +EXPORT_SYMBOL_GPL(sdhci_uhs2_set_power); + /*************************************************************************= ****\ * = * * Driver init/exit = * diff --git a/drivers/mmc/host/sdhci-uhs2.h b/drivers/mmc/host/sdhci-uhs2.h index caaf9fba4975..3efa8dd690bf 100644 --- a/drivers/mmc/host/sdhci-uhs2.h +++ b/drivers/mmc/host/sdhci-uhs2.h @@ -178,5 +178,6 @@ struct sdhci_host; =20 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); =20 #endif /* __SDHCI_UHS2_H */ diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 5a5fe3528bb4..366c3d30dba6 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -23,7 +23,7 @@ #include #include #include - +#include #include =20 #include @@ -2061,41 +2061,46 @@ static void sdhci_set_power_reg(struct sdhci_host *= host, unsigned char mode, sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); } =20 +unsigned short sdhci_get_vdd_value(unsigned short vdd) +{ + switch (1 << vdd) { + case MMC_VDD_165_195: + /* + * Without a regulator, SDHCI does not support 2.0v + * so we only get here if the driver deliberately + * added the 2.0v range to ocr_avail. Map it to 1.8v + * for the purpose of turning on the power. + */ + case MMC_VDD_20_21: + return SDHCI_POWER_180; + case MMC_VDD_29_30: + case MMC_VDD_30_31: + return SDHCI_POWER_300; + case MMC_VDD_32_33: + case MMC_VDD_33_34: + /* + * 3.4V ~ 3.6V are valid only for those platforms where it's + * known that the voltage range is supported by hardware. + */ + case MMC_VDD_34_35: + case MMC_VDD_35_36: + return SDHCI_POWER_330; + default: + return 0; + } +} +EXPORT_SYMBOL_GPL(sdhci_get_vdd_value); + void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode, unsigned short vdd) { u8 pwr =3D 0; =20 if (mode !=3D MMC_POWER_OFF) { - switch (1 << vdd) { - case MMC_VDD_165_195: - /* - * Without a regulator, SDHCI does not support 2.0v - * so we only get here if the driver deliberately - * added the 2.0v range to ocr_avail. Map it to 1.8v - * for the purpose of turning on the power. - */ - case MMC_VDD_20_21: - pwr =3D SDHCI_POWER_180; - break; - case MMC_VDD_29_30: - case MMC_VDD_30_31: - pwr =3D SDHCI_POWER_300; - break; - case MMC_VDD_32_33: - case MMC_VDD_33_34: - /* - * 3.4 ~ 3.6V are valid only for those platforms where it's - * known that the voltage range is supported by hardware. - */ - case MMC_VDD_34_35: - case MMC_VDD_35_36: - pwr =3D SDHCI_POWER_330; - break; - default: + pwr =3D sdhci_get_vdd_value(vdd); + if (!pwr) { WARN(1, "%s: Invalid vdd %#x\n", mmc_hostname(host->mmc), vdd); - break; } } =20 diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index 66ab90bd4017..0f78708d0c70 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -836,6 +836,7 @@ void sdhci_set_power(struct sdhci_host *host, unsigned = char mode, void sdhci_set_power_and_bus_voltage(struct sdhci_host *host, unsigned char mode, unsigned short vdd); +unsigned short sdhci_get_vdd_value(unsigned short vdd); void sdhci_set_power_noreg(struct sdhci_host *host, unsigned char mode, unsigned short vdd); int sdhci_get_cd_nogpio(struct mmc_host *mmc); --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 804821DB92A; Fri, 13 Sep 2024 10:29:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223382; cv=none; b=p1sGZT9kgQ2e9uHrJwrgbRSxYaVWamzK6Mzzm5ZagDyumM86Usxs22+RiaIDhgFXq0/E41EegOk9NQa5KzsHq+kdopJf0YwFzc0U+W/H3LqLiddoPqBQPwvKSVh/Wsy8wbdZcak0KCewmpJ/SmT6zGDRQohXhJOkzwY2OO4bdNs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223382; c=relaxed/simple; bh=VB5pAfZlY5yWHbxrV1VvySF25vuCBwsa2Yimme8Jx9w=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=QJCDq1o7ucDyKYBdiTMVAits3WqGgi0/O5ZAmxo8PK+jDN81wnjjD/3eqURNlu970f0hsn9A3FxXvPCuxakbhg5ak9PkWysXVo98dx0TiBWzyPdXNVCSsrWX8zcYxpsTFsuq0gnFxtSJVVpYlLI/zwpHK8AmhQfKPQHB4hAz4w8= 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=ScFmvSnr; arc=none smtp.client-ip=209.85.210.171 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="ScFmvSnr" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-7191f58054aso1713698b3a.0; Fri, 13 Sep 2024 03:29:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223381; x=1726828181; 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=hGS5FnAtxOoJb/6wOxS2ea2cNEevmIiG+LI1be0l3jU=; b=ScFmvSnr44agjJzdgh82SqZtlp43XkFJ7MQa6QNRsSH8b4EzmgxWmCqLN5H2dL28q8 GXDu3SmzDpeuLlCEnsXoMMcqOr4DL2URhmVhP1AWYJfgpUS+bwepP1w5SMrZhEE8v686 ip9jpFerCRWmbGZWPRz/LqEuQMs/gSGvyhYNBHaX5+nLWIZKDDJU9vngY4ERr/JDWSbC h3AEt7z401kFkyVhbKgh52sPXUZeY1s5tBkorE3+xOx6K7n6aE+G/WMds7DvFx6PjBas H3YhwXaU3myOYl0aNDk5ZrINxoedO/1OlNYm9IPg4VNrNUQ/qdcDZll5E5cSsyAzzGp5 C5Cw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223381; x=1726828181; 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=hGS5FnAtxOoJb/6wOxS2ea2cNEevmIiG+LI1be0l3jU=; b=tKM8XbqQRCgahYGhKKE0O78LXloqHkQqEP5E5qde3qmcrp8iV8Z6+juFpXA9lB+ULK cH0Tn1jGLFtFz8ofNncL5bzL7BO2ja7b2eaYcXi0DMurCQuytyaz5dcSpdTqMKDfqthy PiCLerdNDVNELMYXJh79viu4gXMHbv8zWKv6EG32DusXHLO88UGpoUC9Z+/vQUV7ooZz HNQ5P7DtWgsgoRLKtlMPStX1BFRANlIDuPRSVT+oj4pstDXbzMWnMnfgErtg76Fy9eS8 ZgoD9pKGprdfDpXFLsG6IBwAdR2qTaC57nq+Kt0XU83buKYeeWQKH7RkX8mTuSznw8Yh BcBQ== X-Forwarded-Encrypted: i=1; AJvYcCWAaoRVI1PrvkJTyhf1poqiI+vGV+uwFpJpvaEHts3wViNVaPNgWtleMT1TtShplXo5ZeLl714Lo+jkcL8=@vger.kernel.org X-Gm-Message-State: AOJu0YxaQ3zkglWrRnbFrRcG+xWAY6OWDrLady0a09chsjkuEq1A3LAn aSgLtNdn3PQ0SH32Q7DCMbRKYnMwz0QMCYkdXR+qS9o2VxpZKTuF X-Google-Smtp-Source: AGHT+IGOIhlMK21wDG7gfBh7xJ29q0pemK22aSonTKBmCiY5Rke4XQnf2glORp9FkqlC/OSyMafqjQ== X-Received: by 2002:a05:6a21:9206:b0:1be:c3c1:7be8 with SMTP id adf61e73a8af0-1cf75f3b4bcmr7262126637.26.1726223380696; Fri, 13 Sep 2024 03:29:40 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:29:40 -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 13/22] mmc: sdhci-uhs2: add set_timeout() Date: Fri, 13 Sep 2024 18:28:27 +0800 Message-Id: <20240913102836.6144-14-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 UHS-II version of sdhci's set_timeout() operation. Use sdhci_uhs2_set_timeout() to set and calculate the timeout time. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- Updates in V14: - Use mmc_card_uhs2() to stead sdhci_uhs2_mode() in the sdhci_uhs2_set_timeout(). Updates in V13: - Modify comment message. Updates in V8: - Initialization be combined with declaration and realigned in sdhci_calc_timeout_uhs2(). - Forward declare struct mmc_command in sdhci_uhs2.h. Updates in V6: - Use GENMASK() and FIELD_PREP() in some case. - Use sdhci_uhs2_mode() to simplify code. - Remove unnecessary functions. --- drivers/mmc/host/sdhci-uhs2.c | 72 +++++++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci-uhs2.h | 2 + 2 files changed, 74 insertions(+) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index 756e44d84b87..6b249eb8395a 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -13,6 +13,7 @@ #include #include #include +#include =20 #include "sdhci.h" #include "sdhci-uhs2.h" @@ -135,6 +136,77 @@ void sdhci_uhs2_set_power(struct sdhci_host *host, uns= igned char mode, unsigned } EXPORT_SYMBOL_GPL(sdhci_uhs2_set_power); =20 +static u8 sdhci_calc_timeout_uhs2(struct sdhci_host *host, u8 *cmd_res, u8= *dead_lock) +{ + /* timeout in us */ + unsigned int dead_lock_timeout =3D 1 * 1000 * 1000; + unsigned int cmd_res_timeout =3D 5 * 1000; + unsigned int current_timeout; + u8 count; + + /* + * Figure out needed cycles. + * We do this in steps in order to fit inside a 32 bit int. + * The first step is the minimum timeout, which will have a + * minimum resolution of 6 bits: + * (1) 2^13*1000 > 2^22, + * (2) host->timeout_clk < 2^16 + * =3D> + * (1) / (2) > 2^6 + */ + count =3D 0; + current_timeout =3D (1 << 13) * 1000 / host->timeout_clk; + while (current_timeout < cmd_res_timeout) { + count++; + current_timeout <<=3D 1; + if (count >=3D 0xF) + break; + } + + if (count >=3D 0xF) { + DBG("%s: Too large timeout 0x%x requested for CMD_RES!\n", + mmc_hostname(host->mmc), count); + count =3D 0xE; + } + *cmd_res =3D count; + + count =3D 0; + current_timeout =3D (1 << 13) * 1000 / host->timeout_clk; + while (current_timeout < dead_lock_timeout) { + count++; + current_timeout <<=3D 1; + if (count >=3D 0xF) + break; + } + + if (count >=3D 0xF) { + DBG("%s: Too large timeout 0x%x requested for DEADLOCK!\n", + mmc_hostname(host->mmc), count); + count =3D 0xE; + } + *dead_lock =3D count; + + return count; +} + +static void __sdhci_uhs2_set_timeout(struct sdhci_host *host) +{ + u8 cmd_res, dead_lock; + + sdhci_calc_timeout_uhs2(host, &cmd_res, &dead_lock); + cmd_res |=3D FIELD_PREP(SDHCI_UHS2_TIMER_CTRL_DEADLOCK_MASK, dead_lock); + sdhci_writeb(host, cmd_res, SDHCI_UHS2_TIMER_CTRL); +} + +void sdhci_uhs2_set_timeout(struct sdhci_host *host, struct mmc_command *c= md) +{ + __sdhci_set_timeout(host, cmd); + + if (mmc_card_uhs2(host->mmc)) + __sdhci_uhs2_set_timeout(host); +} +EXPORT_SYMBOL_GPL(sdhci_uhs2_set_timeout); + /*************************************************************************= ****\ * = * * Driver init/exit = * diff --git a/drivers/mmc/host/sdhci-uhs2.h b/drivers/mmc/host/sdhci-uhs2.h index 3efa8dd690bf..9bd3f610cf8c 100644 --- a/drivers/mmc/host/sdhci-uhs2.h +++ b/drivers/mmc/host/sdhci-uhs2.h @@ -175,9 +175,11 @@ #define SDHCI_UHS2_VENDOR_PTR 0xE8 =20 struct sdhci_host; +struct mmc_command; =20 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); =20 #endif /* __SDHCI_UHS2_H */ --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 670BF1DB940; Fri, 13 Sep 2024 10:29:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223386; cv=none; b=SHufaLR+ZUwL+/cbHADBwNHixSxjLEBzOE84NkF9oCene0iIOakVBCVISV87aT8Sl1bLzFmlzLeJotTCwN4DGn5P/0RGZswoRpNXrdlfHOzVKZkWvseqmEglQLvZb2238krm2TzVzkWQrHizvZ5XEpLWWw3WVcAFJyZ/KD1cQ8E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223386; c=relaxed/simple; bh=YFLqV890Z42BNuleGy/377WU3cFQMODtUvsZxEvUggE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=tzFmZYep0+FiYzuGL3gLL/I2538hGVIUpgzWxtqfpAPOLrUq9kSYusPdJdiEVt7jIz9NKaTZG/xeFGQLJsFn8p1BVGt0rKV1zWBNfpcxZVaKlGDoY1l5+iX0tXQTlPD+IciXmKRhfhOKVE5yR+119LDhHKiWuqPO57uVi+iMsps= 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=cBZvyHKs; arc=none smtp.client-ip=209.85.214.175 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="cBZvyHKs" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2055a3f80a4so14085855ad.2; Fri, 13 Sep 2024 03:29:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223385; x=1726828185; 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=cBZvyHKsvfnn22Fg+krf0umqJim/e4hvoa/W9hNV3rCSsLHJWuyjn+lceAL32c4a+j njTlJf+7JpCxB8dwnurJnazbZHWiQ17SlAI8oMB4/raRF7T5QMBm4fYv/KYmYfX2tRuk JDK1GjIBj8XrqBGBgINEM1gP1TLcw9VzN8fQMOwgW65tNUgrVBPdDqpzncoBEK8IvduI 3S/mYDHDhNKcWOWchLHOd+K/rCHigYB/dhnELKP6gTam/FC+1k5m9EQoQvAD2Z1g4EIy cF+gKGukoO3MEK5oq8mp+50iHpPH2W+864UigYRNkw55ABSEORkKUZP9TSnKEbzf7e+Z PIlQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223385; x=1726828185; 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=px5S5/B+1+TJFOiL/mlRzBQwn6nqewW7ChZjsNRYoz/xh2ccFrdYZL8wOE6ctlF8do gxKs55q0rpoTXMM4wlgosvexy1IcHY92m652tGNF84xpte6QLujut11cJQzJUzqaGYV1 sl9/xBJ+bP7c5B6KNCUlSAnLw3xiGMSsS2KZdTot+rECQgIuXeum3JCjmbMDVhermBlj odsTVG5qVsJ8YYAF8ikayvaKgWysoTO1bmfoxWWZ5hJ8o1LJPjdWwhpSmAkhKT/66pkt ZUfzYt9Uf+qrmVamgndTlynv+PY+GbyiWosGINLGrGlSaEzHhP/Go2pjwFvVcPQYUKPD KsEA== X-Forwarded-Encrypted: i=1; AJvYcCWyBcQBH/n3bioSKM3ztZA7hhnT1s+pLCC3bfttt1/qUgaVlQT4Comh4MsNQI6pcApgePNv2Pn0e7wfBbc=@vger.kernel.org X-Gm-Message-State: AOJu0YwPF960asAGglCQnNqsIe5Dc5/lSLXReOzuEPbzv4Bnnk5h08p7 RVrXGBw2w1KoalaovUWoI5a1BG8sVESQtGEgdB7y6eXmsLnpjWZp X-Google-Smtp-Source: AGHT+IFDo86Kh1wDO0Bi76s7UcJVHrghgeRC5dZI/qG07qNoZ96ObwxowNSojYoSUM9scAV4D021Rw== X-Received: by 2002:a17:903:18b:b0:202:301f:36fd with SMTP id d9443c01a7336-2076e361277mr80818475ad.18.1726223384696; Fri, 13 Sep 2024 03:29:44 -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.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:29:44 -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 14/22] mmc: sdhci-uhs2: add add_host() and others to set up the driver Date: Fri, 13 Sep 2024 18:28:28 +0800 Message-Id: <20240913102836.6144-15-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 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 Acked-by: Adrian Hunter --- 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 From nobody Fri Nov 29 23:36:22 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 Acked-by: Adrian Hunter --- 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 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pg1-f173.google.com (mail-pg1-f173.google.com [209.85.215.173]) (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 15A971D7E52; Fri, 13 Sep 2024 10:29:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223396; cv=none; b=hxpfVOcaKZrZq6GwUX7zFlZ/XWKVUKblyDQk+RUPLEz1ToosSHJPibar6UQAUDNYGob/fWyYtCgZrA2cGd7puDHl7+nDBERvLc+GPj565z9V+L5hb7Ezs6G2Y9yJOrMQ92pjhIHsZbsgMmjgHygWFFZ6CWqV54LQ1ZN6PGoljCw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223396; c=relaxed/simple; bh=Yf9c/+P80QvztzSDSZc5+mOLmfL0EsrfDRKcNyiiles=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=uPkW3qhQSs1/IOHAEH2rx/rtK6UDAZnoZYqo+gjleeU2CqaQtRpFYF5N3ldgjK0nX81orHQAt6AM+ktHWeHYQOizIV18Icgq00hDrdTBxpNIK4WyKFCnhVuP8BgcComHUleUtBe0C9B079Bm8EDKRsIAvGXVW4JrggbeXa5pTY4= 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=fbAzN/3a; arc=none smtp.client-ip=209.85.215.173 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="fbAzN/3a" Received: by mail-pg1-f173.google.com with SMTP id 41be03b00d2f7-7d4f85766f0so1723367a12.2; Fri, 13 Sep 2024 03:29:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223394; x=1726828194; 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=MRafvWR7zGbZF3TAjHo6lxtfuVouUGY2HW+1bCf77G0=; b=fbAzN/3aeCy2KlMzTqMaaoUIz5QTgUa8ZggybgrcCKAxyM8ZnHgs7otQzYIq/F/jMq WICTO5B0ChaDjLnrZRHiiERlGLTVQSJreSIyhWktEK5u1oOoNmyDis1FfnP8J7WpDLp/ 3HQztqRYTJ7cObnX5z1IaHVKbdrhSJA2rhtWWnA6ja3m5xpFgv6QpD9TDuHLS8pN2WCI 5dfxLKvfJ5TVCg65TNt+TyRX2hZn4fFC7379Ei6JjiHsjB3cAa2QI6YaaaF5lWB5fKyb je6ePlnOkFrbSHf8gvIQ9M6w7Jkb3Z5kjx7Ql/m3R0MKc4RYA/ssdmfblxhL5hM6anNv HJGw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223394; x=1726828194; 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=MRafvWR7zGbZF3TAjHo6lxtfuVouUGY2HW+1bCf77G0=; b=obECjshe/PkW+CfAxMFxqARpAxv/HvdYq+XttPSPQTKavUJECKxPN63DoPjDS77lfA CUBSzEMTfKNSYQg3x7FxXf48ydDTa2nxLrX9XcjYGpMEu6V+lsQGP+VJ4Z925nzkL47x +ZUfqCoIRPfqCoFY2ecILgmbPGy/CvM9h0uuo3k1E8ZpYdDARGxy59gzcJW3mwI58FqD nvA861uHQLGfwr67c+ntc6Kg2Im1qzrXrZ+fd3d/gKty6qfOwlJp1bbMeJiE3H+u3y+y YzGTeWsOamoVmt8qLVoy+MIt2yX7PQB42UquAvp7N9gdvf9kpseHr08RONagx+tezvm4 Na2A== X-Forwarded-Encrypted: i=1; AJvYcCXTysN5LihUo6GOlsM9jYi15yygHP7GmdQuCb+sUfBKPSuXJP/8DW0jP3EgEMWpFTUVQCErpS0nN9QKexU=@vger.kernel.org X-Gm-Message-State: AOJu0Yz11G4t7VVzPRCE8F3oF5XJ6T/4KkfhOMry8IVR1j1d8bqxzqKL X4NIXWrxIT7XojehIE7J8RPlROdPHdO8n9xvdukWk/r0esYvnG/NVRYTb7kz X-Google-Smtp-Source: AGHT+IFCWXc6iSi4oRGtGNsPJzrhA7Kh+5tIZ0gXps1OjU3xrrUNTAqYD8ZezKnT1e1lPNUGyn5ONw== X-Received: by 2002:a05:6300:404c:b0:1cf:397f:b69 with SMTP id adf61e73a8af0-1cf75ee4c68mr8680295637.13.1726223394196; Fri, 13 Sep 2024 03:29:54 -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.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:29:53 -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 16/22] mmc: sdhci-uhs2: add related functions to initialize the interface Date: Fri, 13 Sep 2024 18:28:30 +0800 Message-Id: <20240913102836.6144-17-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 UHS-II interface (related registers) will be initialized here. The operations include mmc's uhs2_set_reg operations, mmc's uhs2_detect_init operations, uhs2_[enable|disable]_clk operations. After detected the UHS-II interface, the host's UHS-II capabilities will be= set up here and interrupts will also be enabled. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- Updates in V22: - Adjust the patch order from v21 patch#15 to v22 patch#16 and remove unnecessary code to avoid defined but not used warnings. - Modify commit message. Updates in V15: - Resolve merge conflicts and reduce unnecessary line breaks. Updates in V13: - Merge Patch#15, Patch#16 and Patch#17 of v12 version into Patch#15 in v1= 3 version. - Use definitions to simplify code. - Modify comment message. --- drivers/mmc/host/sdhci-uhs2.c | 204 ++++++++++++++++++++++++++++++++++ 1 file changed, 204 insertions(+) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index ee46dac891e5..94e041520a54 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -26,6 +26,9 @@ pr_err("%s: " DRIVER_NAME ": " f, mmc_hostname(host->mmc), ## x) =20 #define UHS2_RESET_TIMEOUT_100MS 100000 +#define UHS2_CHECK_DORMANT_TIMEOUT_100MS 100000 +#define UHS2_INTERFACE_DETECT_TIMEOUT_100MS 100000 +#define UHS2_LANE_SYNC_TIMEOUT_150MS 150000 =20 void sdhci_uhs2_dump_regs(struct sdhci_host *host) { @@ -303,6 +306,186 @@ static int sdhci_uhs2_set_ios(struct mmc_host *mmc, s= truct mmc_ios *ios) return 0; } =20 +static int sdhci_uhs2_interface_detect(struct sdhci_host *host) +{ + u32 val; + + if (read_poll_timeout(sdhci_readl, val, (val & SDHCI_UHS2_IF_DETECT), + 100, UHS2_INTERFACE_DETECT_TIMEOUT_100MS, true, + host, SDHCI_PRESENT_STATE)) { + pr_warn("%s: not detect UHS2 interface in 100ms.\n", mmc_hostname(host->= mmc)); + sdhci_dumpregs(host); + return -EIO; + } + + /* Enable UHS2 error interrupts */ + sdhci_uhs2_clear_set_irqs(host, SDHCI_INT_ALL_MASK, SDHCI_UHS2_INT_ERROR_= MASK); + + if (read_poll_timeout(sdhci_readl, val, (val & SDHCI_UHS2_LANE_SYNC), + 100, UHS2_LANE_SYNC_TIMEOUT_150MS, true, host, SDHCI_PRESENT_STAT= E)) { + pr_warn("%s: UHS2 Lane sync fail in 150ms.\n", mmc_hostname(host->mmc)); + sdhci_dumpregs(host); + return -EIO; + } + + DBG("%s: UHS2 Lane synchronized in UHS2 mode, PHY is initialized.\n", + mmc_hostname(host->mmc)); + return 0; +} + +static int sdhci_uhs2_init(struct sdhci_host *host) +{ + u16 caps_ptr =3D 0; + u32 caps_gen =3D 0; + u32 caps_phy =3D 0; + u32 caps_tran[2] =3D {0, 0}; + struct mmc_host *mmc =3D host->mmc; + + caps_ptr =3D sdhci_readw(host, SDHCI_UHS2_CAPS_PTR); + if (caps_ptr < 0x100 || caps_ptr > 0x1FF) { + pr_err("%s: SDHCI_UHS2_CAPS_PTR(%d) is wrong.\n", + mmc_hostname(mmc), caps_ptr); + return -ENODEV; + } + caps_gen =3D sdhci_readl(host, caps_ptr + SDHCI_UHS2_CAPS_OFFSET); + caps_phy =3D sdhci_readl(host, caps_ptr + SDHCI_UHS2_CAPS_PHY_OFFSET); + caps_tran[0] =3D sdhci_readl(host, caps_ptr + SDHCI_UHS2_CAPS_TRAN_OFFSET= ); + caps_tran[1] =3D sdhci_readl(host, caps_ptr + SDHCI_UHS2_CAPS_TRAN_1_OFFS= ET); + + /* General Caps */ + mmc->uhs2_caps.dap =3D caps_gen & SDHCI_UHS2_CAPS_DAP_MASK; + mmc->uhs2_caps.gap =3D FIELD_GET(SDHCI_UHS2_CAPS_GAP_MASK, caps_gen); + mmc->uhs2_caps.n_lanes =3D FIELD_GET(SDHCI_UHS2_CAPS_LANE_MASK, caps_gen); + mmc->uhs2_caps.addr64 =3D (caps_gen & SDHCI_UHS2_CAPS_ADDR_64) ? 1 : 0; + mmc->uhs2_caps.card_type =3D FIELD_GET(SDHCI_UHS2_CAPS_DEV_TYPE_MASK, cap= s_gen); + + /* PHY Caps */ + mmc->uhs2_caps.phy_rev =3D caps_phy & SDHCI_UHS2_CAPS_PHY_REV_MASK; + mmc->uhs2_caps.speed_range =3D FIELD_GET(SDHCI_UHS2_CAPS_PHY_RANGE_MASK, = caps_phy); + mmc->uhs2_caps.n_lss_sync =3D FIELD_GET(SDHCI_UHS2_CAPS_PHY_N_LSS_SYN_MAS= K, caps_phy); + mmc->uhs2_caps.n_lss_dir =3D FIELD_GET(SDHCI_UHS2_CAPS_PHY_N_LSS_DIR_MASK= , caps_phy); + if (mmc->uhs2_caps.n_lss_sync =3D=3D 0) + mmc->uhs2_caps.n_lss_sync =3D 16 << 2; + else + mmc->uhs2_caps.n_lss_sync <<=3D 2; + if (mmc->uhs2_caps.n_lss_dir =3D=3D 0) + mmc->uhs2_caps.n_lss_dir =3D 16 << 3; + else + mmc->uhs2_caps.n_lss_dir <<=3D 3; + + /* LINK/TRAN Caps */ + mmc->uhs2_caps.link_rev =3D caps_tran[0] & SDHCI_UHS2_CAPS_TRAN_LINK_REV_= MASK; + mmc->uhs2_caps.n_fcu =3D FIELD_GET(SDHCI_UHS2_CAPS_TRAN_N_FCU_MASK, caps_= tran[0]); + if (mmc->uhs2_caps.n_fcu =3D=3D 0) + mmc->uhs2_caps.n_fcu =3D 256; + mmc->uhs2_caps.host_type =3D FIELD_GET(SDHCI_UHS2_CAPS_TRAN_HOST_TYPE_MAS= K, caps_tran[0]); + mmc->uhs2_caps.maxblk_len =3D FIELD_GET(SDHCI_UHS2_CAPS_TRAN_BLK_LEN_MASK= , caps_tran[0]); + mmc->uhs2_caps.n_data_gap =3D caps_tran[1] & SDHCI_UHS2_CAPS_TRAN_1_N_DAT= A_GAP_MASK; + + return 0; +} + +static int sdhci_uhs2_do_detect_init(struct mmc_host *mmc) +{ + struct sdhci_host *host =3D mmc_priv(mmc); + + DBG("Begin do uhs2 detect init.\n"); + + if (sdhci_uhs2_interface_detect(host)) { + pr_warn("%s: cannot detect UHS2 interface.\n", mmc_hostname(host->mmc)); + return -EIO; + } + + if (sdhci_uhs2_init(host)) { + pr_warn("%s: UHS2 init fail.\n", mmc_hostname(host->mmc)); + return -EIO; + } + + /* Init complete, do soft reset and enable UHS2 error irqs. */ + sdhci_uhs2_reset(host, SDHCI_UHS2_SW_RESET_SD); + sdhci_uhs2_clear_set_irqs(host, SDHCI_INT_ALL_MASK, SDHCI_UHS2_INT_ERROR_= MASK); + /* + * N.B SDHCI_INT_ENABLE and SDHCI_SIGNAL_ENABLE was cleared + * by SDHCI_UHS2_SW_RESET_SD + */ + sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); + sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); + + return 0; +} + +static int sdhci_uhs2_disable_clk(struct mmc_host *mmc) +{ + struct sdhci_host *host =3D mmc_priv(mmc); + u16 clk =3D sdhci_readw(host, SDHCI_CLOCK_CONTROL); + + clk &=3D ~SDHCI_CLOCK_CARD_EN; + sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); + + return 0; +} + +static int sdhci_uhs2_enable_clk(struct mmc_host *mmc) +{ + struct sdhci_host *host =3D mmc_priv(mmc); + u16 clk =3D sdhci_readw(host, SDHCI_CLOCK_CONTROL); + int timeout_us =3D 20000; /* 20ms */ + u32 val; + + clk |=3D SDHCI_CLOCK_CARD_EN; + sdhci_writew(host, clk, SDHCI_CLOCK_CONTROL); + + if (read_poll_timeout(sdhci_readw, val, (val & SDHCI_CLOCK_INT_STABLE), + 10, timeout_us, true, host, SDHCI_CLOCK_CONTROL)) { + pr_err("%s: Internal clock never stabilised.\n", mmc_hostname(host->mmc)= ); + sdhci_dumpregs(host); + return -EIO; + } + return 0; +} + +static void sdhci_uhs2_set_config(struct sdhci_host *host) +{ + u32 value; + u16 sdhci_uhs2_set_ptr =3D sdhci_readw(host, SDHCI_UHS2_SETTINGS_PTR); + u16 sdhci_uhs2_gen_set_reg =3D sdhci_uhs2_set_ptr; + u16 sdhci_uhs2_phy_set_reg =3D sdhci_uhs2_set_ptr + 4; + u16 sdhci_uhs2_tran_set_reg =3D sdhci_uhs2_set_ptr + 8; + u16 sdhci_uhs2_tran_set_1_reg =3D sdhci_uhs2_set_ptr + 12; + + /* Set Gen Settings */ + value =3D FIELD_PREP(SDHCI_UHS2_GEN_SETTINGS_N_LANES_MASK, host->mmc->uhs= 2_caps.n_lanes_set); + sdhci_writel(host, value, sdhci_uhs2_gen_set_reg); + + /* Set PHY Settings */ + value =3D FIELD_PREP(SDHCI_UHS2_PHY_N_LSS_DIR_MASK, host->mmc->uhs2_caps.= n_lss_dir_set) | + FIELD_PREP(SDHCI_UHS2_PHY_N_LSS_SYN_MASK, host->mmc->uhs2_caps.n_lss_syn= c_set); + if (host->mmc->ios.timing =3D=3D MMC_TIMING_UHS2_SPEED_B || + host->mmc->ios.timing =3D=3D MMC_TIMING_UHS2_SPEED_B_HD) + value |=3D SDHCI_UHS2_PHY_SET_SPEED_B; + sdhci_writel(host, value, sdhci_uhs2_phy_set_reg); + + /* Set LINK-TRAN Settings */ + value =3D FIELD_PREP(SDHCI_UHS2_TRAN_RETRY_CNT_MASK, host->mmc->uhs2_caps= .max_retry_set) | + FIELD_PREP(SDHCI_UHS2_TRAN_N_FCU_MASK, host->mmc->uhs2_caps.n_fcu_set); + sdhci_writel(host, value, sdhci_uhs2_tran_set_reg); + sdhci_writel(host, host->mmc->uhs2_caps.n_data_gap_set, sdhci_uhs2_tran_s= et_1_reg); +} + +static int sdhci_uhs2_check_dormant(struct sdhci_host *host) +{ + u32 val; + + if (read_poll_timeout(sdhci_readl, val, (val & SDHCI_UHS2_IN_DORMANT_STAT= E), + 100, UHS2_CHECK_DORMANT_TIMEOUT_100MS, true, host, + SDHCI_PRESENT_STATE)) { + pr_warn("%s: UHS2 IN_DORMANT fail in 100ms.\n", mmc_hostname(host->mmc)); + sdhci_dumpregs(host); + return -EIO; + } + return 0; +} + static int sdhci_uhs2_control(struct mmc_host *mmc, enum sd_uhs2_operation= op) { struct sdhci_host *host =3D mmc_priv(mmc); @@ -312,6 +495,27 @@ static int sdhci_uhs2_control(struct mmc_host *mmc, en= um sd_uhs2_operation op) DBG("Begin uhs2 control, act %d.\n", op); =20 switch (op) { + case UHS2_PHY_INIT: + err =3D sdhci_uhs2_do_detect_init(mmc); + break; + case UHS2_SET_CONFIG: + sdhci_uhs2_set_config(host); + break; + case UHS2_ENABLE_INT: + sdhci_uhs2_clear_set_irqs(host, 0, SDHCI_INT_CARD_INT); + break; + case UHS2_DISABLE_INT: + sdhci_uhs2_clear_set_irqs(host, SDHCI_INT_CARD_INT, 0); + break; + case UHS2_CHECK_DORMANT: + err =3D sdhci_uhs2_check_dormant(host); + break; + case UHS2_DISABLE_CLK: + err =3D sdhci_uhs2_disable_clk(mmc); + break; + case UHS2_ENABLE_CLK: + err =3D sdhci_uhs2_enable_clk(mmc); + break; case UHS2_SET_IOS: err =3D sdhci_uhs2_set_ios(mmc, ios); break; --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (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 45AA51DC185; Fri, 13 Sep 2024 10:29:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223401; cv=none; b=mK13j7IuvoQZGgn7N9Doqs1ShPOC1nxsc2lqHnCdj8x3YvBrWjB9qxu9cGKkhCtmQ7tserNju76AW84j0dMWDKOxSYzSVLgRRgs+pEuTN60qzBdOY91Aw/hOE32DN3pDqF2LRO0WC+FiyT1zhpPpaDBfg6L+/7iCi4a4kcEyMlw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223401; c=relaxed/simple; bh=B+Wa7oOAmDVkINnlgYIgH9NByleuifN/m1Jcx69l3vo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=kgwyO5dUr4ZE/iusJC9tzmLiFlsYz/h8d3KtSWeKwgzeAFonKi84aJOBLVkaaA9SJ1MLXVieVIW8Ml4dIMAwt+bI9Spj1Sbom5XPltpKbLWThmWQpP3+CkUB5EcgIfNkJsRQeNIDicB3oYT/69npn1Nq65lkt0bKHQpENDD0+tM= 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=XeEORWka; arc=none smtp.client-ip=209.85.215.177 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="XeEORWka" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-6e7b121be30so472342a12.1; Fri, 13 Sep 2024 03:29:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223399; x=1726828199; 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=2TktPzLzjI8Xc4Q60euNFMPr6whdPIGlEZYibsnuzdI=; b=XeEORWkafLU2yzMm9X/TntMOpd+wL5fBx4/n83GsoPPzWZDMEmZPVvDDerXo8dV+3M R1rB4ER2mG1hWqZCNpGuqvNq5aMlmT6UohLiezwps2PdCxYFHG2NnXH/jH7wkaatTRQ+ UpfBQdBwGo7PQQffhUgUN4nwfocDpwEIpcDYHZttHZ+8JwcF3ZcFuTzvZIqezNEFWztL QlPwHDsogZO9/THxwkcmNKzsP49qTRreIStVzVI3PyceoixzpFl3qyvBS1SmP/D/L/JR 0B1K1qY2LJ8LFbTEviDqZiLMLw6hYjYcm+l1p64YaMd0JURac4K1ZKBDSaTlPziX8QA4 EUZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223399; x=1726828199; 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=2TktPzLzjI8Xc4Q60euNFMPr6whdPIGlEZYibsnuzdI=; b=BJYyXed0sTSMrV4F+A57Nsz3C/Iegc1ggL90Tol+0FCcMo98NwdJcs71lp03e3yS5h A17VrYCPB7+2tk4ONuyNBqbVqgimP72ytd4bY6K3fZLsuWzd0cAc2Wttigx09dTSTDEh FiwGTF2GMHeFo53nm3Yyoq7crkwcl3r0HNhMDdPEHp4l/hS/4IFkaVNVczFI6tLC3VKD vNoqArGP78OHWGhRrAvq94SYR7r0KCLYpb4YTo4oKEAnES8O6sN+u6UzkBMimNTJFGIR 5CbChT2t3Ie7uHAtogAdm8i444bSHGX2d1Z2wns47b8WikKeOCgXs19jsXarEnsoiRtB IuhQ== X-Forwarded-Encrypted: i=1; AJvYcCVgJI41lLxN1NcABp20PZvjnOgRTFokozeNgEvU+2DJ1DET4fAv9RNn2jeWMqAKnSq85/B0xu0+teY3GXY=@vger.kernel.org X-Gm-Message-State: AOJu0YwuRK76PTrScFZSGla7nRvCfth2NKJ8efx0pAJEiRMmeVoeMkMk 9F/4WuN9dhAUp5hZlaCUMSel1Oscx4GZAE9S1prOkiPu0CcbJfdz X-Google-Smtp-Source: AGHT+IFcDCnh+GFomTIglH2R+DVSfYeYgoMGsBrgZ6PYSrWX86fx0GtVtpMjP+Ps3oyVKtXR6WyB3A== X-Received: by 2002:a05:6a21:3987:b0:1cf:4a69:6349 with SMTP id adf61e73a8af0-1d1128a7d15mr3793492637.0.1726223398448; Fri, 13 Sep 2024 03:29:58 -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.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:29:58 -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 17/22] mmc: sdhci-uhs2: add irq() and others Date: Fri, 13 Sep 2024 18:28:31 +0800 Message-Id: <20240913102836.6144-18-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 UHS-II version of sdhci's request() operation. It handles UHS-II related command interrupts and errors. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- Updates in V22: - Remove unnecessary code to avoid defined but not used warnings. Updates in V19: - Corrected sdhci_uhs2_reset() parameter errors in the sdhci_uhs2_request_done(). Updates in V18: - Modify the judgment condition in the sdhci_uhs2_reset_cmd_data() and replace it from mmc_card_uhs2() to host->mmc->uhs2_sd_tran flag. Updates in V17: - Add sdhci_uhs2_reset_cmd_data() and sdhci_uhs2_needs_reset() to resolve the data error or cmd error. Updates in V14: - Use mmc_card_uhs2() to stead sdhci_uhs2_mode() in the sdhci_uhs2_complete_work(), sdhci_uhs2_irq() and sdhci_uhs2_thread_irq(). Updates in V13: - Re-order function to avoid declaration. - Remove unnecessary definitions. Updates in V9: - Cancel export state of sdhci_set_mrq_done() function. Updates in V8: - Forward declare struct mmc_request in sdhci_uhs2.h. - Remove forward declaration of sdhci_send_command(). - Use mmc_dev() to simplify code in sdhci_request_done_dma(). Updates in V7: - Remove unnecessary functions. - Use sdhci_uhs2_mode() to simplify code in sdhci_uhs2_irq(). - Modify descriptions in sdhci_uhs2_irq(). - Cancel export state of some functions. Updates in V6: - Remove unnecessary functions. - Add sdhci_uhs2_mode() in sdhci_uhs2_complete_work(). - Add sdhci_uhs2_mode() in sdhci_uhs2_thread_irq(). --- drivers/mmc/host/sdhci-uhs2.c | 227 ++++++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci-uhs2.h | 2 + drivers/mmc/host/sdhci.c | 109 +++++++++------- drivers/mmc/host/sdhci.h | 8 ++ 4 files changed, 298 insertions(+), 48 deletions(-) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index 94e041520a54..76f1af8b0486 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -98,6 +98,19 @@ void sdhci_uhs2_reset(struct sdhci_host *host, u16 mask) } EXPORT_SYMBOL_GPL(sdhci_uhs2_reset); =20 +static void sdhci_uhs2_reset_cmd_data(struct sdhci_host *host) +{ + sdhci_do_reset(host, SDHCI_RESET_CMD | SDHCI_RESET_DATA); + + if (host->mmc->uhs2_sd_tran) { + sdhci_uhs2_reset(host, SDHCI_UHS2_SW_RESET_SD); + + sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); + sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); + sdhci_uhs2_clear_set_irqs(host, SDHCI_INT_ALL_MASK, SDHCI_UHS2_INT_ERROR= _MASK); + } +} + void sdhci_uhs2_set_power(struct sdhci_host *host, unsigned char mode, uns= igned short vdd) { struct mmc_host *mmc =3D host->mmc; @@ -529,6 +542,217 @@ static int sdhci_uhs2_control(struct mmc_host *mmc, e= num sd_uhs2_operation op) return err; } =20 +/*************************************************************************= ****\ + * = * + * Request done = * + * = * +\*************************************************************************= ****/ + +static bool sdhci_uhs2_needs_reset(struct sdhci_host *host, struct mmc_req= uest *mrq) +{ + return sdhci_needs_reset(host, mrq) || + (!(host->flags & SDHCI_DEVICE_DEAD) && mrq->data && mrq->data->err= or); +} + +static bool sdhci_uhs2_request_done(struct sdhci_host *host) +{ + unsigned long flags; + struct mmc_request *mrq; + int i; + + spin_lock_irqsave(&host->lock, flags); + + for (i =3D 0; i < SDHCI_MAX_MRQS; i++) { + mrq =3D host->mrqs_done[i]; + if (mrq) + break; + } + + if (!mrq) { + spin_unlock_irqrestore(&host->lock, flags); + return true; + } + + /* + * Always unmap the data buffers if they were mapped by + * sdhci_prepare_data() whenever we finish with a request. + * This avoids leaking DMA mappings on error. + */ + if (host->flags & SDHCI_REQ_USE_DMA) + sdhci_request_done_dma(host, mrq); + + /* + * The controller needs a reset of internal state machines + * upon error conditions. + */ + if (sdhci_uhs2_needs_reset(host, mrq)) { + /* + * Do not finish until command and data lines are available for + * reset. Note there can only be one other mrq, so it cannot + * also be in mrqs_done, otherwise host->cmd and host->data_cmd + * would both be null. + */ + if (host->cmd || host->data_cmd) { + spin_unlock_irqrestore(&host->lock, flags); + return true; + } + + if (mrq->cmd->error || mrq->data->error) + sdhci_uhs2_reset_cmd_data(host); + else + sdhci_uhs2_reset(host, SDHCI_UHS2_SW_RESET_SD); + host->pending_reset =3D false; + } + + host->mrqs_done[i] =3D NULL; + + spin_unlock_irqrestore(&host->lock, flags); + + if (host->ops->request_done) + host->ops->request_done(host, mrq); + else + mmc_request_done(host->mmc, mrq); + + return false; +} + +static void sdhci_uhs2_complete_work(struct work_struct *work) +{ + struct sdhci_host *host =3D container_of(work, struct sdhci_host, + complete_work); + + if (!mmc_card_uhs2(host->mmc)) { + sdhci_complete_work(work); + return; + } + + while (!sdhci_uhs2_request_done(host)) + ; +} + +/*************************************************************************= ****\ + * = * + * Interrupt handling = * + * = * +\*************************************************************************= ****/ + +static void __sdhci_uhs2_irq(struct sdhci_host *host, u32 uhs2mask) +{ + DBG("*** %s got UHS2 error interrupt: 0x%08x\n", + mmc_hostname(host->mmc), uhs2mask); + + if (uhs2mask & SDHCI_UHS2_INT_CMD_ERR_MASK) { + if (!host->cmd) { + pr_err("%s: Got cmd interrupt 0x%08x but no cmd.\n", + mmc_hostname(host->mmc), + (unsigned int)uhs2mask); + sdhci_dumpregs(host); + return; + } + host->cmd->error =3D -EILSEQ; + if (uhs2mask & SDHCI_UHS2_INT_CMD_TIMEOUT) + host->cmd->error =3D -ETIMEDOUT; + } + + if (uhs2mask & SDHCI_UHS2_INT_DATA_ERR_MASK) { + if (!host->data) { + pr_err("%s: Got data interrupt 0x%08x but no data.\n", + mmc_hostname(host->mmc), + (unsigned int)uhs2mask); + sdhci_dumpregs(host); + return; + } + + if (uhs2mask & SDHCI_UHS2_INT_DEADLOCK_TIMEOUT) { + pr_err("%s: Got deadlock timeout interrupt 0x%08x\n", + mmc_hostname(host->mmc), + (unsigned int)uhs2mask); + host->data->error =3D -ETIMEDOUT; + } else if (uhs2mask & SDHCI_UHS2_INT_ADMA_ERROR) { + pr_err("%s: ADMA error =3D 0x %x\n", + mmc_hostname(host->mmc), + sdhci_readb(host, SDHCI_ADMA_ERROR)); + host->data->error =3D -EIO; + } else { + host->data->error =3D -EILSEQ; + } + } +} + +u32 sdhci_uhs2_irq(struct sdhci_host *host, u32 intmask) +{ + u32 mask =3D intmask, uhs2mask; + + if (!mmc_card_uhs2(host->mmc)) + goto out; + + if (intmask & SDHCI_INT_ERROR) { + uhs2mask =3D sdhci_readl(host, SDHCI_UHS2_INT_STATUS); + if (!(uhs2mask & SDHCI_UHS2_INT_ERROR_MASK)) + goto cmd_irq; + + /* Clear error interrupts */ + sdhci_writel(host, uhs2mask & SDHCI_UHS2_INT_ERROR_MASK, + SDHCI_UHS2_INT_STATUS); + + /* Handle error interrupts */ + __sdhci_uhs2_irq(host, uhs2mask); + + /* Caller, sdhci_irq(), doesn't have to care about UHS-2 errors */ + intmask &=3D ~SDHCI_INT_ERROR; + mask &=3D SDHCI_INT_ERROR; + } + +cmd_irq: + if (intmask & SDHCI_INT_CMD_MASK) { + /* Clear command interrupt */ + sdhci_writel(host, intmask & SDHCI_INT_CMD_MASK, SDHCI_INT_STATUS); + + /* Caller, sdhci_irq(), doesn't have to care about UHS-2 commands */ + intmask &=3D ~SDHCI_INT_CMD_MASK; + mask &=3D SDHCI_INT_CMD_MASK; + } + + /* Clear already-handled interrupts. */ + sdhci_writel(host, mask, SDHCI_INT_STATUS); + +out: + return intmask; +} +EXPORT_SYMBOL_GPL(sdhci_uhs2_irq); + +static irqreturn_t sdhci_uhs2_thread_irq(int irq, void *dev_id) +{ + struct sdhci_host *host =3D dev_id; + struct mmc_command *cmd; + unsigned long flags; + u32 isr; + + if (!mmc_card_uhs2(host->mmc)) + return sdhci_thread_irq(irq, dev_id); + + while (!sdhci_uhs2_request_done(host)) + ; + + spin_lock_irqsave(&host->lock, flags); + + isr =3D host->thread_isr; + host->thread_isr =3D 0; + + cmd =3D host->deferred_cmd; + + spin_unlock_irqrestore(&host->lock, flags); + + if (isr & (SDHCI_INT_CARD_INSERT | SDHCI_INT_CARD_REMOVE)) { + struct mmc_host *mmc =3D host->mmc; + + mmc->ops->card_event(mmc); + mmc_detect_change(mmc, msecs_to_jiffies(200)); + } + + return IRQ_HANDLED; +} + /*************************************************************************= ****\ * = * * Driver init/exit = * @@ -620,6 +844,9 @@ int sdhci_uhs2_add_host(struct sdhci_host *host) if (mmc->caps2 & MMC_CAP2_SD_UHS2) sdhci_uhs2_host_ops_init(host); =20 + host->complete_work_fn =3D sdhci_uhs2_complete_work; + host->thread_irq_fn =3D sdhci_uhs2_thread_irq; + /* 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 14713a31f8a5..3205adaecfa4 100644 --- a/drivers/mmc/host/sdhci-uhs2.h +++ b/drivers/mmc/host/sdhci-uhs2.h @@ -176,6 +176,7 @@ =20 struct sdhci_host; struct mmc_command; +struct mmc_request; =20 void sdhci_uhs2_dump_regs(struct sdhci_host *host); void sdhci_uhs2_reset(struct sdhci_host *host, u16 mask); @@ -184,5 +185,6 @@ void sdhci_uhs2_set_timeout(struct sdhci_host *host, st= ruct mmc_command *cmd); 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= ); +u32 sdhci_uhs2_irq(struct sdhci_host *host, u32 intmask); =20 #endif /* __SDHCI_UHS2_H */ diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 63fa1714930a..871b4fe2a1b2 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -234,7 +234,7 @@ void sdhci_reset(struct sdhci_host *host, u8 mask) } EXPORT_SYMBOL_GPL(sdhci_reset); =20 -static bool sdhci_do_reset(struct sdhci_host *host, u8 mask) +bool sdhci_do_reset(struct sdhci_host *host, u8 mask) { if (host->quirks & SDHCI_QUIRK_NO_CARD_NO_RESET) { struct mmc_host *mmc =3D host->mmc; @@ -247,6 +247,7 @@ static bool sdhci_do_reset(struct sdhci_host *host, u8 = mask) =20 return true; } +EXPORT_SYMBOL_GPL(sdhci_do_reset); =20 static void sdhci_reset_for_all(struct sdhci_host *host) { @@ -1489,7 +1490,7 @@ static void sdhci_set_transfer_mode(struct sdhci_host= *host, sdhci_writew(host, mode, SDHCI_TRANSFER_MODE); } =20 -static bool sdhci_needs_reset(struct sdhci_host *host, struct mmc_request = *mrq) +bool sdhci_needs_reset(struct sdhci_host *host, struct mmc_request *mrq) { return (!(host->flags & SDHCI_DEVICE_DEAD) && ((mrq->cmd && mrq->cmd->error) || @@ -1497,6 +1498,7 @@ static bool sdhci_needs_reset(struct sdhci_host *host= , struct mmc_request *mrq) (mrq->data && mrq->data->stop && mrq->data->stop->error) || (host->quirks & SDHCI_QUIRK_RESET_AFTER_REQUEST))); } +EXPORT_SYMBOL_GPL(sdhci_needs_reset); =20 static void sdhci_set_mrq_done(struct sdhci_host *host, struct mmc_request= *mrq) { @@ -3076,6 +3078,53 @@ static const struct mmc_host_ops sdhci_ops =3D { * = * \*************************************************************************= ****/ =20 +void sdhci_request_done_dma(struct sdhci_host *host, struct mmc_request *m= rq) +{ + struct mmc_data *data =3D mrq->data; + + if (data && data->host_cookie =3D=3D COOKIE_MAPPED) { + if (host->bounce_buffer) { + /* + * On reads, copy the bounced data into the + * sglist + */ + if (mmc_get_dma_dir(data) =3D=3D DMA_FROM_DEVICE) { + unsigned int length =3D data->bytes_xfered; + + if (length > host->bounce_buffer_size) { + pr_err("%s: bounce buffer is %u bytes but DMA claims to have transfer= red %u bytes\n", + mmc_hostname(host->mmc), + host->bounce_buffer_size, + data->bytes_xfered); + /* Cap it down and continue */ + length =3D host->bounce_buffer_size; + } + dma_sync_single_for_cpu(mmc_dev(host->mmc), + host->bounce_addr, + host->bounce_buffer_size, + DMA_FROM_DEVICE); + sg_copy_from_buffer(data->sg, + data->sg_len, + host->bounce_buffer, + length); + } else { + /* No copying, just switch ownership */ + dma_sync_single_for_cpu(mmc_dev(host->mmc), + host->bounce_addr, + host->bounce_buffer_size, + mmc_get_dma_dir(data)); + } + } else { + /* Unmap the raw data */ + dma_unmap_sg(mmc_dev(host->mmc), data->sg, + data->sg_len, + mmc_get_dma_dir(data)); + } + data->host_cookie =3D COOKIE_UNMAPPED; + } +} +EXPORT_SYMBOL_GPL(sdhci_request_done_dma); + static bool sdhci_request_done(struct sdhci_host *host) { unsigned long flags; @@ -3140,48 +3189,7 @@ static bool sdhci_request_done(struct sdhci_host *ho= st) sdhci_set_mrq_done(host, mrq); } =20 - if (data && data->host_cookie =3D=3D COOKIE_MAPPED) { - if (host->bounce_buffer) { - /* - * On reads, copy the bounced data into the - * sglist - */ - if (mmc_get_dma_dir(data) =3D=3D DMA_FROM_DEVICE) { - unsigned int length =3D data->bytes_xfered; - - if (length > host->bounce_buffer_size) { - pr_err("%s: bounce buffer is %u bytes but DMA claims to have transfe= rred %u bytes\n", - mmc_hostname(host->mmc), - host->bounce_buffer_size, - data->bytes_xfered); - /* Cap it down and continue */ - length =3D host->bounce_buffer_size; - } - dma_sync_single_for_cpu( - mmc_dev(host->mmc), - host->bounce_addr, - host->bounce_buffer_size, - DMA_FROM_DEVICE); - sg_copy_from_buffer(data->sg, - data->sg_len, - host->bounce_buffer, - length); - } else { - /* No copying, just switch ownership */ - dma_sync_single_for_cpu( - mmc_dev(host->mmc), - host->bounce_addr, - host->bounce_buffer_size, - mmc_get_dma_dir(data)); - } - } else { - /* Unmap the raw data */ - dma_unmap_sg(mmc_dev(host->mmc), data->sg, - data->sg_len, - mmc_get_dma_dir(data)); - } - data->host_cookie =3D COOKIE_UNMAPPED; - } + sdhci_request_done_dma(host, mrq); } =20 host->mrqs_done[i] =3D NULL; @@ -3196,7 +3204,7 @@ static bool sdhci_request_done(struct sdhci_host *hos= t) return false; } =20 -static void sdhci_complete_work(struct work_struct *work) +void sdhci_complete_work(struct work_struct *work) { struct sdhci_host *host =3D container_of(work, struct sdhci_host, complete_work); @@ -3204,6 +3212,7 @@ static void sdhci_complete_work(struct work_struct *w= ork) while (!sdhci_request_done(host)) ; } +EXPORT_SYMBOL_GPL(sdhci_complete_work); =20 static void sdhci_timeout_timer(struct timer_list *t) { @@ -3665,7 +3674,7 @@ static irqreturn_t sdhci_irq(int irq, void *dev_id) return result; } =20 -static irqreturn_t sdhci_thread_irq(int irq, void *dev_id) +irqreturn_t sdhci_thread_irq(int irq, void *dev_id) { struct sdhci_host *host =3D dev_id; struct mmc_command *cmd; @@ -3695,6 +3704,7 @@ static irqreturn_t sdhci_thread_irq(int irq, void *de= v_id) =20 return IRQ_HANDLED; } +EXPORT_SYMBOL_GPL(sdhci_thread_irq); =20 /*************************************************************************= ****\ * = * @@ -4067,6 +4077,9 @@ struct sdhci_host *sdhci_alloc_host(struct device *de= v, =20 host->max_timeout_count =3D 0xE; =20 + host->complete_work_fn =3D sdhci_complete_work; + host->thread_irq_fn =3D sdhci_thread_irq; + return host; } =20 @@ -4831,7 +4844,7 @@ int __sdhci_add_host(struct sdhci_host *host) if (!host->complete_wq) return -ENOMEM; =20 - INIT_WORK(&host->complete_work, sdhci_complete_work); + INIT_WORK(&host->complete_work, host->complete_work_fn); =20 timer_setup(&host->timer, sdhci_timeout_timer, 0); timer_setup(&host->data_timer, sdhci_timeout_data_timer, 0); @@ -4840,7 +4853,7 @@ int __sdhci_add_host(struct sdhci_host *host) =20 sdhci_init(host, 0); =20 - ret =3D request_threaded_irq(host->irq, sdhci_irq, sdhci_thread_irq, + ret =3D request_threaded_irq(host->irq, sdhci_irq, host->thread_irq_fn, IRQF_SHARED, mmc_hostname(mmc), host); if (ret) { pr_err("%s: Failed to request IRQ %d: %d\n", diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index 5c66927210bd..5f416bc783bd 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -625,6 +625,9 @@ struct sdhci_host { struct timer_list timer; /* Timer for timeouts */ struct timer_list data_timer; /* Timer for data timeouts */ =20 + void (*complete_work_fn)(struct work_struct *work); + irqreturn_t (*thread_irq_fn)(int irq, void *dev_id); + #if IS_ENABLED(CONFIG_MMC_SDHCI_EXTERNAL_DMA) struct dma_chan *rx_chan; struct dma_chan *tx_chan; @@ -827,6 +830,7 @@ static inline void sdhci_read_caps(struct sdhci_host *h= ost) __sdhci_read_caps(host, NULL, NULL, NULL); } =20 +bool sdhci_needs_reset(struct sdhci_host *host, struct mmc_request *mrq); u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock, unsigned int *actual_clock); void sdhci_set_clock(struct sdhci_host *host, unsigned int clock); @@ -845,6 +849,7 @@ void sdhci_request(struct mmc_host *mmc, struct mmc_req= uest *mrq); int sdhci_request_atomic(struct mmc_host *mmc, struct mmc_request *mrq); void sdhci_set_bus_width(struct sdhci_host *host, int width); void sdhci_reset(struct sdhci_host *host, u8 mask); +bool sdhci_do_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); @@ -854,6 +859,9 @@ 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); void sdhci_enable_sdio_irq(struct mmc_host *mmc, int enable); +void sdhci_request_done_dma(struct sdhci_host *host, struct mmc_request *m= rq); +void sdhci_complete_work(struct work_struct *work); +irqreturn_t sdhci_thread_irq(int irq, void *dev_id); void sdhci_adma_write_desc(struct sdhci_host *host, void **desc, dma_addr_t addr, int len, unsigned int cmd); =20 --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 96EB11DC1A8; Fri, 13 Sep 2024 10:30:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223405; cv=none; b=RqW2+ljCJ2Lbu68CvL0nckUHFioE1b4yPWvsj7I9hRYOxzOAgPX1JpLZYiwk6suY3Gm1Z52G8ZtuB49Z0xcUY+/NcreMydXUj1PfSgADMZr7CbiIqw9TfJdx7fUWz7cLjYeT1xYRwjpkgPi1L5KOJ+PwcK3K8du+pxMX/8V49Oc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223405; c=relaxed/simple; bh=CFzQ4Vv7dL/101A5xPHXt02EkDI0vj/zsYXvMDV0jEc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=aAXAMpeRYctb/8R548dY7AM/0JwTDBf4KwuIELE7x4jScPGpEZkMRYoaI6ajlrxsD6+htxve1jotmwh6aLkUKl5Og+I0R6lFLQkPpFu4bzhrMAhDXTilRVcMgtWhdV7LKtX+Rgry45sfUFNW9jmhXgep6ovkddLwBxRgTyA+QgY= 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=EraK9ZcO; arc=none smtp.client-ip=209.85.210.171 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="EraK9ZcO" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-717849c0dcaso774674b3a.3; Fri, 13 Sep 2024 03:30:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223403; x=1726828203; 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=h7uSYeaZZwxXwIQD3LCDHDP91xIJh8wcjYWHXNSRfSs=; b=EraK9ZcOXqRJM1Qh9972q5cMor8ZVMqce5YvHW4aRH+uew7C2qaSZr6c0hsS9ZiVZN kcdOx2yHaaDBeuJ18x+PkhOODWHeNZ6kmnbZlzt7K01Sidszl7g7B26xIUMa53prgJ1V /ZFpemvbPD6C1ptiPz8iPXr9SnSTI+E1OE3HBsHhujJOh4CzcOhboGZ9LfFQOcOPSVne P30CW8NhHpvZcPAXH0HsPgbb7n0Iu/00TqdhF0Ex6+Czwgs9WOYji6OhWMnD6UATfXAr 3C1usqE+5+vFXfK2Q0/6lhSa6mSRAxz4VRUcCxJ12woH6aUdX7vBUN8t2GCnUnTHt0j7 JcTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223403; x=1726828203; 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=h7uSYeaZZwxXwIQD3LCDHDP91xIJh8wcjYWHXNSRfSs=; b=iNXA8wsY3lzQ3cVHzDW0MyYYnsnQzY3i+5Zi0EwSoCmk9NXsf9IvXPtXNbAo5jltuq WaYO21G9iAdpfxaxKtsEcqBdAReVHmOHOTmBUxtqr2L5YwJikKrVSeJ80VxIqZ5IF0dF tU5+BEEOZsvyAXiXHgANWGH+vggN7LbB3zUr4TVEd0cELIj+8d86Wf8evSixrecUEU1t QjxssnZdEtTfWu44oaKDe2xlcNMqE156ZkQYwpf6qqAEIFV4q6Pq/vY9QiVSO7ataTqJ zdu8OwCr1tZv117zwfy9UYPeZsoK4qezyobeUQGibr2TfXMafiQtVmk9gfq8SP4qFvVc lHeg== X-Forwarded-Encrypted: i=1; AJvYcCXFxC0VziKtEEdLre8w249KvjS6mznXInhXyQ9ElPWUN+eHy1U64PHuro6hS9n+4/8wL6LYM2iQFRlrAo4=@vger.kernel.org X-Gm-Message-State: AOJu0Yz6CQH4vhhcWeySPajMJNGdHeKGzE+jJnRp8aowIlqziM5Znbu8 0YDFn8s5tdCK8YarzPeT+afR86r9zxJlpSZLgLzdv+rinUk25yJWKU6HZL24 X-Google-Smtp-Source: AGHT+IFSx1UxvzEfTS67t6k/wLKwa9hVC37FtD1CLnlYEoXkPgkSexn5/1svva4WJts+wTzd5DuguA== X-Received: by 2002:a05:6a20:cd91:b0:1d0:7df8:2484 with SMTP id adf61e73a8af0-1d112eae052mr3185523637.43.1726223402767; Fri, 13 Sep 2024 03:30:02 -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.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:30:02 -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 18/22] mmc: sdhci-uhs2: add request() and others Date: Fri, 13 Sep 2024 18:28:32 +0800 Message-Id: <20240913102836.6144-19-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 request operation. It covers both UHS-I and UHS-II. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- Updates in V22: - Adjust the patch order from v21 patch#16 to v22 patch#18 and add necessary code to avoid defined but not used warnings. Updates in V19: - cmd->uhs2_cmd->uhs2_resp is always true, remove it from safety check in the __sdhci_uhs2_finish_command(). Updates in V17: - Add new parameter to __sdhci_finish_data_common(). Updates in V16: - Remove irrelevant definition in the sdhci_calc_timeout_uhs2(). Updates in V15: - Adjust the parameters used in the __sdhci_uhs2_finish_command() to match changes in the Patch#7. Updates in V14: - Use mmc_card_uhs2() to stead sdhci_uhs2_mode() in the sdhci_uhs2_request(). Updates in V13: - Re-order function to avoid declaration. - Remove unnecessary function. Updates in V11: - Drop the check mmc_card_uhs2_hd_mode(host->mmc) in sdhci_uhs2_set_transfer_mode(). Updates in V10: - Use tmode_half_duplex to instead of uhs2_tmode0_flag in sdhci_uhs2_set_transfer_mode(). Updates in V9: - Modify the annotations in __sdhci_uhs2_send_command(). Updates in V8: - Adjust the position of matching brackets in sdhci_uhs2_send_command_retry(). - Modify CameCase definition in __sdhci_uhs2_finish_command(). - Modify error message in __sdhci_uhs2_finish_command(). - sdhci_uhs2_send_command_retry() to instead of sdhci_uhs2_send_command() in sdhci_uhs2_request(). - Use sdhci_uhs2_mode() to simplify code in sdhci_uhs2_request_atomic(). - Add forward declaration for sdhci_send_command(). Updates in V7: - Cancel export state of some functions. - Remove unnecessary whitespace changes. Updates in V6: - Add uhs2_dev_cmd() to simplify code. - Remove unnecessary functions. - Cancel export state of some functions. - Drop use CONFIG_MMC_DEBUG(). - Wrap at 100 columns in some functions. --- drivers/mmc/host/sdhci-uhs2.c | 392 ++++++++++++++++++++++++++++++++++ drivers/mmc/host/sdhci.c | 53 +++-- drivers/mmc/host/sdhci.h | 8 + 3 files changed, 437 insertions(+), 16 deletions(-) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index 76f1af8b0486..d99ea05098cb 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -15,6 +15,8 @@ #include #include #include +#include +#include =20 #include "sdhci.h" #include "sdhci-uhs2.h" @@ -30,6 +32,8 @@ #define UHS2_INTERFACE_DETECT_TIMEOUT_100MS 100000 #define UHS2_LANE_SYNC_TIMEOUT_150MS 150000 =20 +#define UHS2_ARG_IOADR_MASK 0xfff + void sdhci_uhs2_dump_regs(struct sdhci_host *host) { if (!(mmc_card_uhs2(host->mmc))) @@ -64,6 +68,11 @@ EXPORT_SYMBOL_GPL(sdhci_uhs2_dump_regs); * = * \*************************************************************************= ****/ =20 +static inline u16 uhs2_dev_cmd(struct mmc_command *cmd) +{ + return be16_to_cpu((__be16)cmd->uhs2_cmd->arg) & UHS2_ARG_IOADR_MASK; +} + static inline int mmc_opt_regulator_set_ocr(struct mmc_host *mmc, struct regulator *supply, unsigned short vdd_bit) @@ -542,6 +551,374 @@ static int sdhci_uhs2_control(struct mmc_host *mmc, e= num sd_uhs2_operation op) return err; } =20 +/*************************************************************************= ****\ + * = * + * Core functions = * + * = * +\*************************************************************************= ****/ + +static void sdhci_uhs2_prepare_data(struct sdhci_host *host, struct mmc_co= mmand *cmd) +{ + struct mmc_data *data =3D cmd->data; + + sdhci_initialize_data(host, data); + + sdhci_prepare_dma(host, data); + + sdhci_writew(host, data->blksz, SDHCI_UHS2_BLOCK_SIZE); + sdhci_writew(host, data->blocks, SDHCI_UHS2_BLOCK_COUNT); +} + +static void sdhci_uhs2_finish_data(struct sdhci_host *host) +{ + struct mmc_data *data =3D host->data; + + __sdhci_finish_data_common(host, true); + + __sdhci_finish_mrq(host, data->mrq); +} + +static void sdhci_uhs2_set_transfer_mode(struct sdhci_host *host, struct m= mc_command *cmd) +{ + u16 mode; + struct mmc_data *data =3D cmd->data; + + if (!data) { + /* clear Auto CMD settings for no data CMDs */ + if (uhs2_dev_cmd(cmd) =3D=3D UHS2_DEV_CMD_TRANS_ABORT) { + mode =3D 0; + } else { + mode =3D sdhci_readw(host, SDHCI_UHS2_TRANS_MODE); + if (cmd->opcode =3D=3D MMC_STOP_TRANSMISSION || cmd->opcode =3D=3D MMC_= ERASE) + mode |=3D SDHCI_UHS2_TRNS_WAIT_EBSY; + else + /* send status mode */ + if (cmd->opcode =3D=3D MMC_SEND_STATUS) + mode =3D 0; + } + + DBG("UHS2 no data trans mode is 0x%x.\n", mode); + + sdhci_writew(host, mode, SDHCI_UHS2_TRANS_MODE); + return; + } + + WARN_ON(!host->data); + + mode =3D SDHCI_UHS2_TRNS_BLK_CNT_EN | SDHCI_UHS2_TRNS_WAIT_EBSY; + if (data->flags & MMC_DATA_WRITE) + mode |=3D SDHCI_UHS2_TRNS_DATA_TRNS_WRT; + + if (data->blocks =3D=3D 1 && + data->blksz !=3D 512 && + cmd->opcode !=3D MMC_READ_SINGLE_BLOCK && + cmd->opcode !=3D MMC_WRITE_BLOCK) { + mode &=3D ~SDHCI_UHS2_TRNS_BLK_CNT_EN; + mode |=3D SDHCI_UHS2_TRNS_BLK_BYTE_MODE; + } + + if (host->flags & SDHCI_REQ_USE_DMA) + mode |=3D SDHCI_UHS2_TRNS_DMA; + + if (cmd->uhs2_cmd->tmode_half_duplex) + mode |=3D SDHCI_UHS2_TRNS_2L_HD; + + sdhci_writew(host, mode, SDHCI_UHS2_TRANS_MODE); + + DBG("UHS2 trans mode is 0x%x.\n", mode); +} + +static void __sdhci_uhs2_send_command(struct sdhci_host *host, struct mmc_= command *cmd) +{ + int i, j; + int cmd_reg; + + i =3D 0; + sdhci_writel(host, + ((u32)cmd->uhs2_cmd->arg << 16) | + (u32)cmd->uhs2_cmd->header, + SDHCI_UHS2_CMD_PACKET + i); + i +=3D 4; + + /* + * Per spec, payload (config) should be MSB before sending out. + * But we don't need convert here because had set payload as + * MSB when preparing config read/write commands. + */ + for (j =3D 0; j < cmd->uhs2_cmd->payload_len / sizeof(u32); j++) { + sdhci_writel(host, *(cmd->uhs2_cmd->payload + j), SDHCI_UHS2_CMD_PACKET = + i); + i +=3D 4; + } + + for ( ; i < SDHCI_UHS2_CMD_PACK_MAX_LEN; i +=3D 4) + sdhci_writel(host, 0, SDHCI_UHS2_CMD_PACKET + i); + + DBG("UHS2 CMD packet_len =3D %d.\n", cmd->uhs2_cmd->packet_len); + for (i =3D 0; i < cmd->uhs2_cmd->packet_len; i++) + DBG("UHS2 CMD_PACKET[%d] =3D 0x%x.\n", i, + sdhci_readb(host, SDHCI_UHS2_CMD_PACKET + i)); + + cmd_reg =3D FIELD_PREP(SDHCI_UHS2_CMD_PACK_LEN_MASK, cmd->uhs2_cmd->packe= t_len); + if ((cmd->flags & MMC_CMD_MASK) =3D=3D MMC_CMD_ADTC) + cmd_reg |=3D SDHCI_UHS2_CMD_DATA; + if (cmd->opcode =3D=3D MMC_STOP_TRANSMISSION) + cmd_reg |=3D SDHCI_UHS2_CMD_CMD12; + + /* UHS2 Native ABORT */ + if ((cmd->uhs2_cmd->header & UHS2_NATIVE_PACKET) && + (uhs2_dev_cmd(cmd) =3D=3D UHS2_DEV_CMD_TRANS_ABORT)) + cmd_reg |=3D SDHCI_UHS2_CMD_TRNS_ABORT; + + /* UHS2 Native DORMANT */ + if ((cmd->uhs2_cmd->header & UHS2_NATIVE_PACKET) && + (uhs2_dev_cmd(cmd) =3D=3D UHS2_DEV_CMD_GO_DORMANT_STATE)) + cmd_reg |=3D SDHCI_UHS2_CMD_DORMANT; + + DBG("0x%x is set to UHS2 CMD register.\n", cmd_reg); + + sdhci_writew(host, cmd_reg, SDHCI_UHS2_CMD); +} + +static bool sdhci_uhs2_send_command(struct sdhci_host *host, struct mmc_co= mmand *cmd) +{ + int flags; + u32 mask; + unsigned long timeout; + + WARN_ON(host->cmd); + + /* Initially, a command has no error */ + cmd->error =3D 0; + + if (cmd->opcode =3D=3D MMC_STOP_TRANSMISSION) + cmd->flags |=3D MMC_RSP_BUSY; + + mask =3D SDHCI_CMD_INHIBIT; + + if (sdhci_readl(host, SDHCI_PRESENT_STATE) & mask) + return false; + + host->cmd =3D cmd; + host->data_timeout =3D 0; + if (sdhci_data_line_cmd(cmd)) { + WARN_ON(host->data_cmd); + host->data_cmd =3D cmd; + __sdhci_uhs2_set_timeout(host); + } + + if (cmd->data) + sdhci_uhs2_prepare_data(host, cmd); + + sdhci_uhs2_set_transfer_mode(host, cmd); + + if ((cmd->flags & MMC_RSP_136) && (cmd->flags & MMC_RSP_BUSY)) { + WARN_ONCE(1, "Unsupported response type!\n"); + /* + * This does not happen in practice because 136-bit response + * commands never have busy waiting, so rather than complicate + * the error path, just remove busy waiting and continue. + */ + cmd->flags &=3D ~MMC_RSP_BUSY; + } + + if (!(cmd->flags & MMC_RSP_PRESENT)) + flags =3D SDHCI_CMD_RESP_NONE; + else if (cmd->flags & MMC_RSP_136) + flags =3D SDHCI_CMD_RESP_LONG; + else if (cmd->flags & MMC_RSP_BUSY) + flags =3D SDHCI_CMD_RESP_SHORT_BUSY; + else + flags =3D SDHCI_CMD_RESP_SHORT; + + if (cmd->flags & MMC_RSP_CRC) + flags |=3D SDHCI_CMD_CRC; + if (cmd->flags & MMC_RSP_OPCODE) + flags |=3D SDHCI_CMD_INDEX; + + timeout =3D jiffies; + if (host->data_timeout) + timeout +=3D nsecs_to_jiffies(host->data_timeout); + else if (!cmd->data && cmd->busy_timeout > 9000) + timeout +=3D DIV_ROUND_UP(cmd->busy_timeout, 1000) * HZ + HZ; + else + timeout +=3D 10 * HZ; + sdhci_mod_timer(host, cmd->mrq, timeout); + + __sdhci_uhs2_send_command(host, cmd); + + return true; +} + +static bool sdhci_uhs2_send_command_retry(struct sdhci_host *host, + struct mmc_command *cmd, + unsigned long flags) + __releases(host->lock) + __acquires(host->lock) +{ + struct mmc_command *deferred_cmd =3D host->deferred_cmd; + int timeout =3D 10; /* Approx. 10 ms */ + bool present; + + while (!sdhci_uhs2_send_command(host, cmd)) { + if (!timeout--) { + pr_err("%s: Controller never released inhibit bit(s).\n", + mmc_hostname(host->mmc)); + sdhci_dumpregs(host); + cmd->error =3D -EIO; + return false; + } + + spin_unlock_irqrestore(&host->lock, flags); + + usleep_range(1000, 1250); + + present =3D host->mmc->ops->get_cd(host->mmc); + + spin_lock_irqsave(&host->lock, flags); + + /* A deferred command might disappear, handle that */ + if (cmd =3D=3D deferred_cmd && cmd !=3D host->deferred_cmd) + return true; + + if (sdhci_present_error(host, cmd, present)) + return false; + } + + if (cmd =3D=3D host->deferred_cmd) + host->deferred_cmd =3D NULL; + + return true; +} + +static void __sdhci_uhs2_finish_command(struct sdhci_host *host) +{ + struct mmc_command *cmd =3D host->cmd; + u8 resp; + u8 error_code; + bool breada0 =3D 0; + int i; + + if (host->mmc->uhs2_sd_tran) { + resp =3D sdhci_readb(host, SDHCI_UHS2_RESPONSE + 2); + if (resp & UHS2_RES_NACK_MASK) { + error_code =3D (resp >> UHS2_RES_ECODE_POS) & UHS2_RES_ECODE_MASK; + pr_err("%s: NACK response, ECODE=3D0x%x.\n", + mmc_hostname(host->mmc), error_code); + } + breada0 =3D 1; + } + + if (cmd->uhs2_cmd->uhs2_resp_len) { + int len =3D min_t(int, cmd->uhs2_cmd->uhs2_resp_len, UHS2_MAX_RESP_LEN); + + /* Get whole response of some native CCMD, like + * DEVICE_INIT, ENUMERATE. + */ + for (i =3D 0; i < len; i++) + cmd->uhs2_cmd->uhs2_resp[i] =3D sdhci_readb(host, SDHCI_UHS2_RESPONSE += i); + } else { + /* Get SD CMD response and Payload for some read + * CCMD, like INQUIRY_CFG. + */ + /* Per spec (p136), payload field is divided into + * a unit of DWORD and transmission order within + * a DWORD is big endian. + */ + if (!breada0) + sdhci_readl(host, SDHCI_UHS2_RESPONSE); + for (i =3D 4; i < 20; i +=3D 4) { + cmd->resp[i / 4 - 1] =3D + (sdhci_readb(host, + SDHCI_UHS2_RESPONSE + i) << 24) | + (sdhci_readb(host, + SDHCI_UHS2_RESPONSE + i + 1) + << 16) | + (sdhci_readb(host, + SDHCI_UHS2_RESPONSE + i + 2) + << 8) | + sdhci_readb(host, SDHCI_UHS2_RESPONSE + i + 3); + } + } +} + +static void sdhci_uhs2_finish_command(struct sdhci_host *host) +{ + struct mmc_command *cmd =3D host->cmd; + + __sdhci_uhs2_finish_command(host); + + host->cmd =3D NULL; + + if (cmd->mrq->cap_cmd_during_tfr && cmd =3D=3D cmd->mrq->cmd) + mmc_command_done(host->mmc, cmd->mrq); + + /* + * The host can send and interrupt when the busy state has + * ended, allowing us to wait without wasting CPU cycles. + * The busy signal uses DAT0 so this is similar to waiting + * for data to complete. + * + * Note: The 1.0 specification is a bit ambiguous about this + * feature so there might be some problems with older + * controllers. + */ + if (cmd->flags & MMC_RSP_BUSY) { + if (cmd->data) { + DBG("Cannot wait for busy signal when also doing a data transfer"); + } else if (!(host->quirks & SDHCI_QUIRK_NO_BUSY_IRQ) && + cmd =3D=3D host->data_cmd) { + /* Command complete before busy is ended */ + return; + } + } + + /* Processed actual command. */ + if (host->data && host->data_early) + sdhci_uhs2_finish_data(host); + + if (!cmd->data) + __sdhci_finish_mrq(host, cmd->mrq); +} + +static void sdhci_uhs2_request(struct mmc_host *mmc, struct mmc_request *m= rq) +{ + struct sdhci_host *host =3D mmc_priv(mmc); + struct mmc_command *cmd; + unsigned long flags; + bool present; + + if (!(mmc_card_uhs2(mmc))) { + sdhci_request(mmc, mrq); + return; + } + + mrq->stop =3D NULL; + mrq->sbc =3D NULL; + if (mrq->data) + mrq->data->stop =3D NULL; + + /* Firstly check card presence */ + present =3D mmc->ops->get_cd(mmc); + + spin_lock_irqsave(&host->lock, flags); + + if (sdhci_present_error(host, mrq->cmd, present)) + goto out_finish; + + cmd =3D mrq->cmd; + + if (!sdhci_uhs2_send_command_retry(host, cmd, flags)) + goto out_finish; + + spin_unlock_irqrestore(&host->lock, flags); + + return; + +out_finish: + sdhci_finish_mrq(host, mrq); + spin_unlock_irqrestore(&host->lock, flags); +} + /*************************************************************************= ****\ * = * * Request done = * @@ -638,6 +1015,8 @@ static void sdhci_uhs2_complete_work(struct work_struc= t *work) =20 static void __sdhci_uhs2_irq(struct sdhci_host *host, u32 uhs2mask) { + struct mmc_command *cmd =3D host->cmd; + DBG("*** %s got UHS2 error interrupt: 0x%08x\n", mmc_hostname(host->mmc), uhs2mask); =20 @@ -677,6 +1056,12 @@ static void __sdhci_uhs2_irq(struct sdhci_host *host,= u32 uhs2mask) host->data->error =3D -EILSEQ; } } + + if (host->data && host->data->error) + sdhci_uhs2_finish_data(host); + else + sdhci_finish_mrq(host, cmd->mrq); + } =20 u32 sdhci_uhs2_irq(struct sdhci_host *host, u32 intmask) @@ -708,6 +1093,10 @@ u32 sdhci_uhs2_irq(struct sdhci_host *host, u32 intma= sk) /* Clear command interrupt */ sdhci_writel(host, intmask & SDHCI_INT_CMD_MASK, SDHCI_INT_STATUS); =20 + /* Handle command interrupt */ + if (intmask & SDHCI_INT_RESPONSE) + sdhci_uhs2_finish_command(host); + /* Caller, sdhci_irq(), doesn't have to care about UHS-2 commands */ intmask &=3D ~SDHCI_INT_CMD_MASK; mask &=3D SDHCI_INT_CMD_MASK; @@ -740,6 +1129,8 @@ static irqreturn_t sdhci_uhs2_thread_irq(int irq, void= *dev_id) host->thread_isr =3D 0; =20 cmd =3D host->deferred_cmd; + if (cmd && !sdhci_uhs2_send_command_retry(host, cmd, flags)) + sdhci_finish_mrq(host, cmd->mrq); =20 spin_unlock_irqrestore(&host->lock, flags); =20 @@ -762,6 +1153,7 @@ static irqreturn_t sdhci_uhs2_thread_irq(int irq, void= *dev_id) static int sdhci_uhs2_host_ops_init(struct sdhci_host *host) { host->mmc_host_ops.uhs2_control =3D sdhci_uhs2_control; + host->mmc_host_ops.request =3D sdhci_uhs2_request; =20 return 0; } diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 871b4fe2a1b2..f4a7733a8ad2 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -147,10 +147,11 @@ void sdhci_enable_v4_mode(struct sdhci_host *host) } EXPORT_SYMBOL_GPL(sdhci_enable_v4_mode); =20 -static inline bool sdhci_data_line_cmd(struct mmc_command *cmd) +bool sdhci_data_line_cmd(struct mmc_command *cmd) { return cmd->data || cmd->flags & MMC_RSP_BUSY; } +EXPORT_SYMBOL_GPL(sdhci_data_line_cmd); =20 static void sdhci_set_card_detection(struct sdhci_host *host, bool enable) { @@ -503,14 +504,15 @@ static inline void sdhci_led_deactivate(struct sdhci_= host *host) =20 #endif =20 -static void sdhci_mod_timer(struct sdhci_host *host, struct mmc_request *m= rq, - unsigned long timeout) +void sdhci_mod_timer(struct sdhci_host *host, struct mmc_request *mrq, + unsigned long timeout) { if (sdhci_data_line_cmd(mrq->cmd)) mod_timer(&host->data_timer, timeout); else mod_timer(&host->timer, timeout); } +EXPORT_SYMBOL_GPL(sdhci_mod_timer); =20 static void sdhci_del_timer(struct sdhci_host *host, struct mmc_request *m= rq) { @@ -1077,8 +1079,7 @@ static void sdhci_set_timeout(struct sdhci_host *host= , struct mmc_command *cmd) __sdhci_set_timeout(host, cmd); } =20 -static void sdhci_initialize_data(struct sdhci_host *host, - struct mmc_data *data) +void sdhci_initialize_data(struct sdhci_host *host, struct mmc_data *data) { WARN_ON(host->data); =20 @@ -1091,6 +1092,7 @@ static void sdhci_initialize_data(struct sdhci_host *= host, host->data_early =3D 0; host->data->bytes_xfered =3D 0; } +EXPORT_SYMBOL_GPL(sdhci_initialize_data); =20 static inline void sdhci_set_block_info(struct sdhci_host *host, struct mmc_data *data) @@ -1113,12 +1115,8 @@ static inline void sdhci_set_block_info(struct sdhci= _host *host, } } =20 -static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command= *cmd) +void sdhci_prepare_dma(struct sdhci_host *host, struct mmc_data *data) { - struct mmc_data *data =3D cmd->data; - - sdhci_initialize_data(host, data); - if (host->flags & (SDHCI_USE_SDMA | SDHCI_USE_ADMA)) { struct scatterlist *sg; unsigned int length_mask, offset_mask; @@ -1203,6 +1201,16 @@ static void sdhci_prepare_data(struct sdhci_host *ho= st, struct mmc_command *cmd) } =20 sdhci_set_transfer_irqs(host); +} +EXPORT_SYMBOL_GPL(sdhci_prepare_dma); + +static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command= *cmd) +{ + struct mmc_data *data =3D cmd->data; + + sdhci_initialize_data(host, data); + + sdhci_prepare_dma(host, data); =20 sdhci_set_block_info(host, data); } @@ -1521,7 +1529,7 @@ static void sdhci_set_mrq_done(struct sdhci_host *hos= t, struct mmc_request *mrq) WARN_ON(i >=3D SDHCI_MAX_MRQS); } =20 -static void __sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request= *mrq) +void __sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq) { if (host->cmd && host->cmd->mrq =3D=3D mrq) host->cmd =3D NULL; @@ -1545,15 +1553,17 @@ static void __sdhci_finish_mrq(struct sdhci_host *h= ost, struct mmc_request *mrq) if (!sdhci_has_requests(host)) sdhci_led_deactivate(host); } +EXPORT_SYMBOL_GPL(__sdhci_finish_mrq); =20 -static void sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *= mrq) +void sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq) { __sdhci_finish_mrq(host, mrq); =20 queue_work(host->complete_wq, &host->complete_work); } +EXPORT_SYMBOL_GPL(sdhci_finish_mrq); =20 -static void __sdhci_finish_data(struct sdhci_host *host, bool sw_data_time= out) +void __sdhci_finish_data_common(struct sdhci_host *host, bool defer_reset) { struct mmc_command *data_cmd =3D host->data_cmd; struct mmc_data *data =3D host->data; @@ -1566,7 +1576,9 @@ static void __sdhci_finish_data(struct sdhci_host *ho= st, bool sw_data_timeout) * conditions. */ if (data->error) { - if (!host->cmd || host->cmd =3D=3D data_cmd) + if (defer_reset) + host->pending_reset =3D true; + else if (!host->cmd || host->cmd =3D=3D data_cmd) sdhci_reset_for(host, REQUEST_ERROR); else sdhci_reset_for(host, REQUEST_ERROR_DATA_ONLY); @@ -1587,6 +1599,14 @@ static void __sdhci_finish_data(struct sdhci_host *h= ost, bool sw_data_timeout) data->bytes_xfered =3D 0; else data->bytes_xfered =3D data->blksz * data->blocks; +} +EXPORT_SYMBOL_GPL(__sdhci_finish_data_common); + +static void __sdhci_finish_data(struct sdhci_host *host, bool sw_data_time= out) +{ + struct mmc_data *data =3D host->data; + + __sdhci_finish_data_common(host, false); =20 /* * Need to send CMD12 if - @@ -1721,8 +1741,8 @@ static bool sdhci_send_command(struct sdhci_host *hos= t, struct mmc_command *cmd) return true; } =20 -static bool sdhci_present_error(struct sdhci_host *host, - struct mmc_command *cmd, bool present) +bool sdhci_present_error(struct sdhci_host *host, + struct mmc_command *cmd, bool present) { if (!present || host->flags & SDHCI_DEVICE_DEAD) { cmd->error =3D -ENOMEDIUM; @@ -1731,6 +1751,7 @@ static bool sdhci_present_error(struct sdhci_host *ho= st, =20 return false; } +EXPORT_SYMBOL_GPL(sdhci_present_error); =20 static bool sdhci_send_command_retry(struct sdhci_host *host, struct mmc_command *cmd, diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index 5f416bc783bd..c636808139d5 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -831,6 +831,14 @@ static inline void sdhci_read_caps(struct sdhci_host *= host) } =20 bool sdhci_needs_reset(struct sdhci_host *host, struct mmc_request *mrq); +bool sdhci_data_line_cmd(struct mmc_command *cmd); +void sdhci_mod_timer(struct sdhci_host *host, struct mmc_request *mrq, uns= igned long timeout); +void sdhci_initialize_data(struct sdhci_host *host, struct mmc_data *data); +void sdhci_prepare_dma(struct sdhci_host *host, struct mmc_data *data); +void __sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq); +void sdhci_finish_mrq(struct sdhci_host *host, struct mmc_request *mrq); +void __sdhci_finish_data_common(struct sdhci_host *host, bool defer_reset); +bool sdhci_present_error(struct sdhci_host *host, struct mmc_command *cmd,= bool present); u16 sdhci_calc_clk(struct sdhci_host *host, unsigned int clock, unsigned int *actual_clock); void sdhci_set_clock(struct sdhci_host *host, unsigned int clock); --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) (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 7B8131DC1BF; Fri, 13 Sep 2024 10:30:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223408; cv=none; b=OoWS4U6zE3fH46EXtm9hiB7fHBYEsN/dGdDKTr7pZ0HZzHsdlTmNdTeKIo0QpJzHuJAc16rHqY8r71rtCRhE7qrq3nTMDYct1BH5jEy0Mhw95DjKVYVRcHP4oAo7DiONLt/TSFqpD3Wz1xUfkHwBnQrS6pRChWLyJgNF5vs3/nU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223408; c=relaxed/simple; bh=v4MM9bGqXsTwGu4en4i1RloVtI86bYOecflv6HHdnis=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UvNuuUiEI/93OYX+CtNq9CXv/sMw9hbLvgodgA+kwKVNnrYo2ubqFF+xtBPo2gpm1LDvHqqP4FqSEgc7Bb8axAzBS6GHQ2kVXbtFnKGWzQCiW9b2OX4X0qMvGOaSeASVBHqltqpIQRs2S7GbFFLdUn82cWNUIqYJYM8803luY68= 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=VS42Pn/6; arc=none smtp.client-ip=209.85.210.181 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="VS42Pn/6" Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-7191fb54147so1406904b3a.2; Fri, 13 Sep 2024 03:30:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223407; x=1726828207; 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=pefaTk8qKKbtSAgriHJ425KtY2+eFqYfJpkB9h3wzgM=; b=VS42Pn/67n1rTORQ9qB/vaBisDJm1V7QvUwj3G/opMulz4BzxudX2QGQK3Ymc2W38X DqAcDon1UOowclQauZYNKG/dIGyIq+a+7nF5aKeAAa+XDkXdPBEajrjVaHS7Nxg/4w1s dM5bn3YTYWYjaleLzgh6DF6yA6WawMsz1qLx0BgychgD+3XZ0Xj7H7FReegVUEdVnVPQ 0qUnohEivOpy3btazeS8hpM+ofPjxC4pgGV5GK9oJRbiNiObT0Lijns3k717t9a5aB1T Ankn0/+R6lYbNzGNjJDCB3Ha783S9LR2W78bzvas/zxD3fL3/TCusTB2Y/M0Q3JHD9fo Chpw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223407; x=1726828207; 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=pefaTk8qKKbtSAgriHJ425KtY2+eFqYfJpkB9h3wzgM=; b=Pg+a48pH3A8sEhIWuhgfxf0bJiz1nGv5cxuAfWHcv84ZBN0oXR6ZqRdwJjGl/a9WfI Ds1C6F0UNw31Eqx6OCRvA4QJl16JXjazRmmR3oCJzgMfwy7NtSnD3g6TIF7PyQySM1m6 aye3gHTPYRvsFNkeKHJJyQI85bzu2m6n3/m4EfYUm7SWn23wjtaChQ4jQ11WbU+8iu83 dimZLIIjVCpOhlQLWskLECCLmdGKCi3bhYvLb67W8UPXmzSs2NQGLEW65wco4C35uU6I EeUF0anMHNUuAEWQYlgb5Aj4UtvAB+sWmJYJ/9nXG2Mzmc2+J4rtmPOq5G7uT3KNG1Mz 9Qeg== X-Forwarded-Encrypted: i=1; AJvYcCWzMzryOEPs7PzR+w3Bvi75I5yJK4B185MpQLtDT5wbDjkstVi5rKL4i3bZVKXKffbY0NiSoUMjxc/r20k=@vger.kernel.org X-Gm-Message-State: AOJu0Yzr0sViV5xlPU5RgzgQlMc5v4CInb5a4Cv0JSTKRwxR6B7o+cr5 fcd0ibUe49R7ecBtc/zaaivIO2XLA72/cD8dn/3PuSn9vpvKlD4S X-Google-Smtp-Source: AGHT+IE7g4H2FNwLVup/XTs5DIU5atEGKDPhco31O1iqlVJvBjg34dMyEzdSr0lL/jcwQVg8jV2xCw== X-Received: by 2002:a05:6a00:4b55:b0:718:d7ac:6342 with SMTP id d2e1a72fcca58-7192609100amr9545361b3a.13.1726223406700; Fri, 13 Sep 2024 03:30:06 -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.30.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:30:06 -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 Subject: [PATCH V22 19/22] mmc: sdhci-uhs2: add pre-detect_init hook Date: Fri, 13 Sep 2024 18:28:33 +0800 Message-Id: <20240913102836.6144-20-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: Ben Chuang This "pre" hook for detect_init(), uhs2_pre_detect_init, will be required to enable UHS-II support, at least, on GL9755. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Acked-by: Adrian Hunter --- drivers/mmc/host/sdhci-uhs2.c | 3 +++ drivers/mmc/host/sdhci.h | 1 + 2 files changed, 4 insertions(+) diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c index d99ea05098cb..c488c6d56015 100644 --- a/drivers/mmc/host/sdhci-uhs2.c +++ b/drivers/mmc/host/sdhci-uhs2.c @@ -413,6 +413,9 @@ static int sdhci_uhs2_do_detect_init(struct mmc_host *m= mc) =20 DBG("Begin do uhs2 detect init.\n"); =20 + if (host->ops && host->ops->uhs2_pre_detect_init) + host->ops->uhs2_pre_detect_init(host); + if (sdhci_uhs2_interface_detect(host)) { pr_warn("%s: cannot detect UHS2 interface.\n", mmc_hostname(host->mmc)); return -EIO; diff --git a/drivers/mmc/host/sdhci.h b/drivers/mmc/host/sdhci.h index c636808139d5..cd0e35a80542 100644 --- a/drivers/mmc/host/sdhci.h +++ b/drivers/mmc/host/sdhci.h @@ -723,6 +723,7 @@ struct sdhci_ops { struct mmc_request *mrq); void (*dump_vendor_regs)(struct sdhci_host *host); void (*dump_uhs2_regs)(struct sdhci_host *host); + void (*uhs2_pre_detect_init)(struct sdhci_host *host); }; =20 #ifdef CONFIG_MMC_SDHCI_IO_ACCESSORS --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) (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 02D881D86C2; Fri, 13 Sep 2024 10:30:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.169 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223413; cv=none; b=tDFAsI+Bn0UYm6JgQs427SNBSj/UixkfCFJTa5uKwqP6Fwl0Qe3lOXlTYlccyVGIA3hLRpc+p61gt7oNJfO4gH+Lx12lt814wSIyJ0ROk370pqNBxbG7bigTItnM0THT4buVUk2sD/n0frVNZD62S6F9D8NNinF2+nj9J9gK74M= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223413; c=relaxed/simple; bh=wwTPC4r8iYAP8GeBuLmgFlyM4VpaIOspAq1+/oVWpDQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Nggj7TpAq99wVT0kpzjuEmRGVScevbH2hAKpR/Rh0pC33S9ZAvA2UR9IQvwJvd7bRnb566ui8tqv+W8FIoODQDwpRHnijY5lS/SE2SLfCkSGEkS2GCMDCg6Lp700wVWFUtFVXZluIDxXVYBdYXPIroLFQ/ChwEooKnqkCO1D3+s= 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=iPWGELuw; arc=none smtp.client-ip=209.85.210.169 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="iPWGELuw" Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-718d6ad6050so682990b3a.0; Fri, 13 Sep 2024 03:30:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223411; x=1726828211; 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=nnvrWqmELtAkmW+kIijtP880LPZaPGwktrrUKOc9JZg=; b=iPWGELuwob5X/rL3aR4y7ptBhriDhH3Rz/stCqF453AecSWu8E/M8TyXycwF/6VrYU p/HjYuARkOjPGTNhZZ9/QnW3JS3fycqXh6t1Ygd4JPsUk3OTYDG0rzeqPViIUYYikR/O w96imaMUnFtzWtvWuioihoF1FWKQmiWvEOMGMyZuQE1H8Kf3T6rwGZBhsJ3CZBCzmfW7 zZAKHcUyjkFg54EgoXq8lkb7iptwblFzLY4WsqruVehiVM61q9ly0ATTEj1hLQFQDMau 9Nw8ukWlP4zcXcSFYovQSUA12LHbGP3fAEV5gMEsLnuOQ7IIHulIjS6/fV68wRQdLDVW jcTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223411; x=1726828211; 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=nnvrWqmELtAkmW+kIijtP880LPZaPGwktrrUKOc9JZg=; b=HtTdhxblHgGyGqPxjjbly9SsBveT9tnxKxif2Zk4ZQ9lX/k17qWseQeVW3EUYsG88j 0V1UdEWyCVTNLqXSn2vefoOvitx6VuXRy3KJgvMuQYN++XafFMc0QqkRTdwONga8ZRGq 7EQDzse6+caO0VOYF8/Du/NS+aXrUsfp0TrCsIznM9W/Yo/yC51Jlq8rabDGHWMaWMYT gRz/okSKnKykfyl5390Cc6kScF3pYj3ZcyydwaU8zJ0svy27t2o6LEv+pHK8vLM9cGiY yaandrV8fNoPwrlv4IuYbAtAkR2Q/h7uYwvc/MYffMJzamIC8RP/VNjsVquD5Dj3IpRI i5+A== X-Forwarded-Encrypted: i=1; AJvYcCXpLI5AEYYG0l+XZFPojgFwTfB1E24ZlohAi9O2p2keALUDUrSse7LVBQqd/C2VnIB0HiRrqgOFZc03T8o=@vger.kernel.org X-Gm-Message-State: AOJu0YyDqIb7dOe9A1UmeCMZamgC0+H2OgKdBiKzbveTEABQhX3zddUc GuW0frKLkQXWIfEAB6mMK4LvVqktmBQjJfSWMjnZTzUxDGAI7Suf X-Google-Smtp-Source: AGHT+IGmgJsfFJulM10qMogYrsmYdj+K11pYgtG+Xqr8c3+FezyFF/+xQe1uiAJ+UvhILiSNxJBA7Q== X-Received: by 2002:a05:6a20:d807:b0:1cf:1b7d:8481 with SMTP id adf61e73a8af0-1d112e8bfc4mr3472603637.32.1726223411218; Fri, 13 Sep 2024 03:30:11 -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.30.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:30:10 -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 20/22] mmc: sdhci-pci: add UHS-II support framework Date: Fri, 13 Sep 2024 18:28:34 +0800 Message-Id: <20240913102836.6144-21-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 patch prepares for adding UHS-II support at a specific UHS-II capable sdhci-pci controller, GL9755 for now. Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih Acked-by: Adrian Hunter --- Updates in V8: - Add config select MMC_SDHCI_UHS2 in Kconfig. --- drivers/mmc/host/Kconfig | 1 + drivers/mmc/host/sdhci-pci-core.c | 16 +++++++++++++++- drivers/mmc/host/sdhci-pci.h | 3 +++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/Kconfig b/drivers/mmc/host/Kconfig index f636af8a98df..70d37a8c3613 100644 --- a/drivers/mmc/host/Kconfig +++ b/drivers/mmc/host/Kconfig @@ -111,6 +111,7 @@ config MMC_SDHCI_PCI tristate "SDHCI support on PCI bus" depends on MMC_SDHCI && PCI select MMC_CQHCI + select MMC_SDHCI_UHS2 select IOSF_MBI if X86 select MMC_SDHCI_IO_ACCESSORS help diff --git a/drivers/mmc/host/sdhci-pci-core.c b/drivers/mmc/host/sdhci-pci= -core.c index ed45ed0bdafd..2b300bc4a701 100644 --- a/drivers/mmc/host/sdhci-pci-core.c +++ b/drivers/mmc/host/sdhci-pci-core.c @@ -40,6 +40,7 @@ #include "sdhci.h" #include "sdhci-cqhci.h" #include "sdhci-pci.h" +#include "sdhci-uhs2.h" =20 static void sdhci_pci_hw_reset(struct sdhci_host *host); =20 @@ -2181,7 +2182,10 @@ static void sdhci_pci_remove_slot(struct sdhci_pci_s= lot *slot) if (scratch =3D=3D (u32)-1) dead =3D 1; =20 - sdhci_remove_host(slot->host, dead); + if (slot->chip->fixes && slot->chip->fixes->remove_host) + slot->chip->fixes->remove_host(slot, dead); + else + sdhci_remove_host(slot->host, dead); =20 if (slot->chip->fixes && slot->chip->fixes->remove_slot) slot->chip->fixes->remove_slot(slot, dead); @@ -2189,6 +2193,16 @@ static void sdhci_pci_remove_slot(struct sdhci_pci_s= lot *slot) sdhci_free_host(slot->host); } =20 +int sdhci_pci_uhs2_add_host(struct sdhci_pci_slot *slot) +{ + return sdhci_uhs2_add_host(slot->host); +} + +void sdhci_pci_uhs2_remove_host(struct sdhci_pci_slot *slot, int dead) +{ + sdhci_uhs2_remove_host(slot->host, dead); +} + static void sdhci_pci_runtime_pm_allow(struct device *dev) { pm_suspend_ignore_children(dev, 1); diff --git a/drivers/mmc/host/sdhci-pci.h b/drivers/mmc/host/sdhci-pci.h index 153704f812ed..e807c039a8b1 100644 --- a/drivers/mmc/host/sdhci-pci.h +++ b/drivers/mmc/host/sdhci-pci.h @@ -145,6 +145,7 @@ struct sdhci_pci_fixes { int (*probe_slot) (struct sdhci_pci_slot *); int (*add_host) (struct sdhci_pci_slot *); void (*remove_slot) (struct sdhci_pci_slot *, int); + void (*remove_host) (struct sdhci_pci_slot *, int); =20 #ifdef CONFIG_PM_SLEEP int (*suspend) (struct sdhci_pci_chip *); @@ -189,6 +190,8 @@ static inline void *sdhci_pci_priv(struct sdhci_pci_slo= t *slot) return (void *)slot->private; } =20 +int sdhci_pci_uhs2_add_host(struct sdhci_pci_slot *slot); +void sdhci_pci_uhs2_remove_host(struct sdhci_pci_slot *slot, int dead); #ifdef CONFIG_PM_SLEEP int sdhci_pci_resume_host(struct sdhci_pci_chip *chip); #endif --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pg1-f177.google.com (mail-pg1-f177.google.com [209.85.215.177]) (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 ACBB81DC754; Fri, 13 Sep 2024 10:30:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223418; cv=none; b=kFx/coPJVR+Eo0yBeKN56nYbdS+5kLfN9RfWBMb/uQWENP6bR06do5XiYIkS7YI/X60BUB1lhhIl9SU/6KWZKZqF2QixEdxeijZAytuVvr1MSsMZAb6wWgB3FGAHoEU5ZOybRog8bvIKJAtyH7mPRewISw2RQByP37Ic/M6npw0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223418; c=relaxed/simple; bh=yBPWMM+UcxmD8WxaMTZD9fPg9PqlDCKf90o5THqyUNM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=U5tJ4nCw/LHoCnz7V89IzEWgcFGP5S5zp3YJhTK3Ozc+gDJ6TTS9EtBunFt7FWTWnuy9aKGngWXBzRx2T053vrac3EHdLokCV8bbimmMHah4lYX+4CO0kQFaoYnUQeH05B5HgU8/tMB0tbQbYCwa1hp/i5y5tmL5/OjX8nlhkuc= 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=eW31lDLt; arc=none smtp.client-ip=209.85.215.177 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="eW31lDLt" Received: by mail-pg1-f177.google.com with SMTP id 41be03b00d2f7-7cd8803fe0aso1478664a12.0; Fri, 13 Sep 2024 03:30:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223416; x=1726828216; 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=ec3ffwGVG4T3zOAIwR5JyB4bVTuiuJxx1Z4oCNcuYcM=; b=eW31lDLtyuOW0TVEAUdJlzIX6qEsORh64qKFGNnt7h5hk+1Zt1QC8PmT2sMLKGmgQe 75lEWgUD4DPfJUZIT1OORbNccrtWyObASF0cato+qMhw1tY3CmbzKeMG+EETme8yGD8G iMqiTx7Wxhqv43y+F5gkhq09klcyKI8PnoCYZamSpa2rFyGwZSC00KsL/qLLQgOQxAyQ Oikhoi2r4M0ZL0roBoGE3+m2OPS/pHjrJP2MEiJOzCQWg5YARVC7U2KwUrUxowyQiUL7 Fp715vyRbCnuPlSDKJjhjbZkME+Tx4L9EeNxUsWyjV5MGcpBlvHqldfnh/OCmD8FoxYV /rDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223416; x=1726828216; 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=ec3ffwGVG4T3zOAIwR5JyB4bVTuiuJxx1Z4oCNcuYcM=; b=mxxy5y2G4W36of5+vIS0hhoxNjDhUdb8bqVmWYaDu7b2K2VFNlAnHTcKIEbLqOkad5 Vdj86NiTUuNVj2n8XN3L9pJFNXiPpLEcMabQ6W1NicGohXIzdUPa1jsGFZ8nSPPVzhR7 e+0Kn2Aek8lucfZIo9yWlnG5f168d4c0+BQvANe5XIMISG+pBfBOlzM6Nij3M9C1Y+sk SvpPrZHX/t/uaTJq+An35RMFrVIgISd4781rGQ9tM0VjgDHyOaNeuQ7tXc3nHRM3+0Mx DBXuL9dztuSzFslm0RR5m0UO21ENPTNUqDYLGi0HNJ8+IuVCy/160Ir/5s55ltq7Zbl8 u+9A== X-Forwarded-Encrypted: i=1; AJvYcCVXsFja2bGie6M2+7d2BEEgviUUzDlq4g+icDMSJivxeG9/i0SVLysTHB3226JkFp4MT1VMojrxcGAvIYU=@vger.kernel.org X-Gm-Message-State: AOJu0Yz+qgsDzX9giOqop8smVYNKD+0RCwJ0NYpoKFKhlzzOloGeNbWo cksX2E/6WZ9G3OGpn1oeuLWidiwLFxyKgwkaG95UpAz35LM1/rqN X-Google-Smtp-Source: AGHT+IHjegn2vsEdpNBWy/EAK3wUYLv7Sq4Q1GCDlbF1hGt7Ezengttwi4JS31Hard3bDK61p71mWw== X-Received: by 2002:a05:6a20:c703:b0:1cf:39ea:945e with SMTP id adf61e73a8af0-1cf75e77015mr7581550637.5.1726223415833; Fri, 13 Sep 2024 03:30:15 -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.30.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:30:15 -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 , Lucas Lai Subject: [PATCH V22 21/22] mmc: sdhci-pci-gli: enable UHS-II mode for GL9755 Date: Fri, 13 Sep 2024 18:28:35 +0800 Message-Id: <20240913102836.6144-22-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 Changes are: * Disable GL9755 overcurrent interrupt when power on/off on UHS-II. * Enable the internal clock when do reset on UHS-II mode. * Increase timeout value before detecting UHS-II interface. * Add vendor settings fro UHS-II mode. * Remove sdhci_gli_enable_internal_clock functon unused clk_ctrl variable. * Make a function sdhci_gli_wait_software_reset_done() for gl9755 reset. * Remove unnecessary code from sdhci_gl9755_reset(). Signed-off-by: Ben Chuang Signed-off-by: AKASHI Takahiro Signed-off-by: Victor Shih Signed-off-by: Lucas Lai Acked-by: Adrian Hunter --- Updates in V21: - Remove unnecessary code from sdhci_gl9755_reset(). Updates in V20: - Remove sdhci_gli_enable_internal_clock functon unused clk_ctrl variable. - Make a function sdhci_gli_wait_software_reset_done() for gl9755 reset. Updates in V19: - Add sdhci_gli_enable_internal_clock() to simplify the code in the sdhci_gl9755_reset(). Updates in V17: - Rname gl9755_overcurrent_event_enable() to sdhci_gli_overcurrent_event_enable(). Updates in V15: - Adjust gl9755_vendor_init() to the correct function. Updates in V13: - Ues uhs2_sd_tran to stead MMC_UHS2_SD_TRAN. Updates in V9: - Rename gl9755_pre_detect_init() to sdhci_gli_pre_detect_init(). - Rename gl9755_uhs2_reset_sd_tran() to sdhci_gli_uhs2_reset_sd_tran(). Updates in V8: - Use sdhci_get_vdd_value() to simplify code in gl9755_set_power(). - Use read_poll_timeout_atomic() to simplify code in sdhci_wait_clock_stable(). - Use read_poll_timeout_atomic() to simplify code in sdhci_gl9755_reset(). Updates in V7: - Drop using gl9755_post_attach_sd(). --- drivers/mmc/host/sdhci-pci-gli.c | 235 ++++++++++++++++++++++++++++++- 1 file changed, 234 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/sdhci-pci-gli.c b/drivers/mmc/host/sdhci-pci-= gli.c index 0f81586a19df..708138eecaa7 100644 --- a/drivers/mmc/host/sdhci-pci-gli.c +++ b/drivers/mmc/host/sdhci-pci-gli.c @@ -18,6 +18,7 @@ #include "sdhci-cqhci.h" #include "sdhci-pci.h" #include "cqhci.h" +#include "sdhci-uhs2.h" =20 /* Genesys Logic extra registers */ #define SDHCI_GLI_9750_WT 0x800 @@ -139,9 +140,36 @@ =20 #define PCI_GLI_9755_PLLSSC 0x68 #define PCI_GLI_9755_PLLSSC_PPM GENMASK(15, 0) +#define PCI_GLI_9755_PLLSSC_RTL BIT(24) +#define GLI_9755_PLLSSC_RTL_VALUE 0x1 +#define PCI_GLI_9755_PLLSSC_TRANS_PASS BIT(27) +#define GLI_9755_PLLSSC_TRANS_PASS_VALUE 0x1 +#define PCI_GLI_9755_PLLSSC_RECV GENMASK(29, 28) +#define GLI_9755_PLLSSC_RECV_VALUE 0x0 +#define PCI_GLI_9755_PLLSSC_TRAN GENMASK(31, 30) +#define GLI_9755_PLLSSC_TRAN_VALUE 0x3 + +#define PCI_GLI_9755_UHS2_PLL 0x6C +#define PCI_GLI_9755_UHS2_PLL_SSC GENMASK(9, 8) +#define GLI_9755_UHS2_PLL_SSC_VALUE 0x0 +#define PCI_GLI_9755_UHS2_PLL_DELAY BIT(18) +#define GLI_9755_UHS2_PLL_DELAY_VALUE 0x1 +#define PCI_GLI_9755_UHS2_PLL_PDRST BIT(27) +#define GLI_9755_UHS2_PLL_PDRST_VALUE 0x1 =20 #define PCI_GLI_9755_SerDes 0x70 +#define PCI_GLI_9755_UHS2_SERDES_INTR GENMASK(2, 0) +#define GLI_9755_UHS2_SERDES_INTR_VALUE 0x3 +#define PCI_GLI_9755_UHS2_SERDES_ZC1 BIT(3) +#define GLI_9755_UHS2_SERDES_ZC1_VALUE 0x0 +#define PCI_GLI_9755_UHS2_SERDES_ZC2 GENMASK(7, 4) +#define GLI_9755_UHS2_SERDES_ZC2_DEFAULT 0xB +#define GLI_9755_UHS2_SERDES_ZC2_SANDISK 0x0 #define PCI_GLI_9755_SCP_DIS BIT(19) +#define PCI_GLI_9755_UHS2_SERDES_TRAN GENMASK(27, 24) +#define GLI_9755_UHS2_SERDES_TRAN_VALUE 0xC +#define PCI_GLI_9755_UHS2_SERDES_RECV GENMASK(31, 28) +#define GLI_9755_UHS2_SERDES_RECV_VALUE 0xF =20 #define PCI_GLI_9755_MISC 0x78 #define PCI_GLI_9755_MISC_SSC_OFF BIT(26) @@ -779,6 +807,203 @@ static void gl9755_hw_setting(struct sdhci_pci_slot *= slot) gl9755_wt_off(pdev); } =20 +static void gl9755_vendor_init(struct sdhci_host *host) +{ + struct sdhci_pci_slot *slot =3D sdhci_priv(host); + struct pci_dev *pdev =3D slot->chip->pdev; + u32 serdes; + u32 pllssc; + u32 uhs2_pll; + + gl9755_wt_on(pdev); + + pci_read_config_dword(pdev, PCI_GLI_9755_SerDes, &serdes); + serdes &=3D ~PCI_GLI_9755_UHS2_SERDES_TRAN; + serdes |=3D FIELD_PREP(PCI_GLI_9755_UHS2_SERDES_TRAN, + GLI_9755_UHS2_SERDES_TRAN_VALUE); + serdes &=3D ~PCI_GLI_9755_UHS2_SERDES_RECV; + serdes |=3D FIELD_PREP(PCI_GLI_9755_UHS2_SERDES_RECV, + GLI_9755_UHS2_SERDES_RECV_VALUE); + serdes &=3D ~PCI_GLI_9755_UHS2_SERDES_INTR; + serdes |=3D FIELD_PREP(PCI_GLI_9755_UHS2_SERDES_INTR, + GLI_9755_UHS2_SERDES_INTR_VALUE); + serdes &=3D ~PCI_GLI_9755_UHS2_SERDES_ZC1; + serdes |=3D FIELD_PREP(PCI_GLI_9755_UHS2_SERDES_ZC1, + GLI_9755_UHS2_SERDES_ZC1_VALUE); + serdes &=3D ~PCI_GLI_9755_UHS2_SERDES_ZC2; + serdes |=3D FIELD_PREP(PCI_GLI_9755_UHS2_SERDES_ZC2, + GLI_9755_UHS2_SERDES_ZC2_DEFAULT); + pci_write_config_dword(pdev, PCI_GLI_9755_SerDes, serdes); + + pci_read_config_dword(pdev, PCI_GLI_9755_UHS2_PLL, &uhs2_pll); + uhs2_pll &=3D ~PCI_GLI_9755_UHS2_PLL_SSC; + uhs2_pll |=3D FIELD_PREP(PCI_GLI_9755_UHS2_PLL_SSC, + GLI_9755_UHS2_PLL_SSC_VALUE); + uhs2_pll &=3D ~PCI_GLI_9755_UHS2_PLL_DELAY; + uhs2_pll |=3D FIELD_PREP(PCI_GLI_9755_UHS2_PLL_DELAY, + GLI_9755_UHS2_PLL_DELAY_VALUE); + uhs2_pll &=3D ~PCI_GLI_9755_UHS2_PLL_PDRST; + uhs2_pll |=3D FIELD_PREP(PCI_GLI_9755_UHS2_PLL_PDRST, + GLI_9755_UHS2_PLL_PDRST_VALUE); + pci_write_config_dword(pdev, PCI_GLI_9755_UHS2_PLL, uhs2_pll); + + pci_read_config_dword(pdev, PCI_GLI_9755_PLLSSC, &pllssc); + pllssc &=3D ~PCI_GLI_9755_PLLSSC_RTL; + pllssc |=3D FIELD_PREP(PCI_GLI_9755_PLLSSC_RTL, + GLI_9755_PLLSSC_RTL_VALUE); + pllssc &=3D ~PCI_GLI_9755_PLLSSC_TRANS_PASS; + pllssc |=3D FIELD_PREP(PCI_GLI_9755_PLLSSC_TRANS_PASS, + GLI_9755_PLLSSC_TRANS_PASS_VALUE); + pllssc &=3D ~PCI_GLI_9755_PLLSSC_RECV; + pllssc |=3D FIELD_PREP(PCI_GLI_9755_PLLSSC_RECV, + GLI_9755_PLLSSC_RECV_VALUE); + pllssc &=3D ~PCI_GLI_9755_PLLSSC_TRAN; + pllssc |=3D FIELD_PREP(PCI_GLI_9755_PLLSSC_TRAN, + GLI_9755_PLLSSC_TRAN_VALUE); + pci_write_config_dword(pdev, PCI_GLI_9755_PLLSSC, pllssc); + + gl9755_wt_off(pdev); +} + +static void sdhci_gli_pre_detect_init(struct sdhci_host *host) +{ + /* Need more time on UHS2 detect flow */ + sdhci_writeb(host, 0xA7, SDHCI_UHS2_TIMER_CTRL); +} + +static void sdhci_gli_overcurrent_event_enable(struct sdhci_host *host, bo= ol enable) +{ + u32 mask; + + mask =3D sdhci_readl(host, SDHCI_SIGNAL_ENABLE); + if (enable) + mask |=3D SDHCI_INT_BUS_POWER; + else + mask &=3D ~SDHCI_INT_BUS_POWER; + + sdhci_writel(host, mask, SDHCI_SIGNAL_ENABLE); + + mask =3D sdhci_readl(host, SDHCI_INT_ENABLE); + if (enable) + mask |=3D SDHCI_INT_BUS_POWER; + else + mask &=3D ~SDHCI_INT_BUS_POWER; + + sdhci_writel(host, mask, SDHCI_INT_ENABLE); +} + +static void gl9755_set_power(struct sdhci_host *host, unsigned char mode, + unsigned short vdd) +{ + u8 pwr =3D 0; + + if (mode !=3D MMC_POWER_OFF) { + pwr =3D sdhci_get_vdd_value(vdd); + if (!pwr) + WARN(1, "%s: Invalid vdd %#x\n", mmc_hostname(host->mmc), vdd); + pwr |=3D SDHCI_VDD2_POWER_180; + } + + if (host->pwr =3D=3D pwr) + return; + + host->pwr =3D pwr; + + if (pwr =3D=3D 0) { + sdhci_gli_overcurrent_event_enable(host, false); + sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); + } else { + sdhci_gli_overcurrent_event_enable(host, false); + sdhci_writeb(host, 0, SDHCI_POWER_CONTROL); + + pwr |=3D (SDHCI_POWER_ON | SDHCI_VDD2_POWER_ON); + + sdhci_writeb(host, pwr & 0xf, SDHCI_POWER_CONTROL); + /* wait stable */ + mdelay(5); + sdhci_writeb(host, pwr, SDHCI_POWER_CONTROL); + /* wait stable */ + mdelay(5); + sdhci_gli_overcurrent_event_enable(host, true); + } +} + +static bool sdhci_wait_clock_stable(struct sdhci_host *host) +{ + u16 clk =3D 0; + + if (read_poll_timeout_atomic(sdhci_readw, clk, (clk & SDHCI_CLOCK_INT_STA= BLE), + 10, 20000, false, host, SDHCI_CLOCK_CONTROL)) { + pr_err("%s: Internal clock never stabilised.\n", mmc_hostname(host->mmc)= ); + sdhci_dumpregs(host); + return false; + } + return true; +} + +static void sdhci_gli_enable_internal_clock(struct sdhci_host *host) +{ + u16 ctrl2; + + ctrl2 =3D sdhci_readw(host, SDHCI_HOST_CONTROL2); + + sdhci_writew(host, SDHCI_CLOCK_INT_EN, SDHCI_CLOCK_CONTROL); + + if (!((ctrl2 & SDHCI_CTRL_V4_MODE) && + (ctrl2 & SDHCI_CTRL_UHS2_ENABLE))) { + sdhci_wait_clock_stable(host); + sdhci_writew(host, SDHCI_CTRL_V4_MODE, SDHCI_HOST_CONTROL2); + } +} + +static int sdhci_gli_wait_software_reset_done(struct sdhci_host *host, u8 = mask) +{ + u8 rst; + + /* hw clears the bit when it's done */ + if (read_poll_timeout_atomic(sdhci_readb, rst, !(rst & mask), + 10, 100000, false, host, SDHCI_SOFTWARE_RESET)) { + pr_err("%s: Reset 0x%x never completed.\n", mmc_hostname(host->mmc), (in= t)mask); + sdhci_dumpregs(host); + /* manual clear */ + sdhci_writeb(host, 0, SDHCI_SOFTWARE_RESET); + return -ETIMEDOUT; + } + + return 0; +} + +static void sdhci_gli_uhs2_reset_sd_tran(struct sdhci_host *host) +{ + /* do this on UHS2 mode */ + if (host->mmc->uhs2_sd_tran) { + sdhci_uhs2_reset(host, SDHCI_UHS2_SW_RESET_SD); + sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); + sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); + sdhci_uhs2_clear_set_irqs(host, + SDHCI_INT_ALL_MASK, + SDHCI_UHS2_INT_ERROR_MASK); + } +} + +static void sdhci_gl9755_reset(struct sdhci_host *host, u8 mask) +{ + /* need internal clock */ + if (mask & SDHCI_RESET_ALL) + sdhci_gli_enable_internal_clock(host); + + sdhci_writeb(host, mask, SDHCI_SOFTWARE_RESET); + + /* reset sd-tran on UHS2 mode if need to reset cmd/data */ + if ((mask & SDHCI_RESET_CMD) | (mask & SDHCI_RESET_DATA)) + sdhci_gli_uhs2_reset_sd_tran(host); + + if (mask & SDHCI_RESET_ALL) + host->clock =3D 0; + + sdhci_gli_wait_software_reset_done(host, mask); +} + static inline void gl9767_vhs_read(struct pci_dev *pdev) { u32 vhs_enable; @@ -1086,6 +1311,7 @@ static int gli_probe_slot_gl9755(struct sdhci_pci_slo= t *slot) gli_pcie_enable_msi(slot); slot->host->mmc->caps2 |=3D MMC_CAP2_NO_SDIO; sdhci_enable_v4_mode(host); + gl9755_vendor_init(host); =20 return 0; } @@ -1524,17 +1750,24 @@ static const struct sdhci_ops sdhci_gl9755_ops =3D { .read_w =3D sdhci_gli_readw, .read_b =3D sdhci_gli_readb, .set_clock =3D sdhci_gl9755_set_clock, + .set_power =3D gl9755_set_power, .enable_dma =3D sdhci_pci_enable_dma, .set_bus_width =3D sdhci_set_bus_width, - .reset =3D sdhci_reset, + .reset =3D sdhci_gl9755_reset, .set_uhs_signaling =3D sdhci_set_uhs_signaling, .voltage_switch =3D sdhci_gli_voltage_switch, + .dump_uhs2_regs =3D sdhci_uhs2_dump_regs, + .set_timeout =3D sdhci_uhs2_set_timeout, + .irq =3D sdhci_uhs2_irq, + .uhs2_pre_detect_init =3D sdhci_gli_pre_detect_init, }; =20 const struct sdhci_pci_fixes sdhci_gl9755 =3D { .quirks =3D SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, .quirks2 =3D SDHCI_QUIRK2_BROKEN_DDR50, .probe_slot =3D gli_probe_slot_gl9755, + .add_host =3D sdhci_pci_uhs2_add_host, + .remove_host =3D sdhci_pci_uhs2_remove_host, .ops =3D &sdhci_gl9755_ops, #ifdef CONFIG_PM_SLEEP .resume =3D sdhci_pci_gli_resume, --=20 2.25.1 From nobody Fri Nov 29 23:36:22 2024 Received: from mail-pf1-f175.google.com (mail-pf1-f175.google.com [209.85.210.175]) (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 E64E91DC73E; Fri, 13 Sep 2024 10:30:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.175 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223422; cv=none; b=deEOGBm/sC06TYCNi+bYED4Q3xaK1CvWjUsR8+K2Os6Q2CuFC7dacVC/ntD9Ok7fJI2ZUluIzfgN/707Sp+gBwh6bGKJPI8UYnlVahKPSEEU/3onmbr/JbI4kBmo59ajQvcPh16I+e/0zkF7wWcN0EjZFVmQIW4u0q4hpVj52C8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726223422; c=relaxed/simple; bh=qmf9WfIviTtJwSgU5Q0mUQTSQ+PhALIXkUuHCsZsb04=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=j/Kvcxippozd3Q5aZSA7epXnCzAwtkNtrZkJMXzDWwqChNTtY8EcM+4xS+A3fHZKfGRc4oXm9YJF3ZMY/uTdaprJqLs0sV/jV7V0HnmIDUqpNt5AZuEDgkcAN7LITgkqO/e6VAS7m/FasMS+SKMXcX3q1yCQ16DlNToGePjul1A= 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=h+jN4lGl; arc=none smtp.client-ip=209.85.210.175 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="h+jN4lGl" Received: by mail-pf1-f175.google.com with SMTP id d2e1a72fcca58-71798661a52so1514827b3a.0; Fri, 13 Sep 2024 03:30:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726223420; x=1726828220; 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=Gbe7qhvT8ntO58X7PAXaQ3B+VwyPxi6oPgIOkOOFc4A=; b=h+jN4lGl6bRizy1wjjrVsXaYoQdpbD8ZP4kb8OTU1CoNJXc0qWuSj6h/m+HM9oxxK1 g2QkqOvvfsuRFqRNQ2EGBkXbSZ0+6hEvOWhu2nK/pTbK5sxKAnIU9vvdu+0HjIaPG1qe eoFH1bbWOEbuvO7z80a8tI6sOZ6l2KFgwMHiFFrzxKl/A32A8P2/9z6iWPnIg7EiTGvM YLIBZhuhxfpto+wjqaNptmu2WZnlTpva7QYwGVmzn2AG47P3J2QxqNXC7O9DYSPluMZ5 wIFoiawLnKDbJBTF4yXKw1aM+lwpM3cDNPMhzps8sHdWG/l51O1IKaLEkdzbhWjQAK60 tH7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726223420; x=1726828220; 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=Gbe7qhvT8ntO58X7PAXaQ3B+VwyPxi6oPgIOkOOFc4A=; b=FDBkZUfyD/EkIH/AQW48Sfx7tjDXh0pckdOdHitz2o/3MQF04HXh7RHlRs+51Hko6l 8GV1qD1kmqv12g4YSOVMK5H3kU2FXpWCDLRr6cPrqc1YSjNpQQtWPCRJFJVduTDoGfpB 50blpaQVriSBn8aBzwh6T9o2y9i48t78g8uzEQUbXGoCKY6vZJ5T02AOIr3hFAGbyqrY 0YKHg/j/mz24b5dGanKDO7S3JAQ0VNmepns3AqWZgBRdnTwuOZ1Tuph+SIHBSFsrwq3b 0IGya8b1EaR3e9gC8v6COX+qHnIcMsUHHZ5TM2Kr0em+HcorOTmlOele1hpcGV5iXLKZ 3i4A== X-Forwarded-Encrypted: i=1; AJvYcCUpqB/C1KtkE33cvbkGOGcOsgF6dRyZ9P0Ebca0L6BMgh2lBjAxVfTc/gminQf3KK4PWOCb7wXOXpW07Oc=@vger.kernel.org X-Gm-Message-State: AOJu0YwJpqq3p5x2+ZcCdbJFpKY2uDIW99Wzlbbn77jm2VXTgrFm/kKn t27n/1iPnHl7VCf/sZP+vCupymipExa/Ne62xEXhVy2C2uX18heg X-Google-Smtp-Source: AGHT+IHxTFxmRKrnbhleEqE6JxqzNirwwJ12/WWWr2Ot9bMNvdHIfhdDoOCmOr0EuN42c59dGphWcQ== X-Received: by 2002:a05:6a00:1d96:b0:714:2336:fa91 with SMTP id d2e1a72fcca58-71907f71a66mr24166023b3a.14.1726223420064; Fri, 13 Sep 2024 03:30:20 -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.30.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 Sep 2024 03:30:19 -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 , Victor Shih , Lucas Lai Subject: [PATCH V22 22/22] mmc: sdhci-pci-gli: enable UHS-II mode for GL9767 Date: Fri, 13 Sep 2024 18:28:36 +0800 Message-Id: <20240913102836.6144-23-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 Changes are: * Enable the internal clock when do reset on UHS-II mode. * Increase timeout value before detecting UHS-II interface. * Add vendor settings for UHS-II mode. * Use the function sdhci_gli_wait_software_reset_done() for gl9767 reset. * Remove unnecessary code from sdhci_gl9767_reset(). Signed-off-by: Ben Chuang Signed-off-by: Victor Shih Signed-off-by: Lucas Lai -- Updates in V21: - Remove unnecessary code from sdhci_gl9767_reset(). Updates in V20: - Use the function sdhci_gli_wait_software_reset_done() for gl9767 reset. Updates in V19: - Use sdhci_gli_enable_internal_clock() to simplify the code in the sdhci_gl9767_reset(). - Directly reading the SDHCI_PRESENT_STATE register to replace the get_cd() avoids the possibility of the get_cd() sleeping in the sdhci_gl9767_set_card_detect_debounce_time(). - Refine the position of gli_set_9767() in the sdhci_gl9767_reset(). Updates in V18: - Add new register settings for gl9767. - Add card_event in the sdhci_ops for gl9767. - Add sdhci_gl9767_set_card_detect_debounce_time() to configure the gl9767. - Adjust the sdhci_gl9767_reset() process for gl9767. Updates in V17: - Use mmc_card_uhs2() to simplify the code in the sdhci_gl9767_reset(). - Use mmc_card_uhs2() to simplify the code in the sdhci_gl9767_set_power(). - Add sdhci_gli_overcurrent_event_enable() to sdhci_gl9767_set_power(). Updates in V15: - Add gl9767 to support uhs2 function. Acked-by: Adrian Hunter --- drivers/mmc/host/sdhci-pci-gli.c | 202 ++++++++++++++++++++++++++++++- 1 file changed, 201 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/sdhci-pci-gli.c b/drivers/mmc/host/sdhci-pci-= gli.c index 708138eecaa7..cf2486ec7b9a 100644 --- a/drivers/mmc/host/sdhci-pci-gli.c +++ b/drivers/mmc/host/sdhci-pci-gli.c @@ -174,6 +174,15 @@ #define PCI_GLI_9755_MISC 0x78 #define PCI_GLI_9755_MISC_SSC_OFF BIT(26) =20 +#define SDHCI_GLI_9767_SD_HOST_OPERATION_CTL 0x508 +#define SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_CMD_CONFLICT_CHECK BIT(0) +#define SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_DEBOUNCE GENMASK(21, 16) +#define SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_DEBOUNCE_PLUG_IN_VALUE 0x= 05 +#define SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_DEBOUNCE_PLUG_OUT_VALUE 0= x3F +#define SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_DEBOUNCE_SCALE GENMASK(2= 3, 22) +#define SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_DEBOUNCE_SCALE_1MS 0x2 +#define SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_DEBOUNCE_SCALE_10MS 0x3 + #define SDHCI_GLI_9767_GM_BURST_SIZE 0x510 #define SDHCI_GLI_9767_GM_BURST_SIZE_AXI_ALWAYS_SET BIT(8) =20 @@ -210,6 +219,13 @@ #define PCIE_GLI_9767_SCR_CORE_PWR_D3_OFF BIT(21) #define PCIE_GLI_9767_SCR_CFG_RST_DATA_LINK_DOWN BIT(30) =20 +#define PCIE_GLI_9767_RESET_REG 0x8E4 +#define PCIE_GLI_9767_RESET_REG_SD_HOST_SW_RESET BIT(0) + +#define PCIE_GLI_9767_UHS2_PHY_SET_REG1 0x90C +#define PCIE_GLI_9767_UHS2_PHY_SET_REG1_SERDES_INTR GENMASK(31, 29) +#define PCIE_GLI_9767_UHS2_PHY_SET_REG1_SERDES_INTR_VALUE 0x3 + #define PCIE_GLI_9767_SDHC_CAP 0x91C #define PCIE_GLI_9767_SDHC_CAP_SDEI_RESULT BIT(5) =20 @@ -228,9 +244,15 @@ #define PCIE_GLI_9767_SD_EXPRESS_CTL_SD_EXPRESS_MODE BIT(1) =20 #define PCIE_GLI_9767_SD_DATA_MULTI_CTL 0x944 +#define PCIE_GLI_9767_SD_DATA_MULTI_CTL_SELECT_UHS2 BIT(5) +#define PCIE_GLI_9767_SD_DATA_MULTI_CTL_UHS2_SWITCH_CTL BIT(8) #define PCIE_GLI_9767_SD_DATA_MULTI_CTL_DISCONNECT_TIME GENMASK(23, 16) #define PCIE_GLI_9767_SD_DATA_MULTI_CTL_DISCONNECT_TIME_VALUE 0x64 =20 +#define PCIE_GLI_9767_UHS2_PHY_SET_REG2 0x948 +#define PCIE_GLI_9767_UHS2_PHY_SET_REG2_SSC_PPM_SETTING GENMASK(22, 2= 1) +#define PCIE_GLI_9767_UHS2_PHY_SET_REG2_SSC_PPM_SETTING_VALUE 0x0 + #define PCIE_GLI_9767_NORMAL_ERR_INT_STATUS_REG2 0x950 #define PCIE_GLI_9767_NORMAL_ERR_INT_STATUS_REG2_SDEI_COMPLETE BIT(0) =20 @@ -240,6 +262,28 @@ #define PCIE_GLI_9767_NORMAL_ERR_INT_SIGNAL_EN_REG2 0x958 #define PCIE_GLI_9767_NORMAL_ERR_INT_SIGNAL_EN_REG2_SDEI_COMPLETE_SIGNAL= _EN BIT(0) =20 +#define PCIE_GLI_9767_UHS2_CTL1 0x95C +#define PCIE_GLI_9767_UHS2_CTL1_TRANS_PASS BIT(5) +#define PCIE_GLI_9767_UHS2_CTL1_TRANS_PASS_VALUE 0x1 +#define PCIE_GLI_9767_UHS2_CTL1_DECODING_CTL BIT(6) +#define PCIE_GLI_9767_UHS2_CTL1_DECODING_CTL_VALUE 0x1 +#define PCIE_GLI_9767_UHS2_CTL1_SERDES_TRAN GENMASK(10, 7) +#define PCIE_GLI_9767_UHS2_CTL1_SERDES_TRAN_VALUE 0x3 +#define PCIE_GLI_9767_UHS2_CTL1_SERDES_RECV GENMASK(14, 11) +#define PCIE_GLI_9767_UHS2_CTL1_SERDES_RECV_VALUE 0xf +#define PCIE_GLI_9767_UHS2_CTL1_DIR_TRANS GENMASK(16, 15) +#define PCIE_GLI_9767_UHS2_CTL1_DIR_TRANS_VALUE 0x0 +#define PCIE_GLI_9767_UHS2_CTL1_DIR_RECV GENMASK(18, 17) +#define PCIE_GLI_9767_UHS2_CTL1_DIR_RECV_VALUE 0x0 +#define PCIE_GLI_9767_UHS2_CTL1_PDRST BIT(25) +#define PCIE_GLI_9767_UHS2_CTL1_PDRST_VALUE 0x1 + +#define PCIE_GLI_9767_UHS2_CTL2 0x964 +#define PCIE_GLI_9767_UHS2_CTL2_ZC GENMASK(3, 0) +#define PCIE_GLI_9767_UHS2_CTL2_ZC_VALUE 0xb +#define PCIE_GLI_9767_UHS2_CTL2_ZC_CTL BIT(6) +#define PCIE_GLI_9767_UHS2_CTL2_ZC_CTL_VALUE 0x1 + #define GLI_MAX_TUNING_LOOP 40 =20 /* Genesys Logic chipset */ @@ -1155,6 +1199,31 @@ static void sdhci_gl9767_set_clock(struct sdhci_host= *host, unsigned int clock) gl9767_vhs_read(pdev); } =20 +static void sdhci_gl9767_set_card_detect_debounce_time(struct sdhci_host *= host) +{ + u32 value; + + value =3D sdhci_readl(host, SDHCI_GLI_9767_SD_HOST_OPERATION_CTL); + value &=3D ~(SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_DEBOUNCE | + SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_DEBOUNCE_SCALE); + if (sdhci_readl(host, SDHCI_PRESENT_STATE) & SDHCI_CARD_PRESENT) + value |=3D FIELD_PREP(SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_DEBOUNCE, + SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_DEBOUNCE_PLUG_IN_VALUE) | + FIELD_PREP(SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_DEBOUNCE_SCALE, + SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_DEBOUNCE_SCALE_1MS); + else + value |=3D FIELD_PREP(SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_DEBOUNCE, + SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_DEBOUNCE_PLUG_OUT_VALUE) | + FIELD_PREP(SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_DEBOUNCE_SCALE, + SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_DEBOUNCE_SCALE_10MS); + sdhci_writel(host, value, SDHCI_GLI_9767_SD_HOST_OPERATION_CTL); +} + +static void sdhci_gl9767_card_event(struct sdhci_host *host) +{ + sdhci_gl9767_set_card_detect_debounce_time(host); +} + static void gli_set_9767(struct sdhci_host *host) { u32 value; @@ -1162,6 +1231,12 @@ static void gli_set_9767(struct sdhci_host *host) value =3D sdhci_readl(host, SDHCI_GLI_9767_GM_BURST_SIZE); value &=3D ~SDHCI_GLI_9767_GM_BURST_SIZE_AXI_ALWAYS_SET; sdhci_writel(host, value, SDHCI_GLI_9767_GM_BURST_SIZE); + + value =3D sdhci_readl(host, SDHCI_GLI_9767_SD_HOST_OPERATION_CTL); + value &=3D ~SDHCI_GLI_9767_SD_HOST_OPERATION_CTL_CMD_CONFLICT_CHECK; + sdhci_writel(host, value, SDHCI_GLI_9767_SD_HOST_OPERATION_CTL); + + sdhci_gl9767_set_card_detect_debounce_time(host); } =20 static void gl9767_hw_setting(struct sdhci_pci_slot *slot) @@ -1200,7 +1275,43 @@ static void gl9767_hw_setting(struct sdhci_pci_slot = *slot) =20 static void sdhci_gl9767_reset(struct sdhci_host *host, u8 mask) { - sdhci_reset(host, mask); + struct sdhci_pci_slot *slot =3D sdhci_priv(host); + struct pci_dev *pdev =3D slot->chip->pdev; + u32 value; + + /* need internal clock */ + if (mask & SDHCI_RESET_ALL) { + sdhci_gli_enable_internal_clock(host); + + gl9767_vhs_write(pdev); + + pci_read_config_dword(pdev, PCIE_GLI_9767_RESET_REG, &value); + value &=3D ~PCIE_GLI_9767_RESET_REG_SD_HOST_SW_RESET; + pci_write_config_dword(pdev, PCIE_GLI_9767_RESET_REG, value); + + if (read_poll_timeout_atomic(pci_read_config_dword, value, + !(value & PCIE_GLI_9767_RESET_REG_SD_HOST_SW_RESET), + 1, 5, true, pdev, PCIE_GLI_9767_RESET_REG, &value)) { + pr_warn("%s: %s: Reset SDHC AHB and TL-AMBA failure.\n", + __func__, mmc_hostname(host->mmc)); + gl9767_vhs_read(pdev); + return; + } + gl9767_vhs_read(pdev); + } + + if (mmc_card_uhs2(host->mmc)) { + if (mask & (SDHCI_RESET_CMD | SDHCI_RESET_DATA)) { + sdhci_writeb(host, mask, SDHCI_SOFTWARE_RESET); + sdhci_gli_uhs2_reset_sd_tran(host); + sdhci_gli_wait_software_reset_done(host, mask); + } else { + sdhci_uhs2_reset(host, mask); + } + } else { + sdhci_reset(host, mask); + } + gli_set_9767(host); } =20 @@ -1291,6 +1402,86 @@ static int gl9767_init_sd_express(struct mmc_host *m= mc, struct mmc_ios *ios) return 0; } =20 +static void gl9767_vendor_init(struct sdhci_host *host) +{ + struct sdhci_pci_slot *slot =3D sdhci_priv(host); + struct pci_dev *pdev =3D slot->chip->pdev; + u32 value; + + gl9767_vhs_write(pdev); + + pci_read_config_dword(pdev, PCIE_GLI_9767_UHS2_PHY_SET_REG1, &value); + value |=3D FIELD_PREP(PCIE_GLI_9767_UHS2_PHY_SET_REG1_SERDES_INTR, + PCIE_GLI_9767_UHS2_PHY_SET_REG1_SERDES_INTR_VALUE); + pci_write_config_dword(pdev, PCIE_GLI_9767_UHS2_PHY_SET_REG1, value); + + pci_read_config_dword(pdev, PCIE_GLI_9767_UHS2_PHY_SET_REG2, &value); + value |=3D FIELD_PREP(PCIE_GLI_9767_UHS2_PHY_SET_REG2_SSC_PPM_SETTING, + PCIE_GLI_9767_UHS2_PHY_SET_REG2_SSC_PPM_SETTING_VALUE); + pci_write_config_dword(pdev, PCIE_GLI_9767_UHS2_PHY_SET_REG2, value); + + pci_read_config_dword(pdev, PCIE_GLI_9767_UHS2_CTL1, &value); + value |=3D FIELD_PREP(PCIE_GLI_9767_UHS2_CTL1_TRANS_PASS, + PCIE_GLI_9767_UHS2_CTL1_TRANS_PASS_VALUE) | + FIELD_PREP(PCIE_GLI_9767_UHS2_CTL1_DECODING_CTL, + PCIE_GLI_9767_UHS2_CTL1_DECODING_CTL_VALUE) | + FIELD_PREP(PCIE_GLI_9767_UHS2_CTL1_SERDES_TRAN, + PCIE_GLI_9767_UHS2_CTL1_SERDES_TRAN_VALUE) | + FIELD_PREP(PCIE_GLI_9767_UHS2_CTL1_SERDES_RECV, + PCIE_GLI_9767_UHS2_CTL1_SERDES_RECV_VALUE) | + FIELD_PREP(PCIE_GLI_9767_UHS2_CTL1_DIR_TRANS, + PCIE_GLI_9767_UHS2_CTL1_DIR_TRANS_VALUE) | + FIELD_PREP(PCIE_GLI_9767_UHS2_CTL1_DIR_RECV, + PCIE_GLI_9767_UHS2_CTL1_DIR_RECV_VALUE) | + FIELD_PREP(PCIE_GLI_9767_UHS2_CTL1_PDRST, + PCIE_GLI_9767_UHS2_CTL1_PDRST_VALUE); + pci_write_config_dword(pdev, PCIE_GLI_9767_UHS2_CTL1, value); + + pci_read_config_dword(pdev, PCIE_GLI_9767_UHS2_CTL2, &value); + value |=3D FIELD_PREP(PCIE_GLI_9767_UHS2_CTL2_ZC, + PCIE_GLI_9767_UHS2_CTL2_ZC_VALUE) | + FIELD_PREP(PCIE_GLI_9767_UHS2_CTL2_ZC_CTL, + PCIE_GLI_9767_UHS2_CTL2_ZC_CTL_VALUE); + pci_write_config_dword(pdev, PCIE_GLI_9767_UHS2_CTL2, value); + + gl9767_vhs_read(pdev); +} + +static void sdhci_gl9767_set_power(struct sdhci_host *host, unsigned char = mode, unsigned short vdd) +{ + struct sdhci_pci_slot *slot =3D sdhci_priv(host); + struct pci_dev *pdev =3D slot->chip->pdev; + u32 value; + + if (mmc_card_uhs2(host->mmc)) { + gl9767_vhs_write(pdev); + + pci_read_config_dword(pdev, PCIE_GLI_9767_SD_DATA_MULTI_CTL, &value); + value |=3D PCIE_GLI_9767_SD_DATA_MULTI_CTL_SELECT_UHS2 | + PCIE_GLI_9767_SD_DATA_MULTI_CTL_UHS2_SWITCH_CTL; + pci_write_config_dword(pdev, PCIE_GLI_9767_SD_DATA_MULTI_CTL, value); + + gl9767_vhs_read(pdev); + + sdhci_gli_overcurrent_event_enable(host, false); + sdhci_uhs2_set_power(host, mode, vdd); + sdhci_gli_overcurrent_event_enable(host, true); + } else { + gl9767_vhs_write(pdev); + + pci_read_config_dword(pdev, PCIE_GLI_9767_SD_DATA_MULTI_CTL, &value); + value &=3D ~(PCIE_GLI_9767_SD_DATA_MULTI_CTL_SELECT_UHS2 | + PCIE_GLI_9767_SD_DATA_MULTI_CTL_UHS2_SWITCH_CTL); + pci_write_config_dword(pdev, PCIE_GLI_9767_SD_DATA_MULTI_CTL, value); + + gl9767_vhs_read(pdev); + + sdhci_gli_overcurrent_event_enable(host, false); + sdhci_set_power(host, mode, vdd); + sdhci_gli_overcurrent_event_enable(host, true); + } +} + static int gli_probe_slot_gl9750(struct sdhci_pci_slot *slot) { struct sdhci_host *host =3D slot->host; @@ -1327,6 +1518,7 @@ static int gli_probe_slot_gl9767(struct sdhci_pci_slo= t *slot) host->mmc->caps2 |=3D MMC_CAP2_SD_EXP; host->mmc_host_ops.init_sd_express =3D gl9767_init_sd_express; sdhci_enable_v4_mode(host); + gl9767_vendor_init(host); =20 return 0; } @@ -1830,12 +2022,20 @@ static const struct sdhci_ops sdhci_gl9767_ops =3D { .reset =3D sdhci_gl9767_reset, .set_uhs_signaling =3D sdhci_set_uhs_signaling, .voltage_switch =3D sdhci_gl9767_voltage_switch, + .dump_uhs2_regs =3D sdhci_uhs2_dump_regs, + .set_timeout =3D sdhci_uhs2_set_timeout, + .irq =3D sdhci_uhs2_irq, + .set_power =3D sdhci_gl9767_set_power, + .uhs2_pre_detect_init =3D sdhci_gli_pre_detect_init, + .card_event =3D sdhci_gl9767_card_event, }; =20 const struct sdhci_pci_fixes sdhci_gl9767 =3D { .quirks =3D SDHCI_QUIRK_NO_ENDATTR_IN_NOPDESC, .quirks2 =3D SDHCI_QUIRK2_BROKEN_DDR50, .probe_slot =3D gli_probe_slot_gl9767, + .add_host =3D sdhci_pci_uhs2_add_host, + .remove_host =3D sdhci_pci_uhs2_remove_host, .ops =3D &sdhci_gl9767_ops, #ifdef CONFIG_PM_SLEEP .resume =3D sdhci_pci_gli_resume, --=20 2.25.1