ath10k.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Bjorn Andersson <bjorn.andersson@linaro.org>
To: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Cc: Andy Gross <agross@kernel.org>,
	Ulf Hansson <ulf.hansson@linaro.org>,
	Marcel Holtmann <marcel@holtmann.org>,
	Johan Hedberg <johan.hedberg@gmail.com>,
	Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
	Kalle Valo <kvalo@codeaurora.org>,
	"David S. Miller" <davem@davemloft.net>,
	Jakub Kicinski <kuba@kernel.org>,
	Stanimir Varbanov <svarbanov@mm-sol.com>,
	linux-arm-msm@vger.kernel.org, linux-mmc@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-bluetooth@vger.kernel.org,
	ath10k@lists.infradead.org, linux-wireless@vger.kernel.org,
	netdev@vger.kernel.org
Subject: Re: [RFC PATCH 01/15] power: add power sequencer subsystem
Date: Thu, 19 Aug 2021 16:37:43 -0700	[thread overview]
Message-ID: <YR7rR6d4nSRea1oX@ripper> (raw)
In-Reply-To: <20210817005507.1507580-2-dmitry.baryshkov@linaro.org>

On Mon 16 Aug 17:54 PDT 2021, Dmitry Baryshkov wrote:

> Basing on MMC's pwrseq support code, add separate power sequencer
> subsystem. It will be used by other drivers to handle device power up
> requirements.
> 

Some more background to why we need a pwrseq framework wouldn't hurt.

[..]
> diff --git a/drivers/power/pwrseq/core.c b/drivers/power/pwrseq/core.c
> new file mode 100644
> index 000000000000..20485cae29aa
> --- /dev/null
> +++ b/drivers/power/pwrseq/core.c
> @@ -0,0 +1,411 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +//
> +// Copyright 2021 (c) Linaro Ltd.
> +// Author: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
> +//
> +// Based on phy-core.c:
> +// Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com

The typical format is:

// SPDX using C++ style comment
/*
 * Copyright stuff using C style comment
 */

> +
> +#include <linux/device.h>
> +#include <linux/idr.h>
> +#include <linux/module.h>
> +#include <linux/mutex.h>
> +#include <linux/pm_runtime.h>
> +#include <linux/pwrseq/consumer.h>
> +#include <linux/pwrseq/driver.h>
> +#include <linux/slab.h>
> +
> +#define	to_pwrseq(a)	(container_of((a), struct pwrseq, dev))

No need for the extra parenthesis around container_of()

> +
> +static DEFINE_IDA(pwrseq_ida);
> +static DEFINE_MUTEX(pwrseq_provider_mutex);
> +static LIST_HEAD(pwrseq_provider_list);
> +
> +struct pwrseq_provider {
> +	struct device		*dev;
> +	struct module		*owner;
> +	struct list_head	list;
> +	void			*data;
> +	struct pwrseq * (*of_xlate)(void *data, struct of_phandle_args *args);
> +};
> +
> +void pwrseq_put(struct device *dev, struct pwrseq *pwrseq)
> +{
> +	device_link_remove(dev, &pwrseq->dev);
> +
> +	module_put(pwrseq->owner);
> +	put_device(&pwrseq->dev);
> +}
> +EXPORT_SYMBOL_GPL(pwrseq_put);
> +
> +static struct pwrseq_provider *of_pwrseq_provider_lookup(struct device_node *node)
> +{
> +	struct pwrseq_provider *pwrseq_provider;
> +
> +	list_for_each_entry(pwrseq_provider, &pwrseq_provider_list, list) {
> +		if (pwrseq_provider->dev->of_node == node)
> +			return pwrseq_provider;
> +	}
> +
> +	return ERR_PTR(-EPROBE_DEFER);
> +}
> +
> +static struct pwrseq *_of_pwrseq_get(struct device *dev, const char *id)
> +{
> +	struct pwrseq_provider *pwrseq_provider;
> +	struct pwrseq *pwrseq;
> +	struct of_phandle_args args;
> +	char prop_name[64]; /* 64 is max size of property name */
> +	int ret;
> +
> +	snprintf(prop_name, 64, "%s-pwrseq", id);

sizeof(prop_name), to avoid giving others a chance to "fix" it later?

> +	ret = of_parse_phandle_with_args(dev->of_node, prop_name, "#pwrseq-cells", 0, &args);
> +	if (ret) {
> +		struct device_node *dn;
> +
> +		/*
> +		 * Parsing failed. Try locating old bindings for mmc-pwrseq,
> +		 * which did not use #pwrseq-cells.
> +		 */
> +		if (strcmp(id, "mmc"))
> +			return ERR_PTR(-ENODEV);
> +
> +		dn = of_parse_phandle(dev->of_node, prop_name, 0);
> +		if (!dn)
> +			return ERR_PTR(-ENODEV);
> +
> +		args.np = dn;
> +		args.args_count = 0;
> +	}
> +
> +	mutex_lock(&pwrseq_provider_mutex);
> +	pwrseq_provider = of_pwrseq_provider_lookup(args.np);
> +	if (IS_ERR(pwrseq_provider) || !try_module_get(pwrseq_provider->owner)) {
> +		pwrseq = ERR_PTR(-EPROBE_DEFER);
> +		goto out_unlock;
> +	}
> +
> +	if (!of_device_is_available(args.np)) {
> +		dev_warn(pwrseq_provider->dev, "Requested pwrseq is disabled\n");
> +		pwrseq = ERR_PTR(-ENODEV);
> +		goto out_put_module;
> +	}
> +
> +	pwrseq = pwrseq_provider->of_xlate(pwrseq_provider->data, &args);
> +
> +out_put_module:
> +	module_put(pwrseq_provider->owner);
> +
> +out_unlock:
> +	mutex_unlock(&pwrseq_provider_mutex);
> +	of_node_put(args.np);
> +
> +	return pwrseq;
> +}
> +
[..]
> +int pwrseq_pre_power_on(struct pwrseq *pwrseq)
> +{
> +	if (pwrseq && pwrseq->ops->pre_power_on)
> +		return pwrseq->ops->pre_power_on(pwrseq);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(pwrseq_pre_power_on);
> +
> +int pwrseq_power_on(struct pwrseq *pwrseq)

Wouldn't it make sense to refcount the power on/off operations and at
least warn about unbalanced disables?

My concern is related to the qca-driver's reliance on the regulator
framework to refcount the on/off of the shared resources and additional
power_off from either the WiFi or BT client would result in the other
client getting its power disabled unexpectedly - which might be
annoying to debug.

> +{
> +	if (pwrseq && pwrseq->ops->power_on)
> +		return pwrseq->ops->power_on(pwrseq);
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(pwrseq_power_on);
> +
> +void pwrseq_power_off(struct pwrseq *pwrseq)
> +{
> +	if (pwrseq && pwrseq->ops->power_off)
> +		pwrseq->ops->power_off(pwrseq);
> +}
> +EXPORT_SYMBOL_GPL(pwrseq_power_off);
> +
> +void pwrseq_reset(struct pwrseq *pwrseq)
> +{
> +	if (pwrseq && pwrseq->ops->reset)
> +		pwrseq->ops->reset(pwrseq);
> +}
> +EXPORT_SYMBOL_GPL(pwrseq_reset);
> +

Regards,
Bjorn

_______________________________________________
ath10k mailing list
ath10k@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/ath10k

  reply	other threads:[~2021-08-19 23:36 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-17  0:54 [RFC PATCH 00/15] create power sequencing subsystem Dmitry Baryshkov
2021-08-17  0:54 ` [RFC PATCH 01/15] power: add power sequencer subsystem Dmitry Baryshkov
2021-08-19 23:37   ` Bjorn Andersson [this message]
2021-08-17  0:54 ` [RFC PATCH 02/15] pwrseq: port MMC's pwrseq drivers to new pwrseq subsystem Dmitry Baryshkov
2021-08-17  0:54 ` [RFC PATCH 03/15] mmc: core: switch " Dmitry Baryshkov
2021-08-17  0:54 ` [RFC PATCH 04/15] ath10k: add support for pwrseq sequencing Dmitry Baryshkov
2021-08-17  0:54 ` [RFC PATCH 05/15] Bluetooth: hci_qca: merge qca_power into qca_serdev Dmitry Baryshkov
2021-08-17  0:54 ` [RFC PATCH 06/15] Bluetooth: hci_qca: merge init paths Dmitry Baryshkov
2021-08-17  0:54 ` [RFC PATCH 07/15] Bluetooth: hci_qca: merge qca_power_on with qca_regulators_init Dmitry Baryshkov
2021-08-17  0:55 ` [RFC PATCH 08/15] Bluetooth: hci_qca: futher rework of power on/off handling Dmitry Baryshkov
2021-08-17  0:55 ` [RFC PATCH 09/15] Bluetooth: hci_qca: add support for pwrseq Dmitry Baryshkov
2021-08-17  0:55 ` [RFC PATCH 10/15] pwrseq: add support for QCA BT+WiFi power sequencer Dmitry Baryshkov
2021-08-19 23:18   ` Bjorn Andersson
2021-08-20  8:10     ` Dmitry Baryshkov
2021-08-20 16:35       ` Bjorn Andersson
2021-08-17  0:55 ` [RFC PATCH 11/15] arm64: dts: qcom: sdm845-db845c: switch bt+wifi to qca " Dmitry Baryshkov
2021-08-19 23:40   ` Bjorn Andersson
2021-08-17  0:55 ` [RFC PATCH 12/15] arm64: dts: qcom: qrb5165-rb5: add bluetooth support Dmitry Baryshkov
2021-08-17  0:55 ` [RFC PATCH 13/15] arm64: dts: qcom: sdm845-db845c: add second channel support to qca power sequencer Dmitry Baryshkov
2021-08-17  0:55 ` [RFC PATCH 14/15] WIP: PCI: qcom: use pwrseq to power up bus devices Dmitry Baryshkov
2021-08-19 23:44   ` Bjorn Andersson
2021-08-20  8:50     ` Dmitry Baryshkov
2021-08-17  0:55 ` [RFC PATCH 15/15] WIP: arm64: dts: qcom: qrb5165-rb5: add bus-pwrseq property to pcie0 Dmitry Baryshkov
2021-08-19 15:23 ` [RFC PATCH 00/15] create power sequencing subsystem Marcel Holtmann
2021-08-20 13:08   ` Dmitry Baryshkov
2021-08-20 17:02     ` Bjorn Andersson
2021-08-20 18:06       ` Dmitry Baryshkov
2021-08-21  6:50     ` Marcel Holtmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YR7rR6d4nSRea1oX@ripper \
    --to=bjorn.andersson@linaro.org \
    --cc=agross@kernel.org \
    --cc=ath10k@lists.infradead.org \
    --cc=davem@davemloft.net \
    --cc=dmitry.baryshkov@linaro.org \
    --cc=johan.hedberg@gmail.com \
    --cc=kuba@kernel.org \
    --cc=kvalo@codeaurora.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=luiz.dentz@gmail.com \
    --cc=marcel@holtmann.org \
    --cc=netdev@vger.kernel.org \
    --cc=svarbanov@mm-sol.com \
    --cc=ulf.hansson@linaro.org \
    --subject='Re: [RFC PATCH 01/15] power: add power sequencer subsystem' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).