From patchwork Sun Dec 2 08:43:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 152648 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp5558188ljp; Sun, 2 Dec 2018 00:46:42 -0800 (PST) X-Google-Smtp-Source: AFSGD/VaYiqyVZqFgdC/X6n+EqVca+7ogguujl1XlQL0Nf0m6L9AzQwA+Usg6SvE5jjsBEPGBTur X-Received: by 2002:a62:18ce:: with SMTP id 197mr12122331pfy.88.1543740402530; Sun, 02 Dec 2018 00:46:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543740402; cv=none; d=google.com; s=arc-20160816; b=UKE6FY0AQbuYO4e/9itps1m9haM3YnSwZRk6p0S5V17S1hh6N7T7smrN/WWQo148v/ /wa+OZdGF5QUDsuaZmuh0upklWTNl/5K7ewSI1VczOx+UOiH/3amOxmeLaz+rJjd8uqy wCJ1BytciWUq/2XtF3rGvqjhTHYl70Tku8UPTAvq37Ltu+i+77weBW4YlnZhn56U7pto cNkAwl9TUko+j42rxV6XWvrgOewjgJsYTFW82Pas0kph6EwR8bBfPH0r+Tu/vwl6xEPE SnqlrhhfpIuitdd0xjVREcuzmD/e4e1hhXszmwC8f3cmxZH72IRte9igjo89Sy27Y/tO 4Y9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=u1REikvF/xAmj8LDazOidCX7wUMOJor+Ed+rW1LtCpc=; b=TouS4NjdfFicdEckVlTraJYg0e2XD3k7/efpJDNmTNZTLPk5JJpHUSmrY6FEaTDnvW mMr/IOQaw5BacCYm16RatKSs+b7XMwJgiYn8iR3/FTqoBdK1TEJIweglg5VvPRBsONC8 Shl8ZcqHUkoDyXUgyb/w989+q55F2cv+tI3QiYeiawUxdFhcV/oQNxeg+/0ZQhDWk+W9 AtPkhQAGmB2U7wIc8CGwBY9h+P2gCcrVxUJBzoNjXwMZ0DZS2aI6vymMta4FgbIRkRge STnHYAjaBaSLs6bbawsD2Ymgh4WIdvDk1kjlaHyBG56Mb1n0ZnSYzdq1oXVTX80LYa+y vBgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Bi2OejjF; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 28si9351748pgz.593.2018.12.02.00.46.42; Sun, 02 Dec 2018 00:46:42 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Bi2OejjF; spf=pass (google.com: best guess record for domain of linux-mmc-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-mmc-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725801AbeLBIqn (ORCPT + 5 others); Sun, 2 Dec 2018 03:46:43 -0500 Received: from mail-lj1-f194.google.com ([209.85.208.194]:39397 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725771AbeLBIqm (ORCPT ); Sun, 2 Dec 2018 03:46:42 -0500 Received: by mail-lj1-f194.google.com with SMTP id t9-v6so8590265ljh.6 for ; Sun, 02 Dec 2018 00:46:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=u1REikvF/xAmj8LDazOidCX7wUMOJor+Ed+rW1LtCpc=; b=Bi2OejjF7PZt6eHPKlzkBG4lZpR2HewvlIDohoq1J3ZaBuGJbNTgAjc8MozjgmCcSq XdrboDBDo2TdXot9KNPW54DbHilN9NJm/9kYXBLrRMOGAntnct5Sc+WEOaTKTgl6R/0J rCSSqjEhR9UCPoUMNRQ1SJ0QZxGJ5Cqp97pVE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u1REikvF/xAmj8LDazOidCX7wUMOJor+Ed+rW1LtCpc=; b=LxnrWkyi3FRFuIWNjAlt6n/M6AD7kSs4oHBrbG4D1aNSZjJKCCeE3D0A8yUuBFTyDR jk2jNEobiP9MZZl49gMthCUkw4+GlLZAk5//dWYHGgZx3QbA2La7dzLtOstn6TzdhwbZ HdtWt9+c/LwwMyiqHJ+AVIJ2nzUUhSVK3eoaNHC3kL7VlOnaFFW/7e3/4zxIM++dL0yT 6TNzBcTkLWeeZu+d6ZTunXjGLvAhZnHohC3LH7afFLTz7NxQcIXshFBm+akqkbLhmjlI 1SxbpJSr9GBBUIN5CLsCAXvUWARbCaT1ZkPCBhX65POdRWvmETeXjgjiChe4MUi3zlIk r0hw== X-Gm-Message-State: AA+aEWZgguDIHQrNSrH1d6ThJH90+dbbq5Q5exaGxg+6yC6MONUCvzyW xBRro7Q4nQBlNGojFZa9hD/tekNmTxPhaw== X-Received: by 2002:a2e:81a:: with SMTP id 26-v6mr8117067lji.14.1543740391743; Sun, 02 Dec 2018 00:46:31 -0800 (PST) Received: from localhost.localdomain (c-ae7b71d5.014-348-6c756e10.bbcust.telenor.se. [213.113.123.174]) by smtp.gmail.com with ESMTPSA id z7-v6sm1772719lji.42.2018.12.02.00.46.29 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 02 Dec 2018 00:46:30 -0800 (PST) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Linus Walleij , Hartley Sweeten , Kuninori Morimoto Subject: [PATCH 01/11 v4] mmc: spi: Convert to use GPIO descriptors Date: Sun, 2 Dec 2018 09:43:18 +0100 Message-Id: <20181202084328.25546-2-linus.walleij@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181202084328.25546-1-linus.walleij@linaro.org> References: <20181202084328.25546-1-linus.walleij@linaro.org> MIME-Version: 1.0 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Switch the SPI MMC driver to use GPIO descriptors internally and just look those up using the standard slot GPIO functions mmc_gpiod_request_cd() and mmc_gpiod_request_ro(). Make sure to request index 0 and 1 in accordance with the SPI MMC DT binding, and add the same GPIOs in machine descriptor tables on all boards that use SPI MMC in board files. The lines are flagged as GPIO_ACTIVE_[LOW|HIGH] as that is what they are, and since we can now rely on the descriptors to have the right polarity, we set the "override_active_level" to false in mmc_gpiod_request_cd() and mmc_gpiod_request_ro(). Cc: Hartley Sweeten # Vision EP9307 Cc: Kuninori Morimoto Reviewed-by: Laurent Pinchart Signed-off-by: Linus Walleij --- ChangeLog v3->v4: - Collect Laurent's ACK. - Fix commit message to say why we do not override the active level anymore. ChangeLog v1->v3: - Resending on top of the applied patches. - Hartley: it'd be great if you could test this series on the Vision EP9307. - Kuninori/Laurent: hope one of you has this Ecovec board so you can test it too. --- arch/arm/mach-ep93xx/simone.c | 14 +++++++++--- arch/arm/mach-ep93xx/vision_ep9307.c | 17 ++++++++++---- arch/sh/boards/mach-ecovec24/setup.c | 17 +++++++++++--- drivers/mmc/host/mmc_spi.c | 27 ++++++++++++---------- drivers/mmc/host/of_mmc_spi.c | 34 ---------------------------- include/linux/spi/mmc_spi.h | 15 ------------ 6 files changed, 53 insertions(+), 71 deletions(-) -- 2.19.1 diff --git a/arch/arm/mach-ep93xx/simone.c b/arch/arm/mach-ep93xx/simone.c index 41aa57581356..80ccb984d521 100644 --- a/arch/arm/mach-ep93xx/simone.c +++ b/arch/arm/mach-ep93xx/simone.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -45,9 +46,15 @@ static struct ep93xxfb_mach_info __initdata simone_fb_info = { static struct mmc_spi_platform_data simone_mmc_spi_data = { .detect_delay = 500, .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, - .flags = MMC_SPI_USE_CD_GPIO, - .cd_gpio = EP93XX_GPIO_LINE_EGPIO0, - .cd_debounce = 1, +}; + +static struct gpiod_lookup_table simone_mmc_spi_gpio_table = { + .dev_id = "mmc_spi.0", /* "mmc_spi" @ CS0 */ + .table = { + /* Card detect */ + GPIO_LOOKUP_IDX("A", 0, NULL, 0, GPIO_ACTIVE_LOW), + { }, + }, }; static struct spi_board_info simone_spi_devices[] __initdata = { @@ -105,6 +112,7 @@ static void __init simone_init_machine(void) ep93xx_register_fb(&simone_fb_info); ep93xx_register_i2c(simone_i2c_board_info, ARRAY_SIZE(simone_i2c_board_info)); + gpiod_add_lookup_table(&simone_mmc_spi_gpio_table); ep93xx_register_spi(&simone_spi_info, simone_spi_devices, ARRAY_SIZE(simone_spi_devices)); simone_register_audio(); diff --git a/arch/arm/mach-ep93xx/vision_ep9307.c b/arch/arm/mach-ep93xx/vision_ep9307.c index 5a0b6187990a..767ee64628dc 100644 --- a/arch/arm/mach-ep93xx/vision_ep9307.c +++ b/arch/arm/mach-ep93xx/vision_ep9307.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -202,13 +203,20 @@ static struct mmc_spi_platform_data vision_spi_mmc_data = { .detect_delay = 100, .powerup_msecs = 100, .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, - .flags = MMC_SPI_USE_CD_GPIO | MMC_SPI_USE_RO_GPIO, - .cd_gpio = EP93XX_GPIO_LINE_EGPIO15, - .cd_debounce = 1, - .ro_gpio = EP93XX_GPIO_LINE_F(0), .caps2 = MMC_CAP2_RO_ACTIVE_HIGH, }; +static struct gpiod_lookup_table vision_spi_mmc_gpio_table = { + .dev_id = "mmc_spi.2", /* "mmc_spi @ CS2 */ + .table = { + /* Card detect */ + GPIO_LOOKUP_IDX("B", 7, NULL, 0, GPIO_ACTIVE_LOW), + /* Write protect */ + GPIO_LOOKUP_IDX("F", 0, NULL, 1, GPIO_ACTIVE_HIGH), + { }, + }, +}; + /************************************************************************* * SPI Bus *************************************************************************/ @@ -286,6 +294,7 @@ static void __init vision_init_machine(void) ep93xx_register_i2c(vision_i2c_info, ARRAY_SIZE(vision_i2c_info)); + gpiod_add_lookup_table(&vision_spi_mmc_gpio_table); ep93xx_register_spi(&vision_spi_master, vision_spi_board_info, ARRAY_SIZE(vision_spi_board_info)); vision_register_i2s(); diff --git a/arch/sh/boards/mach-ecovec24/setup.c b/arch/sh/boards/mach-ecovec24/setup.c index 06a894526a0b..3097307b7cb7 100644 --- a/arch/sh/boards/mach-ecovec24/setup.c +++ b/arch/sh/boards/mach-ecovec24/setup.c @@ -776,9 +776,19 @@ static struct mmc_spi_platform_data mmc_spi_info = { .caps2 = MMC_CAP2_RO_ACTIVE_HIGH, .ocr_mask = MMC_VDD_32_33 | MMC_VDD_33_34, /* 3.3V only */ .setpower = mmc_spi_setpower, - .flags = MMC_SPI_USE_CD_GPIO | MMC_SPI_USE_RO_GPIO, - .cd_gpio = GPIO_PTY7, - .ro_gpio = GPIO_PTY6, +}; + +static struct gpiod_lookup_table mmc_spi_gpio_table = { + .dev_id = "mmc_spi.0", /* device "mmc_spi" @ CS0 */ + .table = { + /* Card detect */ + GPIO_LOOKUP_IDX("sh7724_pfc", GPIO_PTY7, NULL, 0, + GPIO_ACTIVE_LOW), + /* Write protect */ + GPIO_LOOKUP_IDX("sh7724_pfc", GPIO_PTY6, NULL, 1, + GPIO_ACTIVE_HIGH), + { }, + }, }; static struct spi_board_info spi_bus[] = { @@ -1282,6 +1292,7 @@ static int __init arch_setup(void) gpio_request(GPIO_PTB6, NULL); /* 3.3V power control */ gpio_direction_output(GPIO_PTB6, 0); /* disable power by default */ + gpiod_add_lookup_table(&mmc_spi_gpio_table); spi_register_board_info(spi_bus, ARRAY_SIZE(spi_bus)); #endif diff --git a/drivers/mmc/host/mmc_spi.c b/drivers/mmc/host/mmc_spi.c index 476e53d30128..10ba46b728e8 100644 --- a/drivers/mmc/host/mmc_spi.c +++ b/drivers/mmc/host/mmc_spi.c @@ -1434,13 +1434,16 @@ static int mmc_spi_probe(struct spi_device *spi) if (status != 0) goto fail_add_host; - if (host->pdata && host->pdata->flags & MMC_SPI_USE_CD_GPIO) { - status = mmc_gpio_request_cd(mmc, host->pdata->cd_gpio, - host->pdata->cd_debounce); - if (status != 0) - goto fail_add_host; - - /* The platform has a CD GPIO signal that may support + /* + * Index 0 is card detect + * Old boardfiles were specifying 1 ms as debounce + */ + status = mmc_gpiod_request_cd(mmc, NULL, 0, false, 1, NULL); + if (status == -EPROBE_DEFER) + goto fail_add_host; + if (!status) { + /* + * The platform has a CD GPIO signal that may support * interrupts, so let mmc_gpiod_request_cd_irq() decide * if polling is needed or not. */ @@ -1448,12 +1451,12 @@ static int mmc_spi_probe(struct spi_device *spi) mmc_gpiod_request_cd_irq(mmc); } - if (host->pdata && host->pdata->flags & MMC_SPI_USE_RO_GPIO) { + /* Index 1 is write protect/read only */ + status = mmc_gpiod_request_ro(mmc, NULL, 1, false, 0, NULL); + if (status == -EPROBE_DEFER) + goto fail_add_host; + if (!status) has_ro = true; - status = mmc_gpio_request_ro(mmc, host->pdata->ro_gpio); - if (status != 0) - goto fail_add_host; - } dev_info(&spi->dev, "SD/MMC host %s%s%s%s%s\n", dev_name(&mmc->class_dev), diff --git a/drivers/mmc/host/of_mmc_spi.c b/drivers/mmc/host/of_mmc_spi.c index c9eed8436b6b..b294b221f225 100644 --- a/drivers/mmc/host/of_mmc_spi.c +++ b/drivers/mmc/host/of_mmc_spi.c @@ -16,9 +16,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -32,15 +30,7 @@ MODULE_LICENSE("GPL"); -enum { - CD_GPIO = 0, - WP_GPIO, - NUM_GPIOS, -}; - struct of_mmc_spi { - int gpios[NUM_GPIOS]; - bool alow_gpios[NUM_GPIOS]; int detect_irq; struct mmc_spi_platform_data pdata; }; @@ -102,30 +92,6 @@ struct mmc_spi_platform_data *mmc_spi_get_pdata(struct spi_device *spi) oms->pdata.ocr_mask |= mask; } - for (i = 0; i < ARRAY_SIZE(oms->gpios); i++) { - enum of_gpio_flags gpio_flags; - - oms->gpios[i] = of_get_gpio_flags(np, i, &gpio_flags); - if (!gpio_is_valid(oms->gpios[i])) - continue; - - if (gpio_flags & OF_GPIO_ACTIVE_LOW) - oms->alow_gpios[i] = true; - } - - if (gpio_is_valid(oms->gpios[CD_GPIO])) { - oms->pdata.cd_gpio = oms->gpios[CD_GPIO]; - oms->pdata.flags |= MMC_SPI_USE_CD_GPIO; - if (!oms->alow_gpios[CD_GPIO]) - oms->pdata.caps2 |= MMC_CAP2_CD_ACTIVE_HIGH; - } - if (gpio_is_valid(oms->gpios[WP_GPIO])) { - oms->pdata.ro_gpio = oms->gpios[WP_GPIO]; - oms->pdata.flags |= MMC_SPI_USE_RO_GPIO; - if (!oms->alow_gpios[WP_GPIO]) - oms->pdata.caps2 |= MMC_CAP2_RO_ACTIVE_HIGH; - } - oms->detect_irq = irq_of_parse_and_map(np, 0); if (oms->detect_irq != 0) { oms->pdata.init = of_mmc_spi_init; diff --git a/include/linux/spi/mmc_spi.h b/include/linux/spi/mmc_spi.h index bfde741a543d..778ae8eb1f3e 100644 --- a/include/linux/spi/mmc_spi.h +++ b/include/linux/spi/mmc_spi.h @@ -8,11 +8,6 @@ struct device; struct mmc_host; -#define MMC_SPI_USE_CD_GPIO (1 << 0) -#define MMC_SPI_USE_RO_GPIO (1 << 1) -#define MMC_SPI_CD_GPIO_ACTIVE_LOW (1 << 2) -#define MMC_SPI_RO_GPIO_ACTIVE_LOW (1 << 3) - /* Put this in platform_data of a device being used to manage an MMC/SD * card slot. (Modeled after PXA mmc glue; see that for usage examples.) * @@ -27,16 +22,6 @@ struct mmc_spi_platform_data { void *); void (*exit)(struct device *, void *); - /* - * Card Detect and Read Only GPIOs. To enable debouncing on the card - * detect GPIO, set the cd_debounce to the debounce time in - * microseconds. - */ - unsigned int flags; - unsigned int cd_gpio; - unsigned int cd_debounce; - unsigned int ro_gpio; - /* Capabilities to pass into mmc core (e.g. MMC_CAP_NEEDS_POLL). */ unsigned long caps; unsigned long caps2;