From patchwork Mon Nov 12 14:12:32 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 150841 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp3190898ljp; Mon, 12 Nov 2018 06:12:59 -0800 (PST) X-Google-Smtp-Source: AJdET5f3kHPE/cEapXX9GPRFUSoVJBafvn9HRwIXlDSlpzJfml62Wb2T3ycfvZCgfjoQSxFiLEXV X-Received: by 2002:a63:2586:: with SMTP id l128mr997955pgl.104.1542031979526; Mon, 12 Nov 2018 06:12:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542031979; cv=none; d=google.com; s=arc-20160816; b=jVRNqDKlxy7OvVJOGR5WCynGHQDlz8t6yOtd1nAE0on6XY1t3GRLRNOBQuUuPfsOAy ygU5HPOpoj24y4F11Pdtk3+p9xlGp+VhBTcNTUmTY6IngcdkiYFB6Xc5y+nOwkcaCJ5w lbRbPHYMdqU4IOTfFdshh2pFglJGXMvfZSNqiF0Cd7V72Vk6WQBEYVGyPG04QytHkbsm qCN1uQTaddJw+cac+0WhSRtqWib5z1pY7S3jZA4OSHdJXw5s7Jj0Rv2VC8erUuzUZAXe kWEPQgylpTubZ4gaKfL7w/vPPHglKt5brGHTa7vty8iOHL+wM/qlnbNH3O3nl7qpLASp XSHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=uyjO+El3MvuzjjZ225bk+ZX6NPv73zT4TF8rtrL6ozw=; b=zW1OJKlviXho2p9JOSnIiMjhQar+1iTQJmNnd5f+1eE/eCkM3sXYSVQAWpOiBV0FHm u/wyGNlZTeMJQSFCl4/HP82B0YMLL+SnnkqSl95hw9IIqPZyDxVI+p1yZasFENTz7Z19 mJc5GCPu3D9ba6jwitqBQ9RZjY8mUwIbqOG2WoOqr/+C+O7y5wBPm0CGClwp9NecDLSY 8/pl0MvwU8+kT/hhlaq5AdTPa5wPUIuvVxjVIudmU+M6qDH/NE+V8ar252/4rQUieAxT /WZoRfd3PWi3DxPuoAjeEVaGyrwNyzFpbZdKjdlu3DBQRW7tRaf1RMVhasH0d8lI8hXf Yypg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E7ULJOoS; 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 h68-v6si19277640pfb.142.2018.11.12.06.12.59; Mon, 12 Nov 2018 06:12:59 -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=E7ULJOoS; 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 S1729756AbeKMAGZ (ORCPT + 5 others); Mon, 12 Nov 2018 19:06:25 -0500 Received: from mail-lf1-f68.google.com ([209.85.167.68]:45195 "EHLO mail-lf1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727103AbeKMAGZ (ORCPT ); Mon, 12 Nov 2018 19:06:25 -0500 Received: by mail-lf1-f68.google.com with SMTP id b20so6248397lfa.12 for ; Mon, 12 Nov 2018 06:12:56 -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; bh=uyjO+El3MvuzjjZ225bk+ZX6NPv73zT4TF8rtrL6ozw=; b=E7ULJOoS9VqJCsh8FXBvOvv6E7+kbFqeTbqHByoKAkGkqrJizrPlqkBTn34JG6j2e/ fa98zG0kg6oxLmOP9wEa5LOoX24nz++pnDqAQaRIKKi6WzHqgy17qGYPvf9tvUIPqUbC BhFVf1QZv51XGD5UR17Nvz00qyQKWQQ5iUZKY= 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=uyjO+El3MvuzjjZ225bk+ZX6NPv73zT4TF8rtrL6ozw=; b=WBWL69OPd0wSmBMapsPwxGvFon5ZUGZxGbu3nEE2HPe+5d9SbDPDvGZHtzcjCMi7tD G3uDMePCRPJ56RJ7Ck0MZGOmeY0j8Qahow2PMmzNPO376cGqC4pN5O6oJkmUa/x98OMu qf51+DkSra0qvCGqSD0bbZs/XYKffT04Uq1KHVHC4Ez2PmerSjOByvR+w/yzRvcEmb5p lkrVFR3+B6ZifcsLzDOPNqsUz5YUaYXVq6ymNAqKDRfMh/RqsYg3RH73wF5W7Uy/I/Kk BujhYariU6e7rl0C0kyM21ONpF97ghAFVb9UeYsuE740/Hzlr9EmPe1z6HeUq9MbZnXI k28A== X-Gm-Message-State: AGRZ1gK74iW9N0JJVFG019SUwgELj/s+yeu7kafqpuXWqQrVSwAobtx2 4Vfmf/HWuNbaKBB6dQbbYtwRwMXtfg45xQ== X-Received: by 2002:a19:c4cc:: with SMTP id u195mr687899lff.141.1542031975042; Mon, 12 Nov 2018 06:12:55 -0800 (PST) Received: from genomnajs.ideon.se ([85.235.10.227]) by smtp.gmail.com with ESMTPSA id m14-v6sm3056889lji.29.2018.11.12.06.12.53 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Nov 2018 06:12:54 -0800 (PST) From: Linus Walleij To: linux-mmc@vger.kernel.org, Ulf Hansson Cc: Linus Walleij , Paul Cercueil , linux-mips@linux-mips.org Subject: [PATCH 03/10] mmc: jz4740: Use GPIO descriptor for power Date: Mon, 12 Nov 2018 15:12:32 +0100 Message-Id: <20181112141239.19646-4-linus.walleij@linaro.org> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20181112141239.19646-1-linus.walleij@linaro.org> References: <20181112141239.19646-1-linus.walleij@linaro.org> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org The power GPIO line is passed with inversion flags and all from the platform data. Switch to using an optional GPIO descriptor and use this to switch the power. Augment the only boardfile to pass in the proper "power" descriptor in the GPIO descriptor machine table instead. As the GPIO handling is now much simpler, we can cut down on some overhead code. Cc: Paul Cercueil Cc: linux-mips@linux-mips.org Signed-off-by: Linus Walleij --- .../mips/include/asm/mach-jz4740/jz4740_mmc.h | 2 - arch/mips/jz4740/board-qi_lb60.c | 6 +- drivers/mmc/host/jz4740_mmc.c | 65 +++++-------------- 3 files changed, 18 insertions(+), 55 deletions(-) -- 2.17.2 Acked-by: Paul Burton diff --git a/arch/mips/include/asm/mach-jz4740/jz4740_mmc.h b/arch/mips/include/asm/mach-jz4740/jz4740_mmc.h index ff50aeb1a933..9a7de47c7c79 100644 --- a/arch/mips/include/asm/mach-jz4740/jz4740_mmc.h +++ b/arch/mips/include/asm/mach-jz4740/jz4740_mmc.h @@ -3,10 +3,8 @@ #define __LINUX_MMC_JZ4740_MMC struct jz4740_mmc_platform_data { - int gpio_power; unsigned card_detect_active_low:1; unsigned read_only_active_low:1; - unsigned power_active_low:1; unsigned data_1bit:1; }; diff --git a/arch/mips/jz4740/board-qi_lb60.c b/arch/mips/jz4740/board-qi_lb60.c index 705593d40d12..6718efb400f4 100644 --- a/arch/mips/jz4740/board-qi_lb60.c +++ b/arch/mips/jz4740/board-qi_lb60.c @@ -43,8 +43,6 @@ #include "clock.h" /* GPIOs */ -#define QI_LB60_GPIO_SD_VCC_EN_N JZ_GPIO_PORTD(2) - #define QI_LB60_GPIO_KEYOUT(x) (JZ_GPIO_PORTC(10) + (x)) #define QI_LB60_GPIO_KEYIN(x) (JZ_GPIO_PORTD(18) + (x)) #define QI_LB60_GPIO_KEYIN8 JZ_GPIO_PORTD(26) @@ -385,14 +383,14 @@ static struct platform_device qi_lb60_gpio_keys = { }; static struct jz4740_mmc_platform_data qi_lb60_mmc_pdata = { - .gpio_power = QI_LB60_GPIO_SD_VCC_EN_N, - .power_active_low = 1, + /* Intentionally left blank */ }; static struct gpiod_lookup_table qi_lb60_mmc_gpio_table = { .dev_id = "jz4740-mmc.0", .table = { GPIO_LOOKUP("GPIOD", 0, "cd", GPIO_ACTIVE_HIGH), + GPIO_LOOKUP("GPIOD", 2, "power", GPIO_ACTIVE_LOW), { }, }, }; diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c index 44ea452add8e..6f7a99e54af0 100644 --- a/drivers/mmc/host/jz4740_mmc.c +++ b/drivers/mmc/host/jz4740_mmc.c @@ -21,7 +21,7 @@ #include #include #include -#include +#include #include #include #include @@ -136,6 +136,7 @@ struct jz4740_mmc_host { struct platform_device *pdev; struct jz4740_mmc_platform_data *pdata; struct clk *clk; + struct gpio_desc *power; enum jz4740_mmc_version version; @@ -903,18 +904,16 @@ static void jz4740_mmc_set_ios(struct mmc_host *mmc, struct mmc_ios *ios) switch (ios->power_mode) { case MMC_POWER_UP: jz4740_mmc_reset(host); - if (host->pdata && gpio_is_valid(host->pdata->gpio_power)) - gpio_set_value(host->pdata->gpio_power, - !host->pdata->power_active_low); + if (host->power) + gpiod_set_value(host->power, 1); host->cmdat |= JZ_MMC_CMDAT_INIT; clk_prepare_enable(host->clk); break; case MMC_POWER_ON: break; default: - if (host->pdata && gpio_is_valid(host->pdata->gpio_power)) - gpio_set_value(host->pdata->gpio_power, - host->pdata->power_active_low); + if (host->power) + gpiod_set_value(host->power, 0); clk_disable_unprepare(host->clk); break; } @@ -947,30 +946,9 @@ static const struct mmc_host_ops jz4740_mmc_ops = { .enable_sdio_irq = jz4740_mmc_enable_sdio_irq, }; -static int jz4740_mmc_request_gpio(struct device *dev, int gpio, - const char *name, bool output, int value) -{ - int ret; - - if (!gpio_is_valid(gpio)) - return 0; - - ret = gpio_request(gpio, name); - if (ret) { - dev_err(dev, "Failed to request %s gpio: %d\n", name, ret); - return ret; - } - - if (output) - gpio_direction_output(gpio, value); - else - gpio_direction_input(gpio); - - return 0; -} - -static int jz4740_mmc_request_gpios(struct mmc_host *mmc, - struct platform_device *pdev) +static int jz4740_mmc_request_gpios(struct jz4740_mmc_host *host, + struct mmc_host *mmc, + struct platform_device *pdev) { struct jz4740_mmc_platform_data *pdata = dev_get_platdata(&pdev->dev); int ret = 0; @@ -995,19 +973,12 @@ static int jz4740_mmc_request_gpios(struct mmc_host *mmc, if (ret == -EPROBE_DEFER) return ret; - return jz4740_mmc_request_gpio(&pdev->dev, pdata->gpio_power, - "MMC read only", true, pdata->power_active_low); -} - -static void jz4740_mmc_free_gpios(struct platform_device *pdev) -{ - struct jz4740_mmc_platform_data *pdata = dev_get_platdata(&pdev->dev); - - if (!pdata) - return; + host->power = devm_gpiod_get_optional(&pdev->dev, "power", + GPIOD_OUT_HIGH); + if (IS_ERR(host->power)) + return PTR_ERR(host->power); - if (gpio_is_valid(pdata->gpio_power)) - gpio_free(pdata->gpio_power); + return 0; } static const struct of_device_id jz4740_mmc_of_match[] = { @@ -1053,7 +1024,7 @@ static int jz4740_mmc_probe(struct platform_device* pdev) mmc->caps |= MMC_CAP_SDIO_IRQ; if (!(pdata && pdata->data_1bit)) mmc->caps |= MMC_CAP_4_BIT_DATA; - ret = jz4740_mmc_request_gpios(mmc, pdev); + ret = jz4740_mmc_request_gpios(host, mmc, pdev); if (ret) goto err_free_host; } @@ -1104,7 +1075,7 @@ static int jz4740_mmc_probe(struct platform_device* pdev) dev_name(&pdev->dev), host); if (ret) { dev_err(&pdev->dev, "Failed to request irq: %d\n", ret); - goto err_free_gpios; + goto err_free_host; } jz4740_mmc_clock_disable(host); @@ -1135,8 +1106,6 @@ static int jz4740_mmc_probe(struct platform_device* pdev) jz4740_mmc_release_dma_channels(host); err_free_irq: free_irq(host->irq, host); -err_free_gpios: - jz4740_mmc_free_gpios(pdev); err_free_host: mmc_free_host(mmc); @@ -1155,8 +1124,6 @@ static int jz4740_mmc_remove(struct platform_device *pdev) free_irq(host->irq, host); - jz4740_mmc_free_gpios(pdev); - if (host->use_dma) jz4740_mmc_release_dma_channels(host);