From patchwork Wed Feb 13 19:54:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 158245 Delivered-To: patches@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp470072jaa; Wed, 13 Feb 2019 11:54:48 -0800 (PST) X-Received: by 2002:a19:c50c:: with SMTP id w12mr1359829lfe.53.1550087688407; Wed, 13 Feb 2019 11:54:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550087688; cv=none; d=google.com; s=arc-20160816; b=zVCRobAWiC6QLb0UL4Ns2d3gPuplZqAAduRYIAnnlMTr7np9uKOH+IBYYyKhemgUfx P6vR0TBgaD6++3+0hvAEMoMGfROcLRjKUzlMWp868r0XA2JO3jymuKs8SgUc+D+AlLAT UolnBEyXpXflpGxuLyV3DGiLde+SR15PUfuxpGFhzmgdVx7WLtheMobLxw/5YbdSOvlO dfFQPwRrvevrcbf4EKaivGYdBYCB5U5wyRCpy4rBP3Hb6xgMhaMGHzSTHYMsVxbxeQNF PnLpCD/ExKs2k2o++3osFfIRCM8R9/3mOqInvC5GycP9/0ZrnAZk7r3hdL9xKttLtBrk 5LIA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nNUmQRlmGsFjr9KVSiomykiKcxuLQl1wz+4+Y9A/eKs=; b=QBH7MqDAWfhqf/5oghjiqePPuDZUn1eM99sxKrzEACsFj2cVlw/AxeOF+fA54+QxHl r1iyuj4Djrpo83zZN+m3vC4FFwfWVkJGAt5tx4dhxZO4TNNnSflEYGJ4K2Ix2oDU1KO/ MhYi+OxdeZgApXaf3C/1wThg9Kx+vC2QkcfXEFYeHRp6Z6ZIR6h6TR19yGID2ZU9LXm9 G4zfNKle1NoW5qCd3Pkbf2h524lpmB9e24WWjl2Porrg57R4h7rimMKFSTijVAcxk627 LYtqWiriHqAB1Jt5PHomu5+c74wIMK0MW0KEF8b6rWwUfClaKRRSbHuCIiK+T+uZctwr S4hQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mXM6wMlq; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id s74-v6sor158601lje.7.2019.02.13.11.54.48 for (Google Transport Security); Wed, 13 Feb 2019 11:54:48 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mXM6wMlq; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nNUmQRlmGsFjr9KVSiomykiKcxuLQl1wz+4+Y9A/eKs=; b=mXM6wMlq/AJYzzMxH2No0BUdvf+HJhSX41gBOTqRxMibJCPjaJO6NAU1s/GQtnkGeh NBFG+5iGjLe6fUjfL2zW8gh4Ncx+FR29WpmL7yO1lh4Cb93FDx46VFYWyJDD3tjA5yR+ +nb9/DOwxDL4KQ/IMc5x8L3r6W4dBJZs6BpKCc4CO2vZq2F984Q7/FaOb3+HXsNnUg73 cgftoZdtcf/aCn63t/0LJJGcviNo+XbslP2VVKtdC9U7tH0jDudLlwKrW8HHmx8NfumH +s5pf/GersD1ydXhj/s15J8RwCDlgInJL4dhEAyPXG3d9T1+eW2AtomVG8O60KTj+KZ4 Nm6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nNUmQRlmGsFjr9KVSiomykiKcxuLQl1wz+4+Y9A/eKs=; b=tblnn4p43Y+6/VFwnUclDqyWk4qfotXw5ynonGgOoeNTWcBhFo1dJ3MwUGpwS5uQpV HOFH65xVOPROJlzgpyckpml19wTapMlGV84D1zFzqmkPKhzmFPV3TKBwYae9EysjVmLg yqOa33ast91dtijFdubFPWsZKrV8INGPsaaIglY3uIxkbv1r3FEUFTZxcFjTd821r3L3 EhnvFTR2QXGZAmNK6RF7dsr8CKvJNKTsN7+BgtT4VxcZhqJTmD0dLAknJIQ1/NK992IL V0YuY5D8rLY1Cb6rB2/3kWoUEalzoYPHxWs3abulSNuitB9V/6AfRZ9exnSrfpH1x7pv JaoA== X-Gm-Message-State: AHQUAuY+xLFtLSN98jhDzGvDzBlgHbQgPiIqZ9rYIKi+7rcFqi9vrH6q Hnc6FrXM21+n5B7un7FMdJXK0qxz X-Google-Smtp-Source: AHgI3IZMabaafQfdErup2kNoXaN//pZUjVeIZeW3tRYUoUR1/yNoP51DxADKxcyAqcpBTfRID1tukw== X-Received: by 2002:a2e:5747:: with SMTP id r7-v6mr1300252ljd.141.1550087687888; Wed, 13 Feb 2019 11:54:47 -0800 (PST) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id g194sm39169lfg.55.2019.02.13.11.54.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 11:54:47 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Adrian Hunter Cc: Ulf Hansson Subject: [PATCH 1/7] mmc: core: Convert mmc_wait_for_app_cmd() to static Date: Wed, 13 Feb 2019 20:54:37 +0100 Message-Id: <20190213195443.18935-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190213195443.18935-1-ulf.hansson@linaro.org> References: <20190213195443.18935-1-ulf.hansson@linaro.org> mmc_wait_for_app_cmd() is an internal function for sd_ops.c, thus let's drop the unnecessary export and turn it into static function. Signed-off-by: Ulf Hansson --- drivers/mmc/core/sd_ops.c | 17 +---------------- drivers/mmc/core/sd_ops.h | 3 --- 2 files changed, 1 insertion(+), 19 deletions(-) -- 2.17.1 diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c index 47056d8d1bac..39be4d64bc68 100644 --- a/drivers/mmc/core/sd_ops.c +++ b/drivers/mmc/core/sd_ops.c @@ -52,20 +52,7 @@ int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card) } EXPORT_SYMBOL_GPL(mmc_app_cmd); -/** - * mmc_wait_for_app_cmd - start an application command and wait for - completion - * @host: MMC host to start command - * @card: Card to send MMC_APP_CMD to - * @cmd: MMC command to start - * @retries: maximum number of retries - * - * Sends a MMC_APP_CMD, checks the card response, sends the command - * in the parameter and waits for it to complete. Return any error - * that occurred while the command was executing. Do not attempt to - * parse the response. - */ -int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card, +static int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card, struct mmc_command *cmd, int retries) { struct mmc_request mrq = {}; @@ -116,8 +103,6 @@ int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card, return err; } -EXPORT_SYMBOL(mmc_wait_for_app_cmd); - int mmc_app_set_bus_width(struct mmc_card *card, int width) { struct mmc_command cmd = {}; diff --git a/drivers/mmc/core/sd_ops.h b/drivers/mmc/core/sd_ops.h index 0e6c3d51e66d..ffaed5cacc88 100644 --- a/drivers/mmc/core/sd_ops.h +++ b/drivers/mmc/core/sd_ops.h @@ -16,7 +16,6 @@ struct mmc_card; struct mmc_host; -struct mmc_command; int mmc_app_set_bus_width(struct mmc_card *card, int width); int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr); @@ -27,8 +26,6 @@ int mmc_sd_switch(struct mmc_card *card, int mode, int group, u8 value, u8 *resp); int mmc_app_sd_status(struct mmc_card *card, void *ssr); int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card); -int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card, - struct mmc_command *cmd, int retries); #endif From patchwork Wed Feb 13 19:54:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 158246 Delivered-To: patches@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp470085jaa; Wed, 13 Feb 2019 11:54:50 -0800 (PST) X-Received: by 2002:ac2:4219:: with SMTP id y25mr1348016lfh.130.1550087690242; Wed, 13 Feb 2019 11:54:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550087690; cv=none; d=google.com; s=arc-20160816; b=eXir38mGI2kp1r6B7aGmnIsxCPYVAf6wjIUnhVT2eSlunA01YH8pIUNGFsEOSL3OsN 4M47d6vmd9Y+BsfzrnTcWlR+qa0qB0IwKgaii8od9imm13S1/wuYbmhyC//ytqoWqdUs sEyOTAjcapCmqxsMifTsAg6XGnCIK5Vlmzee2ZOILrFn5mygRLQ55G7DcEqXSTLqDtlF 148u9zzVz0Izkaqlos3ChcsfebMhrr8C2scIfr8HVzLnyBP0dba6B5qMTV34T93kak0e VG0TZKqma5jrAENCUfUXu8xPJwTNMOMJO1EG1Qeqpahjei1fyYkQE3eA5SQ4ag2VNhOg rf5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kgDHFK57CR5Ay9YIhXMb7cC0cVszsj4VLxkHuyRddxQ=; b=cO+EnFrJBddsnGl48ixNiRRT1c+FDN1pBSdCFDe3TO+COQdypW1Qgj3YZzARDT4CQL 2sI9TeSZU7PcJmWiQVialkm1TV8qmrR0uCSzU1hXzC9tvuRluF4eM4vbmI3nyDiybGQB WR/XKEPBbVEQMnsjg7u8bLcdKg1oEnN9kpA6wUjIX2+w1HBeFiFDe6RvettGRC1VunAz JBfZwx7rFwF+nZV6AQzyFxD//Fj9yNx4dRtkRnd4DfjK+xZmIrEbfWXHMkMMM1L9shI8 z32HEYs2XHEHlytJZsZmHC9/dUDCgLpXId41VR/aljj0aLZ6jSqotWsZHeAk6jL8HMLE rCsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xOCJNm27; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id l20-v6sor138681lji.21.2019.02.13.11.54.50 for (Google Transport Security); Wed, 13 Feb 2019 11:54:50 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xOCJNm27; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kgDHFK57CR5Ay9YIhXMb7cC0cVszsj4VLxkHuyRddxQ=; b=xOCJNm27TfkIi15lyMEIHxeKSnhUIBjot1Fb25S2CrRJXpom8eaFnSrmOGQdPDmSVs 2hx9KN2YK3AzAGqtBcXoyFdayudBSRbbuSlw4Bd7/TU1ZMcG2wDUY06gpcEMbXMOIZOa Zw84ekiFfKn78MZNai0V7Qjwa8wys7h0uEp6dRrit0TqnvVKsDSS/d5PWLBBBfjY8dg2 YIIVVKVvWET/bhmBu0qCM8XU0AzeQhP63cCm4bjzzu5e6Ul0f+c7L/SF0NrFhmugosgu PI2z2abIDzVFzxllVm1HJex3Z4WKgYQS0KIV/yOtOj+tCIU9fhGxZoLUL6rUmfT0VR0R M/vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=kgDHFK57CR5Ay9YIhXMb7cC0cVszsj4VLxkHuyRddxQ=; b=WwtxxocTQ9wHXg3mCXd+Fh1Y2jFhQ7ETjic2NC1NoGE48hHCgRF7WPR+GjNs9xUMjz ko+hDKUmq6nOWDH4YUMF2wB0arWpmrpXac8gB3POKNrnUBtdYG2ML26R1GGgkPOhPlwA OwrtRnI2bYjs44yae7u8RrJF07E2V02/z/N9yf52lp1sq5PUEOMxXB+CIYcDdHm/FCV3 OmUXB2TRAEYX0vzjfpu98WmY+D2bpE2QB6p6/ru+SlllmjDNxp39YYMRsAARkNg7Op1t DftJ7ctUdGBOL2rzmTEbcBlRykFIHM0hk5hkI3OcfR1vXCvdaazw4BDCO+S4BMkcKQuZ uktw== X-Gm-Message-State: AHQUAuYtX9sIcm1jDwCakt3uMs4Ag+SE0/pWykXNfAqISo0n8+e71n71 DETigO/vinR8f0rRl0V58PF9/5H9/rhOqg== X-Google-Smtp-Source: AHgI3IacToGuGXv9lHW94N1a289/vGrNE7DAZqITplA38dCMeFhuV9glQ+G+qcWSfHRP0lKlZcIsTQ== X-Received: by 2002:a2e:8585:: with SMTP id b5mr1323808lji.125.1550087689729; Wed, 13 Feb 2019 11:54:49 -0800 (PST) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id g194sm39169lfg.55.2019.02.13.11.54.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 11:54:49 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Adrian Hunter Cc: Ulf Hansson Subject: [PATCH 2/7] mmc: core: Drop retries as in-parameter to mmc_wait_for_app_cmd() Date: Wed, 13 Feb 2019 20:54:38 +0100 Message-Id: <20190213195443.18935-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190213195443.18935-1-ulf.hansson@linaro.org> References: <20190213195443.18935-1-ulf.hansson@linaro.org> All callers of mmc_wait_for_app_cmd() set the retries in-parameter to MMC_CMD_RETRIES. This is silly, so let's just drop the in-parameter altogether, as to simplify the code. Signed-off-by: Ulf Hansson --- drivers/mmc/core/sd_ops.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) -- 2.17.1 diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c index 39be4d64bc68..0bb0b8419016 100644 --- a/drivers/mmc/core/sd_ops.c +++ b/drivers/mmc/core/sd_ops.c @@ -53,22 +53,16 @@ int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card) EXPORT_SYMBOL_GPL(mmc_app_cmd); static int mmc_wait_for_app_cmd(struct mmc_host *host, struct mmc_card *card, - struct mmc_command *cmd, int retries) + struct mmc_command *cmd) { struct mmc_request mrq = {}; - - int i, err; - - if (retries < 0) - retries = MMC_CMD_RETRIES; - - err = -EIO; + int i, err = -EIO; /* * We have to resend MMC_APP_CMD for each attempt so * we cannot use the retries field in mmc_command. */ - for (i = 0;i <= retries;i++) { + for (i = 0; i <= MMC_CMD_RETRIES; i++) { err = mmc_app_cmd(host, card); if (err) { /* no point in retrying; no APP commands allowed */ @@ -121,7 +115,7 @@ int mmc_app_set_bus_width(struct mmc_card *card, int width) return -EINVAL; } - return mmc_wait_for_app_cmd(card->host, card, &cmd, MMC_CMD_RETRIES); + return mmc_wait_for_app_cmd(card->host, card, &cmd); } int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr) @@ -137,7 +131,7 @@ int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr) cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R3 | MMC_CMD_BCR; for (i = 100; i; i--) { - err = mmc_wait_for_app_cmd(host, NULL, &cmd, MMC_CMD_RETRIES); + err = mmc_wait_for_app_cmd(host, NULL, &cmd); if (err) break; From patchwork Wed Feb 13 19:54:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 158247 Delivered-To: patches@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp470106jaa; Wed, 13 Feb 2019 11:54:52 -0800 (PST) X-Received: by 2002:ac2:411a:: with SMTP id b26mr1410845lfi.169.1550087692068; Wed, 13 Feb 2019 11:54:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550087692; cv=none; d=google.com; s=arc-20160816; b=nVm6iAQwGnL+TlMoeoVATNI98z2VBnjfbAj2oZgG2HqkBAG9kZq0hHsxgBsBJJQ0no AgDmn68/zsEIh/cqDsUiONch1NwDBi8yYEZL8nAeYwxHe0l448oGsdhNGErFNXe1JDOU ejulIwkGKc0lN3dvEL1Q0TvdvAJHtOfh6Mkz1q82KUrwFoQgnyOaB5gJAF29Y9BmuQ3H pZ9mJR0NaBnTq+a9clXGIbVzHcZa8J4Izyd97td3If/OzmEWRGxDt5ZXjpiXatEx5PPr /kgMOtyGElUk27ejfECJVwAdEVygrt50e5t6ISJNoOS0wUHN+YJIOhw2oc4Fak23DbGU gf3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nuXD6VM1wVFkPlHiS/tUPo5Gno6gYFdCgM2U6wJp148=; b=kA2OlEp6JOtrW/klUM32hhDQnnJT2lOjMVHwUzB6ngVF0SRuOmCfCxikh8QR31mTSB QtNflgU3yhShUItvSAtV9J+1w/bPSTq1E86xY2NP8dnQhRq9ItyKFEEQRZjCvCLJQhNt 2jDFv++gnhCJ4OsRi/l3Hk40jAqQhreO8VpPhna0Te+iLGXMAQdTeWV5xj35xtHQFJKj zkn2DRY6HHqAfE124n9CKeBZONHKQZ6DuUjkquZxL7UyJzXtdVU+eNqMOp10+G8xCZUf AKNui4x/Le8hAbRqSpyGwmOREbxxL1rMwRMqskQW4jsybM6aJRvqby9zAbXSyyw54g/N Iecg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gQGAf3Gl; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id r10-v6sor117760lji.40.2019.02.13.11.54.51 for (Google Transport Security); Wed, 13 Feb 2019 11:54:52 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gQGAf3Gl; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nuXD6VM1wVFkPlHiS/tUPo5Gno6gYFdCgM2U6wJp148=; b=gQGAf3Gldetn56cN+l3X6/VjqQwekFIGuJVx0rPvM4AfgJUmfVAsQUw1/qtiWlUGqW 60PD++G3SjkKTTAANbJuRmA1YuVo+llbUsTBU5mAXtZLKkHgplVGF1jtbXBYuaNlDFsI WuO5cC0+MjT3aZYPQuuAcoMTWTVXUod6/gWeJGHUL0shDCYMjekkZLJ8UcOeevgpltyG FgzSrkiyOTSOtrSIM5Z9zXCLdXdyE+/2V/yWhheubXYGPidEpGhbcS8I42hXTDu7D4s0 RRSTx/WtRn8aUA7DdNJLTPkE0uauw/qFBf07gzOWFWM6d3V1nKYiXC33IfDQTFN0WrPl sBXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nuXD6VM1wVFkPlHiS/tUPo5Gno6gYFdCgM2U6wJp148=; b=peZgafWgU1OQyeCiKquEwt0MlRfpx+Nxgo0c50YynT4hv/M3ITcay6VGCd48Rv+rDK GnP8GMRwqCxe+wf0O39vjfjaC5/7ODVvJ4sOr+qcjExagczENGUhidqNm+2rLQ2F/lQa LIdWmSbt/Gsi44b+yy2Aql4LntklYfm9+6PIHmZsdE1yhGWQtfNrnv1ITjiekdcsVUkp 4wakqnashvstwb5kdBIOLjP3XWWdV+Ks7hakCkSXe9bo2nWrzNSMbec/4zeo2gvfV1VX /DjwS24nQHdZS5vlFzoBv2J8XZTGmTYR0kyvpPNzfFra5DCG8y/PQHCrV/X1f8jGyuxj GUlA== X-Gm-Message-State: AHQUAuY/2wInTgz0IKPQkVe8y+ZRPQ0xF923YQsTMDQZHSXIFBbvhqLe k83Wn9wGfPbr/ayze7drEaz8m7KJ X-Google-Smtp-Source: AHgI3IZ3RQxmiu507CYYdnR2wK9HjyFtlRJPmXOqXMg+8MLqYuLCCZ+uCsVPqCdtJ8SDPQcgmFIxMA== X-Received: by 2002:a2e:9a58:: with SMTP id k24mr1432875ljj.136.1550087691562; Wed, 13 Feb 2019 11:54:51 -0800 (PST) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id g194sm39169lfg.55.2019.02.13.11.54.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 11:54:50 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Adrian Hunter Cc: Ulf Hansson Subject: [PATCH 3/7] mmc: of_mmc_spi: Convert to mmc_of_parse_voltage() Date: Wed, 13 Feb 2019 20:54:39 +0100 Message-Id: <20190213195443.18935-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190213195443.18935-1-ulf.hansson@linaro.org> References: <20190213195443.18935-1-ulf.hansson@linaro.org> Let's drop the open-coding of the parsing of the "voltage-ranges" DT property and convert to use the common mmc_of_parse_voltage() API instead. Signed-off-by: Ulf Hansson --- drivers/mmc/host/of_mmc_spi.c | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) -- 2.17.1 diff --git a/drivers/mmc/host/of_mmc_spi.c b/drivers/mmc/host/of_mmc_spi.c index b294b221f225..8a274b91804e 100644 --- a/drivers/mmc/host/of_mmc_spi.c +++ b/drivers/mmc/host/of_mmc_spi.c @@ -61,9 +61,6 @@ struct mmc_spi_platform_data *mmc_spi_get_pdata(struct spi_device *spi) struct device *dev = &spi->dev; struct device_node *np = dev->of_node; struct of_mmc_spi *oms; - const __be32 *voltage_ranges; - int num_ranges; - int i; if (dev->platform_data || !np) return dev->platform_data; @@ -72,25 +69,8 @@ struct mmc_spi_platform_data *mmc_spi_get_pdata(struct spi_device *spi) if (!oms) return NULL; - voltage_ranges = of_get_property(np, "voltage-ranges", &num_ranges); - num_ranges = num_ranges / sizeof(*voltage_ranges) / 2; - if (!voltage_ranges || !num_ranges) { - dev_err(dev, "OF: voltage-ranges unspecified\n"); + if (mmc_of_parse_voltage(np, &oms->pdata.ocr_mask) <= 0) goto err_ocr; - } - - for (i = 0; i < num_ranges; i++) { - const int j = i * 2; - u32 mask; - - mask = mmc_vddrange_to_ocrmask(be32_to_cpu(voltage_ranges[j]), - be32_to_cpu(voltage_ranges[j + 1])); - if (!mask) { - dev_err(dev, "OF: voltage-range #%d is invalid\n", i); - goto err_ocr; - } - oms->pdata.ocr_mask |= mask; - } oms->detect_irq = irq_of_parse_and_map(np, 0); if (oms->detect_irq != 0) { From patchwork Wed Feb 13 19:54:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 158248 Delivered-To: patches@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp470123jaa; Wed, 13 Feb 2019 11:54:53 -0800 (PST) X-Received: by 2002:a19:41ca:: with SMTP id o193mr1223026lfa.121.1550087693710; Wed, 13 Feb 2019 11:54:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550087693; cv=none; d=google.com; s=arc-20160816; b=M/X3y4sZMWbEd4524gAz6NUlaML1TqP8FtFe/KwhFjMO3/3RqZpbMXTzUSpfhLVJxu QH+ktbl1ujKYKZnD/eSy0FhRKGl/rEGllSnirYzD/92xNgVwNGyPk+E7YFWlJe51ZhVi DzuxuW6CpVVpz2sRCfNBzvi2oN8rORkZetVyk/AJ97RzXNQlAaOFk4gr9J+E2PpRydSf pBI+48hF/wbacj0kr5rm0r1msxY7U2tcFHtHAlbTuvrAUplk09J+dETW8JSRGFT9MF4J FW3WgjwAAN7FQELJPR7+co1dJyPEGSliflwDr7W7k/5TO0ZQO+E0McsGMRDX23xj2Cyc wQYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=gZ/V1NLFWGmnT4wEPVpXZkWnIFtRoE4htTAF7WBoXzU=; b=oQIcbOyT59lsmxDtnwVmz3kexRI1TMHFI36cj5g4rCp3e66YdhcU8WfbL8mDFkaJuw wmbhXXUmGsXwOdy2xO1RoavtpHFoOPIe2PFWbPAnkODU2mepUOPMtTBpTMD25v5jOkWO iZbf2A1FTeJt4qWNrhXfUZBJ8FlTznMhtRtLLcMuAKhMMJSr/V4Ou++vtOgNCbkNMYTX u0mGU2x6S/w8ZRb1F/Z5ZpopKql+FuxVkthk86vX0mQ5vZejt+PTN49uFd1XxjZH72Wg iXwFxxjTCvTVqEQwKuciZMRH2E2WWTtiAi0zvdIFsUb5S2gfjixNkWEMBucse3wy0FkJ XQuA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FbEdX7xh; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id b17-v6sor143554ljd.16.2019.02.13.11.54.53 for (Google Transport Security); Wed, 13 Feb 2019 11:54:53 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FbEdX7xh; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=gZ/V1NLFWGmnT4wEPVpXZkWnIFtRoE4htTAF7WBoXzU=; b=FbEdX7xhz2jByLYoYieMkvNYl3M8fS5DJkE0Df9o9yTXh+Y89iIwvf09tpyyfoysm9 OGFZhfPttgSE+O88r01BiYXWj8Y0uzYMm8QOfuxYSsjCYqMPl1HYm011uIDyZf6XxrJC l5fVAb7K4ZsIDw7BQkW5Q6IinZWY03GJEc444By5EjGtiqFCMwOyd3ZSDI6MWku1E1tN CYjQWW/BjzttpW5OJfWJMCTA5T61TrwVIHp0j8XnXubML+6pPdTaliSlgohFruidLjka wEz4ChWRD4kaFfkPaxCQ5gOkmLRJOmife1KlFtaayIiPE3c8YROIU9isyQhITAiqZLil J3vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=gZ/V1NLFWGmnT4wEPVpXZkWnIFtRoE4htTAF7WBoXzU=; b=TdJZWPOo//17+s/oPgNT6VWIBL6FScDMeuSJpo44NPFRBst4o5DV6OWWpUAusXQaeT EoIyCvqlhDeB7hdo6B82w8adHFG/tH/KK5FBnR8AXuWLQVPtfgmaKiiSFRwTy2u+3Uth 2oBv3SCZFqOfUoLxaR32JOH6FyHNS3OeMb/NQe4hbH0XJZKOQUK19HQHl2xLmQ46IqPS scTg539I95KnkM3H5I4UcajF9jYWE1/qHeIFAFdZdGaqFYYgedHjXgilwGhBx0b/PQXo VoxD+RrzA86AsXhSEGE+FL79HJlSivg1azp8Kx0siG8Yr/g3i6Nd9LRB+gLS56JkeFEZ vUEA== X-Gm-Message-State: AHQUAububGTDktfmCpdUP6q8mPT9knAatJpdvIXuJRX8iHJ7poIvUZ+U A/ddTWB507W9KBB5+i98qj1uQUvH X-Google-Smtp-Source: AHgI3IYucvIikkzQ4dPDBfEVkzEZHYrgsPFSwmqz6EbdvQiXxAROhbZVZnN9yEvTP9Zk8sqHq56K7w== X-Received: by 2002:a2e:9b05:: with SMTP id u5mr1336668lji.144.1550087692949; Wed, 13 Feb 2019 11:54:52 -0800 (PST) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id g194sm39169lfg.55.2019.02.13.11.54.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 11:54:52 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Adrian Hunter Cc: Ulf Hansson Subject: [PATCH 4/7] mmc: core: Move regulator helpers to separate file Date: Wed, 13 Feb 2019 20:54:40 +0100 Message-Id: <20190213195443.18935-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190213195443.18935-1-ulf.hansson@linaro.org> References: <20190213195443.18935-1-ulf.hansson@linaro.org> The mmc regulator helper functions, are placed in the extensive core.c file. In a step towards trying to create a better structure of files, avoiding too many lines of code per file, let's move these helpers to a new file, regulator.c. Moreover, this within this context it makes sense to also drop the export of mmc_vddrange_to_ocrmask(), but instead let's make it internal to the mmc core. Signed-off-by: Ulf Hansson --- drivers/mmc/core/Makefile | 2 +- drivers/mmc/core/core.c | 242 -------------------------------- drivers/mmc/core/core.h | 1 + drivers/mmc/core/regulator.c | 261 +++++++++++++++++++++++++++++++++++ include/linux/mmc/host.h | 1 - 5 files changed, 263 insertions(+), 244 deletions(-) create mode 100644 drivers/mmc/core/regulator.c -- 2.17.1 diff --git a/drivers/mmc/core/Makefile b/drivers/mmc/core/Makefile index abba078f7f49..95ffe008ebdf 100644 --- a/drivers/mmc/core/Makefile +++ b/drivers/mmc/core/Makefile @@ -8,7 +8,7 @@ mmc_core-y := core.o bus.o host.o \ mmc.o mmc_ops.o sd.o sd_ops.o \ sdio.o sdio_ops.o sdio_bus.o \ sdio_cis.o sdio_io.o sdio_irq.o \ - slot-gpio.o + slot-gpio.o regulator.o mmc_core-$(CONFIG_OF) += pwrseq.o obj-$(CONFIG_PWRSEQ_SIMPLE) += pwrseq_simple.o obj-$(CONFIG_PWRSEQ_SD8787) += pwrseq_sd8787.o diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index de0f1a1f0a63..f796a6afb19b 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -21,7 +21,6 @@ #include #include #include -#include #include #include #include @@ -1112,7 +1111,6 @@ u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max) return mask; } -EXPORT_SYMBOL(mmc_vddrange_to_ocrmask); #ifdef CONFIG_OF @@ -1190,246 +1188,6 @@ struct device_node *mmc_of_find_child_device(struct mmc_host *host, return NULL; } -#ifdef CONFIG_REGULATOR - -/** - * mmc_ocrbitnum_to_vdd - Convert a OCR bit number to its voltage - * @vdd_bit: OCR bit number - * @min_uV: minimum voltage value (mV) - * @max_uV: maximum voltage value (mV) - * - * This function returns the voltage range according to the provided OCR - * bit number. If conversion is not possible a negative errno value returned. - */ -static int mmc_ocrbitnum_to_vdd(int vdd_bit, int *min_uV, int *max_uV) -{ - int tmp; - - if (!vdd_bit) - return -EINVAL; - - /* - * REVISIT mmc_vddrange_to_ocrmask() may have set some - * bits this regulator doesn't quite support ... don't - * be too picky, most cards and regulators are OK with - * a 0.1V range goof (it's a small error percentage). - */ - tmp = vdd_bit - ilog2(MMC_VDD_165_195); - if (tmp == 0) { - *min_uV = 1650 * 1000; - *max_uV = 1950 * 1000; - } else { - *min_uV = 1900 * 1000 + tmp * 100 * 1000; - *max_uV = *min_uV + 100 * 1000; - } - - return 0; -} - -/** - * mmc_regulator_get_ocrmask - return mask of supported voltages - * @supply: regulator to use - * - * This returns either a negative errno, or a mask of voltages that - * can be provided to MMC/SD/SDIO devices using the specified voltage - * regulator. This would normally be called before registering the - * MMC host adapter. - */ -int mmc_regulator_get_ocrmask(struct regulator *supply) -{ - int result = 0; - int count; - int i; - int vdd_uV; - int vdd_mV; - - count = regulator_count_voltages(supply); - if (count < 0) - return count; - - for (i = 0; i < count; i++) { - vdd_uV = regulator_list_voltage(supply, i); - if (vdd_uV <= 0) - continue; - - vdd_mV = vdd_uV / 1000; - result |= mmc_vddrange_to_ocrmask(vdd_mV, vdd_mV); - } - - if (!result) { - vdd_uV = regulator_get_voltage(supply); - if (vdd_uV <= 0) - return vdd_uV; - - vdd_mV = vdd_uV / 1000; - result = mmc_vddrange_to_ocrmask(vdd_mV, vdd_mV); - } - - return result; -} -EXPORT_SYMBOL_GPL(mmc_regulator_get_ocrmask); - -/** - * mmc_regulator_set_ocr - set regulator to match host->ios voltage - * @mmc: the host to regulate - * @supply: regulator to use - * @vdd_bit: zero for power off, else a bit number (host->ios.vdd) - * - * Returns zero on success, else negative errno. - * - * MMC host drivers may use this to enable or disable a regulator using - * a particular supply voltage. This would normally be called from the - * set_ios() method. - */ -int mmc_regulator_set_ocr(struct mmc_host *mmc, - struct regulator *supply, - unsigned short vdd_bit) -{ - int result = 0; - int min_uV, max_uV; - - if (vdd_bit) { - mmc_ocrbitnum_to_vdd(vdd_bit, &min_uV, &max_uV); - - result = regulator_set_voltage(supply, min_uV, max_uV); - if (result == 0 && !mmc->regulator_enabled) { - result = regulator_enable(supply); - if (!result) - mmc->regulator_enabled = true; - } - } else if (mmc->regulator_enabled) { - result = regulator_disable(supply); - if (result == 0) - mmc->regulator_enabled = false; - } - - if (result) - dev_err(mmc_dev(mmc), - "could not set regulator OCR (%d)\n", result); - return result; -} -EXPORT_SYMBOL_GPL(mmc_regulator_set_ocr); - -static int mmc_regulator_set_voltage_if_supported(struct regulator *regulator, - int min_uV, int target_uV, - int max_uV) -{ - /* - * Check if supported first to avoid errors since we may try several - * signal levels during power up and don't want to show errors. - */ - if (!regulator_is_supported_voltage(regulator, min_uV, max_uV)) - return -EINVAL; - - return regulator_set_voltage_triplet(regulator, min_uV, target_uV, - max_uV); -} - -/** - * mmc_regulator_set_vqmmc - Set VQMMC as per the ios - * - * For 3.3V signaling, we try to match VQMMC to VMMC as closely as possible. - * That will match the behavior of old boards where VQMMC and VMMC were supplied - * by the same supply. The Bus Operating conditions for 3.3V signaling in the - * SD card spec also define VQMMC in terms of VMMC. - * If this is not possible we'll try the full 2.7-3.6V of the spec. - * - * For 1.2V and 1.8V signaling we'll try to get as close as possible to the - * requested voltage. This is definitely a good idea for UHS where there's a - * separate regulator on the card that's trying to make 1.8V and it's best if - * we match. - * - * This function is expected to be used by a controller's - * start_signal_voltage_switch() function. - */ -int mmc_regulator_set_vqmmc(struct mmc_host *mmc, struct mmc_ios *ios) -{ - struct device *dev = mmc_dev(mmc); - int ret, volt, min_uV, max_uV; - - /* If no vqmmc supply then we can't change the voltage */ - if (IS_ERR(mmc->supply.vqmmc)) - return -EINVAL; - - switch (ios->signal_voltage) { - case MMC_SIGNAL_VOLTAGE_120: - return mmc_regulator_set_voltage_if_supported(mmc->supply.vqmmc, - 1100000, 1200000, 1300000); - case MMC_SIGNAL_VOLTAGE_180: - return mmc_regulator_set_voltage_if_supported(mmc->supply.vqmmc, - 1700000, 1800000, 1950000); - case MMC_SIGNAL_VOLTAGE_330: - ret = mmc_ocrbitnum_to_vdd(mmc->ios.vdd, &volt, &max_uV); - if (ret < 0) - return ret; - - dev_dbg(dev, "%s: found vmmc voltage range of %d-%duV\n", - __func__, volt, max_uV); - - min_uV = max(volt - 300000, 2700000); - max_uV = min(max_uV + 200000, 3600000); - - /* - * Due to a limitation in the current implementation of - * regulator_set_voltage_triplet() which is taking the lowest - * voltage possible if below the target, search for a suitable - * voltage in two steps and try to stay close to vmmc - * with a 0.3V tolerance at first. - */ - if (!mmc_regulator_set_voltage_if_supported(mmc->supply.vqmmc, - min_uV, volt, max_uV)) - return 0; - - return mmc_regulator_set_voltage_if_supported(mmc->supply.vqmmc, - 2700000, volt, 3600000); - default: - return -EINVAL; - } -} -EXPORT_SYMBOL_GPL(mmc_regulator_set_vqmmc); - -#endif /* CONFIG_REGULATOR */ - -/** - * mmc_regulator_get_supply - try to get VMMC and VQMMC regulators for a host - * @mmc: the host to regulate - * - * Returns 0 or errno. errno should be handled, it is either a critical error - * or -EPROBE_DEFER. 0 means no critical error but it does not mean all - * regulators have been found because they all are optional. If you require - * certain regulators, you need to check separately in your driver if they got - * populated after calling this function. - */ -int mmc_regulator_get_supply(struct mmc_host *mmc) -{ - struct device *dev = mmc_dev(mmc); - int ret; - - mmc->supply.vmmc = devm_regulator_get_optional(dev, "vmmc"); - mmc->supply.vqmmc = devm_regulator_get_optional(dev, "vqmmc"); - - if (IS_ERR(mmc->supply.vmmc)) { - if (PTR_ERR(mmc->supply.vmmc) == -EPROBE_DEFER) - return -EPROBE_DEFER; - dev_dbg(dev, "No vmmc regulator found\n"); - } else { - ret = mmc_regulator_get_ocrmask(mmc->supply.vmmc); - if (ret > 0) - mmc->ocr_avail = ret; - else - dev_warn(dev, "Failed getting OCR mask: %d\n", ret); - } - - if (IS_ERR(mmc->supply.vqmmc)) { - if (PTR_ERR(mmc->supply.vqmmc) == -EPROBE_DEFER) - return -EPROBE_DEFER; - dev_dbg(dev, "No vqmmc regulator found\n"); - } - - return 0; -} -EXPORT_SYMBOL_GPL(mmc_regulator_get_supply); - /* * Mask off any voltages we don't support and select * the lowest voltage diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h index 8fb6bc37f808..b5083b13d594 100644 --- a/drivers/mmc/core/core.h +++ b/drivers/mmc/core/core.h @@ -59,6 +59,7 @@ void mmc_power_up(struct mmc_host *host, u32 ocr); void mmc_power_off(struct mmc_host *host); void mmc_power_cycle(struct mmc_host *host, u32 ocr); void mmc_set_initial_state(struct mmc_host *host); +u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max); static inline void mmc_delay(unsigned int ms) { diff --git a/drivers/mmc/core/regulator.c b/drivers/mmc/core/regulator.c new file mode 100644 index 000000000000..80f95f86ca0e --- /dev/null +++ b/drivers/mmc/core/regulator.c @@ -0,0 +1,261 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Helper functions for MMC regulators. + */ + +#include +#include +#include +#include + +#include + +#include "core.h" +#include "host.h" + +#ifdef CONFIG_REGULATOR + +/** + * mmc_ocrbitnum_to_vdd - Convert a OCR bit number to its voltage + * @vdd_bit: OCR bit number + * @min_uV: minimum voltage value (mV) + * @max_uV: maximum voltage value (mV) + * + * This function returns the voltage range according to the provided OCR + * bit number. If conversion is not possible a negative errno value returned. + */ +static int mmc_ocrbitnum_to_vdd(int vdd_bit, int *min_uV, int *max_uV) +{ + int tmp; + + if (!vdd_bit) + return -EINVAL; + + /* + * REVISIT mmc_vddrange_to_ocrmask() may have set some + * bits this regulator doesn't quite support ... don't + * be too picky, most cards and regulators are OK with + * a 0.1V range goof (it's a small error percentage). + */ + tmp = vdd_bit - ilog2(MMC_VDD_165_195); + if (tmp == 0) { + *min_uV = 1650 * 1000; + *max_uV = 1950 * 1000; + } else { + *min_uV = 1900 * 1000 + tmp * 100 * 1000; + *max_uV = *min_uV + 100 * 1000; + } + + return 0; +} + +/** + * mmc_regulator_get_ocrmask - return mask of supported voltages + * @supply: regulator to use + * + * This returns either a negative errno, or a mask of voltages that + * can be provided to MMC/SD/SDIO devices using the specified voltage + * regulator. This would normally be called before registering the + * MMC host adapter. + */ +int mmc_regulator_get_ocrmask(struct regulator *supply) +{ + int result = 0; + int count; + int i; + int vdd_uV; + int vdd_mV; + + count = regulator_count_voltages(supply); + if (count < 0) + return count; + + for (i = 0; i < count; i++) { + vdd_uV = regulator_list_voltage(supply, i); + if (vdd_uV <= 0) + continue; + + vdd_mV = vdd_uV / 1000; + result |= mmc_vddrange_to_ocrmask(vdd_mV, vdd_mV); + } + + if (!result) { + vdd_uV = regulator_get_voltage(supply); + if (vdd_uV <= 0) + return vdd_uV; + + vdd_mV = vdd_uV / 1000; + result = mmc_vddrange_to_ocrmask(vdd_mV, vdd_mV); + } + + return result; +} +EXPORT_SYMBOL_GPL(mmc_regulator_get_ocrmask); + +/** + * mmc_regulator_set_ocr - set regulator to match host->ios voltage + * @mmc: the host to regulate + * @supply: regulator to use + * @vdd_bit: zero for power off, else a bit number (host->ios.vdd) + * + * Returns zero on success, else negative errno. + * + * MMC host drivers may use this to enable or disable a regulator using + * a particular supply voltage. This would normally be called from the + * set_ios() method. + */ +int mmc_regulator_set_ocr(struct mmc_host *mmc, + struct regulator *supply, + unsigned short vdd_bit) +{ + int result = 0; + int min_uV, max_uV; + + if (vdd_bit) { + mmc_ocrbitnum_to_vdd(vdd_bit, &min_uV, &max_uV); + + result = regulator_set_voltage(supply, min_uV, max_uV); + if (result == 0 && !mmc->regulator_enabled) { + result = regulator_enable(supply); + if (!result) + mmc->regulator_enabled = true; + } + } else if (mmc->regulator_enabled) { + result = regulator_disable(supply); + if (result == 0) + mmc->regulator_enabled = false; + } + + if (result) + dev_err(mmc_dev(mmc), + "could not set regulator OCR (%d)\n", result); + return result; +} +EXPORT_SYMBOL_GPL(mmc_regulator_set_ocr); + +static int mmc_regulator_set_voltage_if_supported(struct regulator *regulator, + int min_uV, int target_uV, + int max_uV) +{ + /* + * Check if supported first to avoid errors since we may try several + * signal levels during power up and don't want to show errors. + */ + if (!regulator_is_supported_voltage(regulator, min_uV, max_uV)) + return -EINVAL; + + return regulator_set_voltage_triplet(regulator, min_uV, target_uV, + max_uV); +} + +/** + * mmc_regulator_set_vqmmc - Set VQMMC as per the ios + * + * For 3.3V signaling, we try to match VQMMC to VMMC as closely as possible. + * That will match the behavior of old boards where VQMMC and VMMC were supplied + * by the same supply. The Bus Operating conditions for 3.3V signaling in the + * SD card spec also define VQMMC in terms of VMMC. + * If this is not possible we'll try the full 2.7-3.6V of the spec. + * + * For 1.2V and 1.8V signaling we'll try to get as close as possible to the + * requested voltage. This is definitely a good idea for UHS where there's a + * separate regulator on the card that's trying to make 1.8V and it's best if + * we match. + * + * This function is expected to be used by a controller's + * start_signal_voltage_switch() function. + */ +int mmc_regulator_set_vqmmc(struct mmc_host *mmc, struct mmc_ios *ios) +{ + struct device *dev = mmc_dev(mmc); + int ret, volt, min_uV, max_uV; + + /* If no vqmmc supply then we can't change the voltage */ + if (IS_ERR(mmc->supply.vqmmc)) + return -EINVAL; + + switch (ios->signal_voltage) { + case MMC_SIGNAL_VOLTAGE_120: + return mmc_regulator_set_voltage_if_supported(mmc->supply.vqmmc, + 1100000, 1200000, 1300000); + case MMC_SIGNAL_VOLTAGE_180: + return mmc_regulator_set_voltage_if_supported(mmc->supply.vqmmc, + 1700000, 1800000, 1950000); + case MMC_SIGNAL_VOLTAGE_330: + ret = mmc_ocrbitnum_to_vdd(mmc->ios.vdd, &volt, &max_uV); + if (ret < 0) + return ret; + + dev_dbg(dev, "%s: found vmmc voltage range of %d-%duV\n", + __func__, volt, max_uV); + + min_uV = max(volt - 300000, 2700000); + max_uV = min(max_uV + 200000, 3600000); + + /* + * Due to a limitation in the current implementation of + * regulator_set_voltage_triplet() which is taking the lowest + * voltage possible if below the target, search for a suitable + * voltage in two steps and try to stay close to vmmc + * with a 0.3V tolerance at first. + */ + if (!mmc_regulator_set_voltage_if_supported(mmc->supply.vqmmc, + min_uV, volt, max_uV)) + return 0; + + return mmc_regulator_set_voltage_if_supported(mmc->supply.vqmmc, + 2700000, volt, 3600000); + default: + return -EINVAL; + } +} +EXPORT_SYMBOL_GPL(mmc_regulator_set_vqmmc); + +#else + +static inline int mmc_regulator_get_ocrmask(struct regulator *supply) +{ + return 0; +} + +#endif /* CONFIG_REGULATOR */ + +/** + * mmc_regulator_get_supply - try to get VMMC and VQMMC regulators for a host + * @mmc: the host to regulate + * + * Returns 0 or errno. errno should be handled, it is either a critical error + * or -EPROBE_DEFER. 0 means no critical error but it does not mean all + * regulators have been found because they all are optional. If you require + * certain regulators, you need to check separately in your driver if they got + * populated after calling this function. + */ +int mmc_regulator_get_supply(struct mmc_host *mmc) +{ + struct device *dev = mmc_dev(mmc); + int ret; + + mmc->supply.vmmc = devm_regulator_get_optional(dev, "vmmc"); + mmc->supply.vqmmc = devm_regulator_get_optional(dev, "vqmmc"); + + if (IS_ERR(mmc->supply.vmmc)) { + if (PTR_ERR(mmc->supply.vmmc) == -EPROBE_DEFER) + return -EPROBE_DEFER; + dev_dbg(dev, "No vmmc regulator found\n"); + } else { + ret = mmc_regulator_get_ocrmask(mmc->supply.vmmc); + if (ret > 0) + mmc->ocr_avail = ret; + else + dev_warn(dev, "Failed getting OCR mask: %d\n", ret); + } + + if (IS_ERR(mmc->supply.vqmmc)) { + if (PTR_ERR(mmc->supply.vqmmc) == -EPROBE_DEFER) + return -EPROBE_DEFER; + dev_dbg(dev, "No vqmmc 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 d893902b2f1c..7f93747c8cdc 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -532,7 +532,6 @@ static inline int mmc_regulator_set_vqmmc(struct mmc_host *mmc, } #endif -u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max); int mmc_regulator_get_supply(struct mmc_host *mmc); static inline int mmc_card_is_removable(struct mmc_host *host) From patchwork Wed Feb 13 19:54:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 158249 Delivered-To: patches@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp470138jaa; Wed, 13 Feb 2019 11:54:55 -0800 (PST) X-Received: by 2002:a2e:9f49:: with SMTP id v9mr1316518ljk.77.1550087695123; Wed, 13 Feb 2019 11:54:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550087695; cv=none; d=google.com; s=arc-20160816; b=CUPZCHsnCKaU0cJ0UeIIad+ndH65+yAmiDl7Z/LhTeaviN9a4X7EvEXyDBc7J9WeLo 4d4r67pV54uBL99lBsNxprnJFXRjM8BElL9Vdwf40I1ktpx0x31xM3aRGqdlgYpV7vVJ bPwa5d1jfK3+pq3O5COVGAh3/Du+dBGKqiZQiBclh8eqyqf4Pd0nADzpVN6M7aVY5QHU oOKHN+Cx5kfz3oPlaOkM6hYjL09tpgU0tLzpPcAP/yWnfNo5XqAOyWowAhSkNoxBXhPz AVgGBWPd7n6ZzzC3DA3Lhekd6Q/6bLUKjHf1YnBF5oSgl1BDDmPizG9W8mj42+tXiEfs J9Qw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=wZaZoCFjoOtW+NkB6SOQlGphxZkvtBrenisM/NI1+ws=; b=seI5zCOCxs4RKg8WUn7LRyrHm2vNSpXfK9vw/+WCn9TvT90AmhxFLgI24Jm5F8aaWA y7cjCaDjIlvU/g3BN63y2o1Ecp3tpCJDM1PYNJ9tgrp2OzYALBkb6GZaBCLS+jTwEmzR 0E/1JbOpfN8n4H67WilJH0Z0LWy6rfowwKWyET7UGqd5YLPuAsJKm0rUoT+8xWg6cKTk EkyDOfjfywKzSLm5qr1w7TxwNq1hMa4nnaZv87ddJl8skSuxWbPS90HMr0OO8SFjy6UB x/21O9cC7ABbzaPbQPqWgr/zGgTYIJ47op7D1SQseNVTCGQVjf9BcnRLIez64XAIEn5u oaQw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="T/71x5mH"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id a4sor64937lfj.30.2019.02.13.11.54.54 for (Google Transport Security); Wed, 13 Feb 2019 11:54:55 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="T/71x5mH"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=wZaZoCFjoOtW+NkB6SOQlGphxZkvtBrenisM/NI1+ws=; b=T/71x5mHp4/YbTSYnNrTLCIxKYNrZgx3TPTDkGJylA6ydHNgs25x5lTXZxFeqpoLNF H/f3ab9UCumMUOQyWuKzVg9lDpPCm1m24/1JaG3n0xScXWFSEvZJuv8harhYZdKX54r2 BVIHQUQ1ljAEB75+VpEU73lVXh/XBSOqYKUABESQTq/qovtRwLIwgsbJZK4nPAql1gZu q/EwBEI8XfNauGA8zS85pSb4W3b3DnWH2LfMLTbpEac9q1gMwIAT2msjZeCiWtrZvw7T sYnQE+3L1bbTtdRBnD9k/toZg6LGgXbpsdhChO0I3Vf30GhZwb6V4UFl0Dw/uR84Luuh gJEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=wZaZoCFjoOtW+NkB6SOQlGphxZkvtBrenisM/NI1+ws=; b=V7Z+GYF34uDm3FRiE7i5+/NeQIe+mgIx6j7Jne6kZEbLUlYlJprBCZeRZa3QeUCq9g Wne6WR0PGBhPS+P+JTwKPG8sbWkWcEnHcvUjdyoYC2/URkwlIuY+yO9SDfr5E2/lY42W XmlSQpyjvSbMeumqfSlA3u2QWCVtwsnjgUqFFUSJpoouPt4S4LCrKjIq2AKLzSLUeQQt E8YyFNqnXR9nyTJH60xGyKgD9t65EKmRWP/QXlV7mmeEfSVR8WqR0xvgBhcJaOjVykq8 WYLbWXqHUguGVLoap2WbMuNO1OiMVcIPr49E99Lz0dP9EyPwSDff17WFg8i8H2PNNJ0X 7Lsw== X-Gm-Message-State: AHQUAuaMXNETMD0U3oQXU2mb0ktcqlt7EDq34cMrTO9iM0ao/ig9f1nm lDV6Io14w8viPUBxkQmX9fx10Kaw X-Google-Smtp-Source: AHgI3IbdqGwSgSZBf8gjVFizV2Sw5Y5te/C99WosOTYlWDoIIWcD/DWrNnOj6HFCBDqt0ZQ/ZA0GzQ== X-Received: by 2002:ac2:5090:: with SMTP id f16mr1451560lfm.132.1550087694592; Wed, 13 Feb 2019 11:54:54 -0800 (PST) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id g194sm39169lfg.55.2019.02.13.11.54.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 11:54:53 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Adrian Hunter Cc: Ulf Hansson Subject: [PATCH 5/7] mmc: core: Convert mmc_regulator_get_ocrmask() to static Date: Wed, 13 Feb 2019 20:54:41 +0100 Message-Id: <20190213195443.18935-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190213195443.18935-1-ulf.hansson@linaro.org> References: <20190213195443.18935-1-ulf.hansson@linaro.org> The only left user of mmc_regulator_get_ocrmask() is the mmc core itself. Therefore, let's drop the export and turn it into static. Signed-off-by: Ulf Hansson --- drivers/mmc/core/regulator.c | 3 +-- include/linux/mmc/host.h | 6 ------ 2 files changed, 1 insertion(+), 8 deletions(-) -- 2.17.1 diff --git a/drivers/mmc/core/regulator.c b/drivers/mmc/core/regulator.c index 80f95f86ca0e..b6febbcf8978 100644 --- a/drivers/mmc/core/regulator.c +++ b/drivers/mmc/core/regulator.c @@ -58,7 +58,7 @@ static int mmc_ocrbitnum_to_vdd(int vdd_bit, int *min_uV, int *max_uV) * regulator. This would normally be called before registering the * MMC host adapter. */ -int mmc_regulator_get_ocrmask(struct regulator *supply) +static int mmc_regulator_get_ocrmask(struct regulator *supply) { int result = 0; int count; @@ -90,7 +90,6 @@ int mmc_regulator_get_ocrmask(struct regulator *supply) return result; } -EXPORT_SYMBOL_GPL(mmc_regulator_get_ocrmask); /** * mmc_regulator_set_ocr - set regulator to match host->ios voltage diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 7f93747c8cdc..43d0f0c496f6 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -507,17 +507,11 @@ void sdio_run_irqs(struct mmc_host *host); void sdio_signal_irq(struct mmc_host *host); #ifdef CONFIG_REGULATOR -int mmc_regulator_get_ocrmask(struct regulator *supply); 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); #else -static inline int mmc_regulator_get_ocrmask(struct regulator *supply) -{ - return 0; -} - static inline int mmc_regulator_set_ocr(struct mmc_host *mmc, struct regulator *supply, unsigned short vdd_bit) From patchwork Wed Feb 13 19:54:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 158250 Delivered-To: patches@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp470150jaa; Wed, 13 Feb 2019 11:54:56 -0800 (PST) X-Received: by 2002:a2e:9a16:: with SMTP id o22-v6mr1368296lji.112.1550087696437; Wed, 13 Feb 2019 11:54:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550087696; cv=none; d=google.com; s=arc-20160816; b=0atp2YeGx0uaoi3Sfyen1ONqXy4oyHm7+S5aQXqG97rl1ESEbqna9vLUDRdktO2UpD RCngiM+DqKCxohFX5OAezo1XJ7L6DD8PR3gqgKoYic8Gej4k2c0jBJg195OlGflFo96L hauWMu/Q2NVwMh3zNh52gskuC3ACMXD3HZhmZRDT5Jfxz1cVcESVgFPd/uv6aGsxEAcB Mw0tf+wp8ZnaI9J874yDe1sZJZnGjQdaVh23B3VT/p85wAYiU+SYoQadFS6zn9u1Ni8G zk4tvFNUMfan1Mga5GIwr/de/p/81/so1hYWRp2yqRUJj2/PZ9siWDmjTszCQfaR+eVF 6m/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=MRqFhz7nKkdjRls5Ll0A5LeUiGAisfOYUztGbW66WvI=; b=s4zIwlIurfoRHOtE6ZEeMwuhT+f72qN2tVwdQEglv7l2lfPUwDqG1ufPS4VHTAf1oy cI3mFO3GxNq1NYCIdorvnkL0/JjgStXGKcyD4/IfcFGg4xkoweMBFn4JwDvRTDfZJ1fs jX3lIBi+VnuYHJI7FWrNUkdwFqnq9Bkidsf7Fs1LNEWogpeGWtIC+uhS5jU3MyhxqegD 0xOWVdAKaRjgm7Y2Zs2kT0iixcMEz5u/ALO5FwJv6KhBhEtKHGe6N9UHHNzsIM8/GrWe ACce1whTVqbWF9bB9/Zdp0DuFYtbMcyvFbcMBhvhd/1mYNJ7aQgIHsbhNgjVgflCGdqK dlsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P9+IJBWv; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id n10sor60498lfe.49.2019.02.13.11.54.56 for (Google Transport Security); Wed, 13 Feb 2019 11:54:56 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P9+IJBWv; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MRqFhz7nKkdjRls5Ll0A5LeUiGAisfOYUztGbW66WvI=; b=P9+IJBWv5AGiWVDo1cB1Tdh8vWIfJ93mJaEpslrhAWiaqvb890cGtZHuk+wySC3CY/ 7XtT1HKWHlgrmznn5VwjZ+IyV4vXuhjNSwt0k5fAwOaD4ZyOUvB/WdSUQQxRuZoB5E80 weFaO+7gOMZBcLRUKCRbDeScJTlDe27XIEFfxhkvd/ReRyPt3skKhZkKt8zZJH8dTGIF sCIr36yOVY78CKAiKHCJz8N9mJHfSoRWw0jLfS/GWCbVEFTtcKuxTOo5MkA0YEsARPlr 3kn0kQAGNLQvSnzJNhWlBpsfQrdiaVmLbg8C3CBo1ZL8r0TRPQQCl13cSm7PNvF7Es3q hpZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MRqFhz7nKkdjRls5Ll0A5LeUiGAisfOYUztGbW66WvI=; b=CcUbhKYcMOZgFRr4mEC28X5VsN243yqMjRR+0nyo//dlLesPK/43oIfZqPT5khQVOD IZWziCsEGu0m5oCgTKuYzsFndj7GJcj+fVqQyZUzbkIL6UAFHza3tdhv7Zqn/SM5AwWn xsjZGzoOOqijfeRpYgOI9i8d79VFFtmrXWZF2JuOGaXVZvosK0PUnaXIF6MYHo6ZTrZv yUktjtofK11eWG565XrzXKC8XHlKdJOOPIBftFJ9ITpQla2mRMTiNTrcnSNn5yLnpGSu d/v598zTLATtXx9cS4ko2I9zohzo+FFyKaSfm9RTz30t1IPLAwY50CB98aYbLnKbMjbs hpAA== X-Gm-Message-State: AHQUAuZnLKeEHHh78eK0QHmW2dtz5y2I9ef5HEl/2pd2yZqzsnvADiSX /Iuv1QWLX5gFBhzDZkDcQSFAEjSX7tMVBg== X-Google-Smtp-Source: AHgI3IaX+6CtEcWQ54lj+m5c5QHYpckxQoZ+36sanl4MT+NXM0HYIktF35gZM68xHhTLm49Pob8p/g== X-Received: by 2002:a19:6e0b:: with SMTP id j11mr1335191lfc.124.1550087695900; Wed, 13 Feb 2019 11:54:55 -0800 (PST) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id g194sm39169lfg.55.2019.02.13.11.54.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 11:54:55 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Adrian Hunter Cc: Ulf Hansson Subject: [PATCH 6/7] mmc: core: Move mmc_of_parse_voltage() to host.c Date: Wed, 13 Feb 2019 20:54:42 +0100 Message-Id: <20190213195443.18935-7-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190213195443.18935-1-ulf.hansson@linaro.org> References: <20190213195443.18935-1-ulf.hansson@linaro.org> MMC OF parsing functions, which parses various host DT properties, should stay close to each other. Therefore, let's move mmc_of_parse_voltage() close to mmc_of_parse() into host.c. Additionally, there is no reason to build the code only when CONFIG_OF is set, as there should be stub functions for the OF helpers that is being used, so let's drop this condition as well. Signed-off-by: Ulf Hansson --- drivers/mmc/core/core.c | 48 ----------------------------------------- drivers/mmc/core/host.c | 44 +++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 48 deletions(-) -- 2.17.1 diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index f796a6afb19b..659eb32c0246 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1112,54 +1112,6 @@ u32 mmc_vddrange_to_ocrmask(int vdd_min, int vdd_max) return mask; } -#ifdef CONFIG_OF - -/** - * mmc_of_parse_voltage - return mask of supported voltages - * @np: The device node need to be parsed. - * @mask: mask of voltages available for MMC/SD/SDIO - * - * Parse the "voltage-ranges" DT property, returning zero if it is not - * found, negative errno if the voltage-range specification is invalid, - * or one if the voltage-range is specified and successfully parsed. - */ -int mmc_of_parse_voltage(struct device_node *np, u32 *mask) -{ - const u32 *voltage_ranges; - int num_ranges, i; - - voltage_ranges = of_get_property(np, "voltage-ranges", &num_ranges); - num_ranges = num_ranges / sizeof(*voltage_ranges) / 2; - if (!voltage_ranges) { - pr_debug("%pOF: voltage-ranges unspecified\n", np); - return 0; - } - if (!num_ranges) { - pr_err("%pOF: voltage-ranges empty\n", np); - return -EINVAL; - } - - for (i = 0; i < num_ranges; i++) { - const int j = i * 2; - u32 ocr_mask; - - ocr_mask = mmc_vddrange_to_ocrmask( - be32_to_cpu(voltage_ranges[j]), - be32_to_cpu(voltage_ranges[j + 1])); - if (!ocr_mask) { - pr_err("%pOF: voltage-range #%d is invalid\n", - np, i); - return -EINVAL; - } - *mask |= ocr_mask; - } - - return 1; -} -EXPORT_SYMBOL(mmc_of_parse_voltage); - -#endif /* CONFIG_OF */ - static int mmc_of_get_func_num(struct device_node *node) { u32 reg; diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c index 652ea6502336..3a4402a79904 100644 --- a/drivers/mmc/core/host.c +++ b/drivers/mmc/core/host.c @@ -348,6 +348,50 @@ int mmc_of_parse(struct mmc_host *host) EXPORT_SYMBOL(mmc_of_parse); +/** + * mmc_of_parse_voltage - return mask of supported voltages + * @np: The device node need to be parsed. + * @mask: mask of voltages available for MMC/SD/SDIO + * + * Parse the "voltage-ranges" DT property, returning zero if it is not + * found, negative errno if the voltage-range specification is invalid, + * or one if the voltage-range is specified and successfully parsed. + */ +int mmc_of_parse_voltage(struct device_node *np, u32 *mask) +{ + const u32 *voltage_ranges; + int num_ranges, i; + + voltage_ranges = of_get_property(np, "voltage-ranges", &num_ranges); + num_ranges = num_ranges / sizeof(*voltage_ranges) / 2; + if (!voltage_ranges) { + pr_debug("%pOF: voltage-ranges unspecified\n", np); + return 0; + } + if (!num_ranges) { + pr_err("%pOF: voltage-ranges empty\n", np); + return -EINVAL; + } + + for (i = 0; i < num_ranges; i++) { + const int j = i * 2; + u32 ocr_mask; + + ocr_mask = mmc_vddrange_to_ocrmask( + be32_to_cpu(voltage_ranges[j]), + be32_to_cpu(voltage_ranges[j + 1])); + if (!ocr_mask) { + pr_err("%pOF: voltage-range #%d is invalid\n", + np, i); + return -EINVAL; + } + *mask |= ocr_mask; + } + + return 1; +} +EXPORT_SYMBOL(mmc_of_parse_voltage); + /** * mmc_alloc_host - initialise the per-host structure. * @extra: sizeof private data structure From patchwork Wed Feb 13 19:54:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 158251 Delivered-To: patches@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp470171jaa; Wed, 13 Feb 2019 11:54:58 -0800 (PST) X-Received: by 2002:a19:4847:: with SMTP id v68mr1310470lfa.136.1550087697985; Wed, 13 Feb 2019 11:54:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550087697; cv=none; d=google.com; s=arc-20160816; b=RYvpT5CkibvSa+iV9Or5lYN9zz7+USWQiOR06fTIu5bpKSTo3RU9n9YgIEx/wvjJZ6 koy8ZDYxRixIWrLDLHzyl7Sa4tJlUcN27zymBjU/YIIzb3np1HPQiEOwht/xO1k9dIjZ 4wO6t4B/Gxc/UiWFAmcHrzssau3QP4xQZxLuqZE6t06ouM/bq1QxrkU1HjUmqmDA+qTP X364fkI3mMWIVHac3Hsp6sN2bsDPu+52kFrW8I0gB9KKKmU366DHx+zfAf1zx+7ZhWm9 gWP+H8osuBY48QOLKgKNdRm4o8s3kSvOWV7ye7IYxq0/27PK5EfsgEcy9TG3t0xeEbVt yKhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QsrtEZTLEsP2XILqx5eH4QDILCJkqe7UoHCPhY85Pc0=; b=CBxb7WlsI9BdjVmT8qTKXeDssbXFKaNvESFtuxWZoG1W+JHlPZwc5u0isjNEPnGsXF ZII+hjhuB07xHHpenwGwhjzICdgdGNC6T0tGKEdSkZLbL9iX2XXgY/Bb0YVav1JbGz3K Eoya7DHEdAFcbRxGNZzImUBgmxg0L0TIOR48qfJtPrbV9MJqCzj5B3Z6YSNRdw+ASREa rBD8qJ+IUcpsD+qWeSidqvgDSGKt4sa/6LhlhHInTxONW5Rt+sV0OexIa68snm7wsrSf IpjG4e0wXjKVMdUlWvLH23PzRqY+7QyrSLqLk1DcIbGFvWf5v0WTkBM2NQqLkeOMh6o6 wVDA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="w/zJfg0g"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id d2sor62598lfk.41.2019.02.13.11.54.57 for (Google Transport Security); Wed, 13 Feb 2019 11:54:57 -0800 (PST) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="w/zJfg0g"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=QsrtEZTLEsP2XILqx5eH4QDILCJkqe7UoHCPhY85Pc0=; b=w/zJfg0g16k4bISobpl514UBQ03quu1cOWcrPWDeXNPIxozDRlontbcShYuBVwDR0q oQIwYqIEZTXdP0FhEir7+tj4W0DtwOOVpANBBQfX2etIKFJJsE3P6rDcVrqvEPvRYtIx HIM0uub2eAHbkNlgMtpe2Bvas1yME8zU/vCp/Ffu24hsMlvtral+CLIY7ds/ksm7NtNt yDgP/Bp6xYivrSuBphr3WwKqt6oGxJFOzZM1qd+x9hiKLHEaLdnrr/3o+AK1MenEBzuc jNVJhzgt3Gtj6wWT9fFsRENmeHkO2eeWYEWYXhIClSrsLfOPqwUGIyvaH4KjeN+zVvpd Cgxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=QsrtEZTLEsP2XILqx5eH4QDILCJkqe7UoHCPhY85Pc0=; b=MkG/FwCEoL9q5ROOs18dNaP5hG4kxTO4ylLhG6ujkxKHrkb1fpHAcECX0Aj/C+gZ52 uT+SNSmshEN0pZwYy8PV+ykuPrKvWhLC6dRF0lT1YxOOPBKBKgHts8SpSSMb0hfaZYXk HLwopXwIAR3lfNZsVkcUrVJt2lBJ37+2ylR1EpVrT+eCD8cx+fYh1j1gvVQS5sFhuIcV RPxx0NZz+keM+e3Ym34phd5ES6cLxSK8qmV/IzIP8nAULnQFXzShaIM3ZCnOQsiDu8Ma BrgweDIgWYdgjL/NnPkKW84DhOQWSRizJk7FQd5CgX1b77iPLLDq2pi4taxip3hHxHzW ablA== X-Gm-Message-State: AHQUAublkzoQmUuVYVyoPTaX2jb3JIIQKoJK0SQ1a3aSdFRUSM5Lfze6 bFkXuzZ4Lcre0wgp4NazWpWL9hN+ X-Google-Smtp-Source: AHgI3IbTqElkQ5+erA8bqWWq/eI2BNmj0F/NvUdAhIIAXGrAH83rhLvDBfZEGR6OsD8WSPleiLmWHQ== X-Received: by 2002:a19:f244:: with SMTP id d4mr1487588lfk.0.1550087697426; Wed, 13 Feb 2019 11:54:57 -0800 (PST) Return-Path: Received: from localhost.localdomain (h-158-174-22-210.NA.cust.bahnhof.se. [158.174.22.210]) by smtp.gmail.com with ESMTPSA id g194sm39169lfg.55.2019.02.13.11.54.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Feb 2019 11:54:56 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Adrian Hunter Cc: Ulf Hansson Subject: [PATCH 7/7] mmc: core: Convert mmc_align_data_size() into an SDIO specific function Date: Wed, 13 Feb 2019 20:54:43 +0100 Message-Id: <20190213195443.18935-8-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190213195443.18935-1-ulf.hansson@linaro.org> References: <20190213195443.18935-1-ulf.hansson@linaro.org> The only user of mmc_align_data_size() is sdio_align_size(), which is called from SDIO func drivers to let them distinguish, how to optimally allocate data buffers. Let's move mmc_align_data_size() close to the SDIO code as to make it static, rename it to _sdio_align_size() and simplify its definition, all with the purpose of clarifying that this is SDIO specific. Signed-off-by: Ulf Hansson --- drivers/mmc/core/core.c | 27 --------------------------- drivers/mmc/core/sdio_io.c | 30 ++++++++++++++++++++++-------- drivers/mmc/core/sdio_ops.h | 1 - 3 files changed, 22 insertions(+), 36 deletions(-) -- 2.17.1 diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 659eb32c0246..b45aaa904107 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -757,33 +757,6 @@ void mmc_set_data_timeout(struct mmc_data *data, const struct mmc_card *card) } EXPORT_SYMBOL(mmc_set_data_timeout); -/** - * mmc_align_data_size - pads a transfer size to a more optimal value - * @card: the MMC card associated with the data transfer - * @sz: original transfer size - * - * Pads the original data size with a number of extra bytes in - * order to avoid controller bugs and/or performance hits - * (e.g. some controllers revert to PIO for certain sizes). - * - * Returns the improved size, which might be unmodified. - * - * Note that this function is only relevant when issuing a - * single scatter gather entry. - */ -unsigned int mmc_align_data_size(struct mmc_card *card, unsigned int sz) -{ - /* - * FIXME: We don't have a system for the controller to tell - * the core about its problems yet, so for now we just 32-bit - * align the size. - */ - sz = ((sz + 3) / 4) * 4; - - return sz; -} -EXPORT_SYMBOL(mmc_align_data_size); - /* * Allow claiming an already claimed host if the context is the same or there is * no context but the task is the same. diff --git a/drivers/mmc/core/sdio_io.c b/drivers/mmc/core/sdio_io.c index d40744bbafa9..6ce089d6b1f5 100644 --- a/drivers/mmc/core/sdio_io.c +++ b/drivers/mmc/core/sdio_io.c @@ -203,6 +203,23 @@ static inline unsigned int sdio_max_byte_size(struct sdio_func *func) return min(mval, 512u); /* maximum size for byte mode */ } +/* + * This is legacy code, which needs to be re-worked some day. Basically we need + * to take into account the properties of the host, as to enable the SDIO func + * driver layer to allocate optimal buffers. + */ +static inline unsigned int _sdio_align_size(unsigned int sz) +{ + /* + * FIXME: We don't have a system for the controller to tell + * the core about its problems yet, so for now we just 32-bit + * align the size. + */ + sz = ((sz + 3) / 4) * 4; + + return sz; +} + /** * sdio_align_size - pads a transfer size to a more optimal value * @func: SDIO function @@ -230,7 +247,7 @@ unsigned int sdio_align_size(struct sdio_func *func, unsigned int sz) * wants to increase the size up to a point where it * might need more than one block. */ - sz = mmc_align_data_size(func->card, sz); + sz = _sdio_align_size(sz); /* * If we can still do this with just a byte transfer, then @@ -252,7 +269,7 @@ unsigned int sdio_align_size(struct sdio_func *func, unsigned int sz) */ blk_sz = ((sz + func->cur_blksize - 1) / func->cur_blksize) * func->cur_blksize; - blk_sz = mmc_align_data_size(func->card, blk_sz); + blk_sz = _sdio_align_size(blk_sz); /* * This value is only good if it is still just @@ -265,8 +282,7 @@ unsigned int sdio_align_size(struct sdio_func *func, unsigned int sz) * We failed to do one request, but at least try to * pad the remainder properly. */ - byte_sz = mmc_align_data_size(func->card, - sz % func->cur_blksize); + byte_sz = _sdio_align_size(sz % func->cur_blksize); if (byte_sz <= sdio_max_byte_size(func)) { blk_sz = sz / func->cur_blksize; return blk_sz * func->cur_blksize + byte_sz; @@ -276,16 +292,14 @@ unsigned int sdio_align_size(struct sdio_func *func, unsigned int sz) * We need multiple requests, so first check that the * controller can handle the chunk size; */ - chunk_sz = mmc_align_data_size(func->card, - sdio_max_byte_size(func)); + chunk_sz = _sdio_align_size(sdio_max_byte_size(func)); if (chunk_sz == sdio_max_byte_size(func)) { /* * Fix up the size of the remainder (if any) */ byte_sz = orig_sz % chunk_sz; if (byte_sz) { - byte_sz = mmc_align_data_size(func->card, - byte_sz); + byte_sz = _sdio_align_size(byte_sz); } return (orig_sz / chunk_sz) * chunk_sz + byte_sz; diff --git a/drivers/mmc/core/sdio_ops.h b/drivers/mmc/core/sdio_ops.h index 96945cafbf0b..1f6d0447ea0f 100644 --- a/drivers/mmc/core/sdio_ops.h +++ b/drivers/mmc/core/sdio_ops.h @@ -25,7 +25,6 @@ int mmc_io_rw_direct(struct mmc_card *card, int write, unsigned fn, int mmc_io_rw_extended(struct mmc_card *card, int write, unsigned fn, unsigned addr, int incr_addr, u8 *buf, unsigned blocks, unsigned blksz); int sdio_reset(struct mmc_host *host); -unsigned int mmc_align_data_size(struct mmc_card *card, unsigned int sz); void sdio_irq_work(struct work_struct *work); static inline bool sdio_is_io_busy(u32 opcode, u32 arg)