From patchwork Mon Jan 19 09:13:03 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 5655821 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 43DF99F2ED for ; Mon, 19 Jan 2015 09:21:16 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 5718A2034A for ; Mon, 19 Jan 2015 09:21:15 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5DB2D20306 for ; Mon, 19 Jan 2015 09:21:14 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1YD8TO-00085D-MN; Mon, 19 Jan 2015 09:18:14 +0000 Received: from mail-la0-f41.google.com ([209.85.215.41]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1YD8Ru-0007OX-HF for linux-arm-kernel@lists.infradead.org; Mon, 19 Jan 2015 09:16:44 +0000 Received: by mail-la0-f41.google.com with SMTP id gm9so1507741lab.0 for ; Mon, 19 Jan 2015 01:16:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=H0u8fThr12gw7IWdfja2PzydVc8dB2lRM+l8syEtbzQ=; b=f/v1Es7tU0Rd7b3ZPlLHTmEdE1Sh/LPX+Ko+dW6V0QAKbZBk+9eRwuiiRrq6Ol0eLg JbeUG3D44b5Bdwah28qZa7IDxH0i1JeooREm+fQIoyOQF/6XC+bdGLOTOpi4sSTr2GFf iNxLofIb5rKqyqigdfYklAZhH7c8G+Y4uKqpKfhEi32VUfGJF5fKP01M09eIWvcU5wEu mKTIahwvqJ1LsrqtVerlQDdGVX3FLAKLDuZ4IXN24ToDqQWTd9+5J/9dMiWZsb+85Erh MVaJtMomJ/OQje/WF96mCHezzbqKBwOl+RRSIj8YmqmW2AQnpISglfy7BaeSDSYvG7cL cISw== X-Gm-Message-State: ALoCoQk8rvKZzM+6uEBh3ZUfLhBJboj2BE6nDaxenvyae+W3Fj2DB5oQI2eSgWqHYgOFJwYymbTp X-Received: by 10.112.54.167 with SMTP id k7mr3710414lbp.72.1421658978785; Mon, 19 Jan 2015 01:16:18 -0800 (PST) Received: from localhost.localdomain ([85.235.11.236]) by mx.google.com with ESMTPSA id zo3sm2933894lbb.10.2015.01.19.01.16.16 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 19 Jan 2015 01:16:17 -0800 (PST) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Chris Ball Subject: [PATCH V4 3/4] mmc: pwrseq: Initial support for the simple MMC power sequence provider Date: Mon, 19 Jan 2015 10:13:03 +0100 Message-Id: <1421658784-11980-4-git-send-email-ulf.hansson@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1421658784-11980-1-git-send-email-ulf.hansson@linaro.org> References: <1421658784-11980-1-git-send-email-ulf.hansson@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20150119_011643_011371_3D586060 X-CRM114-Status: GOOD ( 20.58 ) X-Spam-Score: -0.7 (/) Cc: Mark Rutland , devicetree@vger.kernel.org, Hans de Goede , Russell King , Tomeu Vizoso , Arnd Bergmann , Alexandre Courbot , NeilBrown , Linus Walleij , Doug Anderson , Olof Johansson , Mark Brown , Arend van Spriel , Ulf Hansson , Sascha Hauer , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP To add the core part for the MMC power sequence, let's start by adding initial support for the simple MMC power sequence provider. In this initial step, the MMC power sequence node are fetched and the compatible string for the simple MMC power sequence provider are verified. At this point we don't parse the node for any properties, but instead that will be handled from following patches. Since there are no properties supported yet, let's just implement the ->alloc() and the ->free() callbacks. Signed-off-by: Ulf Hansson Reviewed-by: Javier Martinez Canillas Tested-by: Javier Martinez Canillas --- Changes in v4: - Fixed call to kfree(). --- drivers/mmc/core/Makefile | 2 +- drivers/mmc/core/pwrseq.c | 61 +++++++++++++++++++++++++++++++++++++++- drivers/mmc/core/pwrseq.h | 2 ++ drivers/mmc/core/pwrseq_simple.c | 48 +++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 drivers/mmc/core/pwrseq_simple.c diff --git a/drivers/mmc/core/Makefile b/drivers/mmc/core/Makefile index ccdd35f..b39cbd2 100644 --- a/drivers/mmc/core/Makefile +++ b/drivers/mmc/core/Makefile @@ -8,5 +8,5 @@ mmc_core-y := core.o bus.o host.o \ sdio.o sdio_ops.o sdio_bus.o \ sdio_cis.o sdio_io.o sdio_irq.o \ quirks.o slot-gpio.o -mmc_core-$(CONFIG_OF) += pwrseq.o +mmc_core-$(CONFIG_OF) += pwrseq.o pwrseq_simple.o mmc_core-$(CONFIG_DEBUG_FS) += debugfs.o diff --git a/drivers/mmc/core/pwrseq.c b/drivers/mmc/core/pwrseq.c index bd08772..2cea00e 100644 --- a/drivers/mmc/core/pwrseq.c +++ b/drivers/mmc/core/pwrseq.c @@ -7,14 +7,73 @@ * * MMC power sequence management */ +#include +#include +#include +#include +#include + #include #include "pwrseq.h" +struct mmc_pwrseq_match { + const char *compatible; + int (*alloc)(struct mmc_host *host, struct device *dev); +}; + +static struct mmc_pwrseq_match pwrseq_match[] = { + { + .compatible = "mmc-pwrseq-simple", + .alloc = mmc_pwrseq_simple_alloc, + }, +}; + +static struct mmc_pwrseq_match *mmc_pwrseq_find(struct device_node *np) +{ + struct mmc_pwrseq_match *match = ERR_PTR(-ENODEV); + int i; + + for (i = 0; i < ARRAY_SIZE(pwrseq_match); i++) { + if (of_device_is_compatible(np, pwrseq_match[i].compatible)) { + match = &pwrseq_match[i]; + break; + } + } + + return match; +} int mmc_pwrseq_alloc(struct mmc_host *host) { - return 0; + struct platform_device *pdev; + struct device_node *np; + struct mmc_pwrseq_match *match; + int ret = 0; + + np = of_parse_phandle(host->parent->of_node, "mmc-pwrseq", 0); + if (!np) + return 0; + + pdev = of_find_device_by_node(np); + if (!pdev) { + ret = -ENODEV; + goto err; + } + + match = mmc_pwrseq_find(np); + if (IS_ERR(match)) { + ret = PTR_ERR(match); + goto err; + } + + ret = match->alloc(host, &pdev->dev); + if (!ret) + dev_info(host->parent, "allocated mmc-pwrseq\n"); + +err: + of_node_put(np); + return ret; } void mmc_pwrseq_pre_power_on(struct mmc_host *host) diff --git a/drivers/mmc/core/pwrseq.h b/drivers/mmc/core/pwrseq.h index 12aaf2b..bd860d8 100644 --- a/drivers/mmc/core/pwrseq.h +++ b/drivers/mmc/core/pwrseq.h @@ -27,6 +27,8 @@ void mmc_pwrseq_post_power_on(struct mmc_host *host); void mmc_pwrseq_power_off(struct mmc_host *host); void mmc_pwrseq_free(struct mmc_host *host); +int mmc_pwrseq_simple_alloc(struct mmc_host *host, struct device *dev); + #else static inline int mmc_pwrseq_alloc(struct mmc_host *host) { return 0; } diff --git a/drivers/mmc/core/pwrseq_simple.c b/drivers/mmc/core/pwrseq_simple.c new file mode 100644 index 0000000..61c991e --- /dev/null +++ b/drivers/mmc/core/pwrseq_simple.c @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2014 Linaro Ltd + * + * Author: Ulf Hansson + * + * License terms: GNU General Public License (GPL) version 2 + * + * Simple MMC power sequence management + */ +#include +#include +#include +#include + +#include + +#include "pwrseq.h" + +struct mmc_pwrseq_simple { + struct mmc_pwrseq pwrseq; +}; + +static void mmc_pwrseq_simple_free(struct mmc_host *host) +{ + struct mmc_pwrseq_simple *pwrseq = container_of(host->pwrseq, + struct mmc_pwrseq_simple, pwrseq); + + kfree(pwrseq); + host->pwrseq = NULL; +} + +static struct mmc_pwrseq_ops mmc_pwrseq_simple_ops = { + .free = mmc_pwrseq_simple_free, +}; + +int mmc_pwrseq_simple_alloc(struct mmc_host *host, struct device *dev) +{ + struct mmc_pwrseq_simple *pwrseq; + + pwrseq = kzalloc(sizeof(struct mmc_pwrseq_simple), GFP_KERNEL); + if (!pwrseq) + return -ENOMEM; + + pwrseq->pwrseq.ops = &mmc_pwrseq_simple_ops; + host->pwrseq = &pwrseq->pwrseq; + + return 0; +}