From patchwork Fri Jul 14 21:40:03 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 9841717 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8299560381 for ; Fri, 14 Jul 2017 21:40:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7248E287B3 for ; Fri, 14 Jul 2017 21:40:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 66981287CB; Fri, 14 Jul 2017 21:40:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6A23F287B3 for ; Fri, 14 Jul 2017 21:40:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=zXfo0XzzeI3MqyB/uUwO6KmX3bRRuSF5lQd9OqIxgiE=; b=NF7loEw0tee1lLFVNsdl/qwyYy 65HAMqn/giQ3Wrxhb4MdR/65MWwEbvNdCQIF0ovcJFhWOTF1JdlNuXYUvpMRC//W5heYv6ZrXMweF C86af7+wImn+gY4Sld8M/v2TSFbwf0AkQUmlwLll7OGE0FXzvDOiMdimKCev6ghEPc7UWDhck9fzd maPmyERgNv13pMo++Kyvg6x2qAk7Hws8EK8ZzyWzQu6vCG0LKvEDY6mRVXHf9FMMuFltkhs3utHUV 7PM41jnbNI0mO7UIAgY7E30Vv1xQDFzYB0uOmyQQtvusqlti2LGXiZMj5ozY9ZXoylEzcMTCt5V4y PokqYuxA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dW8KN-0008Ox-Fv; Fri, 14 Jul 2017 21:40:47 +0000 Received: from mail-pg0-x22f.google.com ([2607:f8b0:400e:c05::22f]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dW8K5-00089b-JL for linux-arm-kernel@lists.infradead.org; Fri, 14 Jul 2017 21:40:31 +0000 Received: by mail-pg0-x22f.google.com with SMTP id 123so743712pgd.3 for ; Fri, 14 Jul 2017 14:40:09 -0700 (PDT) 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=BSaWw6a+xDUoGSsN4nCPJ9z58VZBw6s5QYBmlJGAuh4=; b=TvWVioOxW+O+cvv65lFFaV01FubZdloIvr31eAz+r24GO37t5xtHyCWHV7CvQi3bi5 lhyU2lXDkaU82vpLEA7sfJjY2YG+67XQBjRdTh+cJUhOwqzcYRx+fRTORxOWDZDUK7dG i+MHP6cNwD8SvO3ICocP+f/AGpranX3oukkCs= 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=BSaWw6a+xDUoGSsN4nCPJ9z58VZBw6s5QYBmlJGAuh4=; b=qpoe/JORnJ5Jf4CG/o/tw5EyxmsDO5Q8IhwPEU7D/90UlWTr7Kwjo1ZC4MK5cVQwBn E+ngXcH3EWWltRJHYUbihbMayr7zPMSwowz/ISrE6lwrCpA1+jBUE3VijKMYnA4cJgdN 4Jfgmt20EjctQaZPQqwDQ0a5ebOxhhuHdx6iLAubN3sQSd6+EKwud+raZZYmwANJY1PT RIHt9PRcyI9MUp9YeesvXBKBIWyixKat2i3mwXOHPtpCc0MFk894yus1b+xDg83gGRr/ 9t1eMfg2vIB95B1d0isHbZ2jcJGzqD4SQsF1UEgXMIr1Cjbe//2SX4XGebUD3QGmMWSY QLwg== X-Gm-Message-State: AIVw111TytVb0bug2CFJxQWwDTrKZt3tiNKeE0JspHs9FX//eEX2MC1x BfxZ9fZg2eak6028 X-Received: by 10.84.132.73 with SMTP id 67mr17985650ple.53.1500068408984; Fri, 14 Jul 2017 14:40:08 -0700 (PDT) Received: from localhost.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id e13sm17795271pfh.96.2017.07.14.14.40.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 14 Jul 2017 14:40:08 -0700 (PDT) From: Stephen Boyd To: Peter Rosin Subject: [PATCH v2 1/3] mux: Add mux_control_get_optional() API Date: Fri, 14 Jul 2017 14:40:03 -0700 Message-Id: <20170714214005.14967-2-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.10.0.297.gf6727b0 In-Reply-To: <20170714214005.14967-1-stephen.boyd@linaro.org> References: <20170714214005.14967-1-stephen.boyd@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170714_144029_675619_BFED89F4 X-CRM114-Status: GOOD ( 21.14 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Peter Chen , linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org, Jonathan Cameron , Rob Clark , Rob Herring , devicetree@vger.infradead.org, Philipp Zabel , Andy Gross , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Sometimes drivers only use muxes under certain scenarios. For example, the chipidea usb controller may be connected to a usb switch on some platforms, and connected directly to a usb port on others. The driver won't know one way or the other though, so add a mux_control_get_optional() API that allows the driver to differentiate errors getting the mux from there not being a mux for the driver to use at all. Cc: Jonathan Cameron Cc: Philipp Zabel Signed-off-by: Stephen Boyd --- Documentation/driver-model/devres.txt | 1 + drivers/mux/mux-core.c | 98 ++++++++++++++++++++++++++++------- include/linux/mux/consumer.h | 4 ++ 3 files changed, 83 insertions(+), 20 deletions(-) diff --git a/Documentation/driver-model/devres.txt b/Documentation/driver-model/devres.txt index 30e04f7a690d..4fdd3e63ff8b 100644 --- a/Documentation/driver-model/devres.txt +++ b/Documentation/driver-model/devres.txt @@ -342,6 +342,7 @@ MUX devm_mux_chip_alloc() devm_mux_chip_register() devm_mux_control_get() + devm_mux_control_get_optional() PER-CPU MEM devm_alloc_percpu() diff --git a/drivers/mux/mux-core.c b/drivers/mux/mux-core.c index 90b8995f07cb..a0e5bf16f02f 100644 --- a/drivers/mux/mux-core.c +++ b/drivers/mux/mux-core.c @@ -289,6 +289,9 @@ EXPORT_SYMBOL_GPL(devm_mux_chip_register); */ unsigned int mux_control_states(struct mux_control *mux) { + if (!mux) + return 0; + return mux->states; } EXPORT_SYMBOL_GPL(mux_control_states); @@ -338,6 +341,9 @@ int mux_control_select(struct mux_control *mux, unsigned int state) { int ret; + if (!mux) + return 0; + ret = down_killable(&mux->lock); if (ret < 0) return ret; @@ -370,6 +376,9 @@ int mux_control_try_select(struct mux_control *mux, unsigned int state) { int ret; + if (!mux) + return 0; + if (down_trylock(&mux->lock)) return -EBUSY; @@ -398,6 +407,9 @@ int mux_control_deselect(struct mux_control *mux) { int ret = 0; + if (!mux) + return 0; + if (mux->idle_state != MUX_IDLE_AS_IS && mux->idle_state != mux->cached_state) ret = mux_control_set(mux, mux->idle_state); @@ -422,14 +434,8 @@ static struct mux_chip *of_find_mux_chip_by_node(struct device_node *np) return dev ? to_mux_chip(dev) : NULL; } -/** - * mux_control_get() - Get the mux-control for a device. - * @dev: The device that needs a mux-control. - * @mux_name: The name identifying the mux-control. - * - * Return: A pointer to the mux-control, or an ERR_PTR with a negative errno. - */ -struct mux_control *mux_control_get(struct device *dev, const char *mux_name) +struct mux_control * +__mux_control_get(struct device *dev, const char *mux_name, bool optional) { struct device_node *np = dev->of_node; struct of_phandle_args args; @@ -441,6 +447,8 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name) if (mux_name) { index = of_property_match_string(np, "mux-control-names", mux_name); + if (index == -EINVAL && optional) + return NULL; if (index < 0) { dev_err(dev, "mux controller '%s' not found\n", mux_name); @@ -451,6 +459,8 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name) ret = of_parse_phandle_with_args(np, "mux-controls", "#mux-control-cells", index, &args); + if (ret == -ENOENT && optional) + return NULL; if (ret) { dev_err(dev, "%s: failed to get mux-control %s(%i)\n", np->full_name, mux_name ?: "", index); @@ -482,9 +492,35 @@ struct mux_control *mux_control_get(struct device *dev, const char *mux_name) get_device(&mux_chip->dev); return &mux_chip->mux[controller]; } + +/** + * mux_control_get() - Get the mux-control for a device. + * @dev: The device that needs a mux-control. + * @mux_name: The name identifying the mux-control. + * + * Return: A pointer to the mux-control, or an ERR_PTR with a negative errno. + */ +struct mux_control *mux_control_get(struct device *dev, const char *mux_name) +{ + return __mux_control_get(dev, mux_name, false); +} EXPORT_SYMBOL_GPL(mux_control_get); /** + * mux_control_get_optional() - Get the optional mux-control for a device. + * @dev: The device that needs a mux-control. + * @mux_name: The name identifying the mux-control. + * + * Return: A pointer to the mux-control, or an ERR_PTR with a negative errno. + */ +struct mux_control * +mux_control_get_optional(struct device *dev, const char *mux_name) +{ + return __mux_control_get(dev, mux_name, true); +} +EXPORT_SYMBOL_GPL(mux_control_get_optional); + +/** * mux_control_put() - Put away the mux-control for good. * @mux: The mux-control to put away. * @@ -492,7 +528,8 @@ EXPORT_SYMBOL_GPL(mux_control_get); */ void mux_control_put(struct mux_control *mux) { - put_device(&mux->chip->dev); + if (mux) + put_device(&mux->chip->dev); } EXPORT_SYMBOL_GPL(mux_control_put); @@ -503,16 +540,8 @@ static void devm_mux_control_release(struct device *dev, void *res) mux_control_put(mux); } -/** - * devm_mux_control_get() - Get the mux-control for a device, with resource - * management. - * @dev: The device that needs a mux-control. - * @mux_name: The name identifying the mux-control. - * - * Return: Pointer to the mux-control, or an ERR_PTR with a negative errno. - */ -struct mux_control *devm_mux_control_get(struct device *dev, - const char *mux_name) +static struct mux_control * +__devm_mux_control_get(struct device *dev, const char *mux_name, bool optional) { struct mux_control **ptr, *mux; @@ -520,7 +549,7 @@ struct mux_control *devm_mux_control_get(struct device *dev, if (!ptr) return ERR_PTR(-ENOMEM); - mux = mux_control_get(dev, mux_name); + mux = __mux_control_get(dev, mux_name, optional); if (IS_ERR(mux)) { devres_free(ptr); return mux; @@ -531,8 +560,37 @@ struct mux_control *devm_mux_control_get(struct device *dev, return mux; } + +/** + * devm_mux_control_get() - Get the mux-control for a device, with resource + * management. + * @dev: The device that needs a mux-control. + * @mux_name: The name identifying the mux-control. + * + * Return: Pointer to the mux-control, or an ERR_PTR with a negative errno. + */ +struct mux_control * +devm_mux_control_get(struct device *dev, const char *mux_name) +{ + return __devm_mux_control_get(dev, mux_name, false); +} EXPORT_SYMBOL_GPL(devm_mux_control_get); +/** + * devm_mux_control_get_optional() - Get the optional mux-control for a device, + * with resource management. + * @dev: The device that needs a mux-control. + * @mux_name: The name identifying the mux-control. + * + * Return: Pointer to the mux-control, or an ERR_PTR with a negative errno. + */ +struct mux_control * +devm_mux_control_get_optional(struct device *dev, const char *mux_name) +{ + return __devm_mux_control_get(dev, mux_name, true); +} +EXPORT_SYMBOL_GPL(devm_mux_control_get_optional); + /* * Using subsys_initcall instead of module_init here to try to ensure - for * the non-modular case - that the subsystem is initialized when mux consumers diff --git a/include/linux/mux/consumer.h b/include/linux/mux/consumer.h index 5577e1b773c4..5e2aa046f032 100644 --- a/include/linux/mux/consumer.h +++ b/include/linux/mux/consumer.h @@ -24,9 +24,13 @@ int __must_check mux_control_try_select(struct mux_control *mux, int mux_control_deselect(struct mux_control *mux); struct mux_control *mux_control_get(struct device *dev, const char *mux_name); +struct mux_control *mux_control_get_optional(struct device *dev, + const char *mux_name); void mux_control_put(struct mux_control *mux); struct mux_control *devm_mux_control_get(struct device *dev, const char *mux_name); +struct mux_control *devm_mux_control_get_optional(struct device *dev, + const char *mux_name); #endif /* _LINUX_MUX_CONSUMER_H */