mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: David Lechner <david@lechnology.com>
To: Bartosz Golaszewski <brgl@bgdev.pl>,
	Philipp Zabel <p.zabel@pengutronix.de>
Cc: linux-kernel@vger.kernel.org,
	Bartosz Golaszewski <bgolaszewski@baylibre.com>,
	Sekhar Nori <nsekhar@ti.com>, Kevin Hilman <khilman@baylibre.com>
Subject: Re: [PATCH] reset: add support for non-DT systems
Date: Tue, 13 Feb 2018 11:17:56 -0600	[thread overview]
Message-ID: <be0e422c-465f-954e-254f-21a5b5766bed@lechnology.com> (raw)
In-Reply-To: <20180213152524.16620-1-brgl@bgdev.pl>

On 02/13/2018 09:25 AM, Bartosz Golaszewski wrote:
> From: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> 
> The reset framework only supports device-tree. There are some platforms
> however, which need to use it even in legacy, board-file based mode.
> 
> An example of such architecture is the DaVinci family of SoCs which
> supports both device tree and legacy boot modes and we don't want to
> introduce any regressions.
> 
> We're currently working on converting the platform from its hand-crafted
> clock API to using the common clock framework. Part of the overhaul will
> be representing the chip's power sleep controller's reset lines using
> the reset framework.
> 
> This changeset extends the core reset code with a new field in the
> reset controller struct which contains an array of lookup entries. Each
> entry contains the device name and an additional, optional identifier
> string.
> 
> Drivers can register a set of reset lines using this lookup table and
> concerned devices can access them using the regular reset_control API.
> 
> This new function is only called as a fallback in case the of_node
> field is NULL and doesn't change anything for current users.
> 
> Tested with a dummy reset driver with several lookup entries.
> 
> An example lookup table can look like this:
> 
> static const struct reset_lookup foobar_reset_lookup[] = {
> 	[FOO_RESET] = { .dev = "foo", .id = "foo_id" },
> 	[BAR_RESET] = { .dev = "bar", .id = NULL },
> 	{ }
> };
> 
> where FOO_RESET and BAR_RESET will correspond with the id parameters
> of reset callbacks.
> 
> Cc: Sekhar Nori <nsekhar@ti.com>
> Cc: Kevin Hilman <khilman@baylibre.com>
> Cc: David Lechner <david@lechnology.com>
> Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com>
> ---

Looks good to me. I just made a few very minor comments. I will
try to use this in PSC driver later today.


>   drivers/reset/core.c             | 43 ++++++++++++++++++++++++++++++++++++++--
>   include/linux/reset-controller.h | 13 ++++++++++++
>   2 files changed, 54 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/reset/core.c b/drivers/reset/core.c
> index da4292e9de97..ba7011c6e06f 100644
> --- a/drivers/reset/core.c
> +++ b/drivers/reset/core.c
> @@ -493,12 +493,51 @@ struct reset_control *__of_reset_control_get(struct device_node *node,
>   }
>   EXPORT_SYMBOL_GPL(__of_reset_control_get);
>   
> +static struct reset_control *
> +__reset_control_get_lookup(struct device *dev, const char *id,

Based on the name of the function, I expected this to return
struct reset_lookup. Perhaps __reset_control_lookup() or
__reset_control_match_lookup() would be a slightly better name?

> +			   bool shared, bool optional)
> +{
> +	struct reset_controller_dev *rcdev;
> +	const char *dev_id = dev_name(dev);
> +	struct reset_control *rstc = NULL;
> +	const struct reset_lookup *lookup;
> +	int index;
> +
> +	mutex_lock(&reset_list_mutex);
> +
> +	list_for_each_entry(rcdev, &reset_controller_list, list) {
> +		if (!rcdev->lookup)
> +			continue;
> +
> +		lookup = rcdev->lookup;
> +		for (index = 0; lookup->dev; index++, lookup++) {
> +			if (strcmp(dev_id, lookup->dev))
> +				continue;
> +
> +			if ((!id && !lookup->id) ||
> +			    (id && lookup->id && !strcmp(id, lookup->id))) {
> +				rstc = __reset_control_get_internal(rcdev,
> +								index, shared);
> +			}
> +		}
> +	}
> +
> +	mutex_unlock(&reset_list_mutex);
> +
> +	if (!rstc)
> +		return optional ? NULL : ERR_PTR(-ENOENT);
> +
> +	return rstc;
> +}
> +
>   struct reset_control *__reset_control_get(struct device *dev, const char *id,
>   					  int index, bool shared, bool optional)
>   {
>   	if (dev->of_node)
> -		return __of_reset_control_get(dev->of_node, id, index, shared,
> -					      optional);
> +		return __of_reset_control_get(dev->of_node, id,
> +					      index, shared, optional);

I don't understand why this line is changed. It is just being rearranged?

> +	else
> +		return __reset_control_get_lookup(dev, id, shared, optional);
>   
>   	return optional ? NULL : ERR_PTR(-EINVAL);
>   }
> diff --git a/include/linux/reset-controller.h b/include/linux/reset-controller.h
> index adb88f8cefbc..0c081336e08b 100644
> --- a/include/linux/reset-controller.h
> +++ b/include/linux/reset-controller.h
> @@ -22,6 +22,17 @@ struct reset_control_ops {
>   	int (*status)(struct reset_controller_dev *rcdev, unsigned long id);
>   };
>   
> +/**
> + * struct reset_lookup - a single entry in a reset lookup table
> + *
> + * @dev: name of the device associated with this reset
> + * @id: additional reset identifier (if the device uses multiple reset lines)
> + */
> +struct reset_lookup {
> +	const char *dev;
> +	const char *id;
> +};
> +
>   struct module;
>   struct device_node;
>   struct of_phandle_args;
> @@ -34,6 +45,7 @@ struct of_phandle_args;
>    * @list: internal list of reset controller devices
>    * @reset_control_head: head of internal list of requested reset controls
>    * @of_node: corresponding device tree node as phandle target
> + * @lookup: array of lookup entries associated with this request controller

Might be nice to mention that this array must end with an empty struct (i.e.
lookup->dev == NULL)

>    * @of_reset_n_cells: number of cells in reset line specifiers
>    * @of_xlate: translation function to translate from specifier as found in the
>    *            device tree to id as given to the reset control ops
> @@ -45,6 +57,7 @@ struct reset_controller_dev {
>   	struct list_head list;
>   	struct list_head reset_control_head;
>   	struct device_node *of_node;
> +	const struct reset_lookup *lookup;
>   	int of_reset_n_cells;
>   	int (*of_xlate)(struct reset_controller_dev *rcdev,
>   			const struct of_phandle_args *reset_spec);
> 

  reply	other threads:[~2018-02-13 17:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-13 15:25 Bartosz Golaszewski
2018-02-13 17:17 ` David Lechner [this message]
2018-02-13 17:43   ` Bartosz Golaszewski

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=be0e422c-465f-954e-254f-21a5b5766bed@lechnology.com \
    --to=david@lechnology.com \
    --cc=bgolaszewski@baylibre.com \
    --cc=brgl@bgdev.pl \
    --cc=khilman@baylibre.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nsekhar@ti.com \
    --cc=p.zabel@pengutronix.de \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®