linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Frank Rowand <frowand.list@gmail.com>
To: Jaewon Kim <jaewon02.kim@gmail.com>,
	Rob Herring <robh+dt@kernel.org>,
	Jaewon Kim <jaewon02.kim@samsung.com>
Cc: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] of/platform: Support dynamic device tree on AMBA bus
Date: Tue, 30 Oct 2018 16:04:52 -0700	[thread overview]
Message-ID: <25f61a9b-af37-18b1-9975-cb4ccbbb3aa7@gmail.com> (raw)
In-Reply-To: <1540485597-12240-1-git-send-email-jaewon02.kim@samsung.com>

Hi Jaewon,

On 10/25/18 9:39 AM, Jaewon Kim wrote:
> This patch supports dynamic device-tree for AMBA device.

Add AMBA devices and buses to of_platform_notify() so that dynamic device-tree
will support AMBA.

> The AMBA device must be registered on the AMBA bus, not the platform bus.
> 
> Signed-off-by: Jaewon Kim <jaewon02.kim@samsung.com>
> ---
>  drivers/of/platform.c | 93 ++++++++++++++++++++++++++++++++++++++++-----------
>  1 file changed, 73 insertions(+), 20 deletions(-)
> 
> diff --git a/drivers/of/platform.c b/drivers/of/platform.c
> index 04ad312..b9ac105 100644
> --- a/drivers/of/platform.c
> +++ b/drivers/of/platform.c
> @@ -286,6 +286,22 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
>  	of_node_clear_flag(node, OF_POPULATED);
>  	return NULL;
>  }
> +
> +/**
> + * of_find_amba_device_by_node - Find the amba_device associated with a node
> + * @np: Pointer to device tree node
> + *
> + * Returns amba_device pointer, or NULL if not found
> + */
> +struct amba_device *of_find_amba_device_by_node(struct device_node *np)
> +{
> +	struct device *dev;
> +
> +	dev = bus_find_device(&amba_bustype, NULL, np, of_dev_node_match);
> +	return dev ? to_amba_device(dev) : NULL;
> +}
> +EXPORT_SYMBOL(of_find_amba_device_by_node);
> +
>  #else /* CONFIG_ARM_AMBA */
>  static struct amba_device *of_amba_device_create(struct device_node *node,
>  						 const char *bus_id,
> @@ -294,6 +310,12 @@ static struct amba_device *of_amba_device_create(struct device_node *node,
>  {
>  	return NULL;
>  }
> +
> +struct amba_device *of_find_amba_device_by_node(struct device_node *np)
> +{
> +	return NULL;
> +}
> +EXPORT_SYMBOL(of_find_amba_device_by_node);
>  #endif /* CONFIG_ARM_AMBA */
>  
>  /**
> @@ -665,6 +687,7 @@ static int of_platform_notify(struct notifier_block *nb,
>  {
>  	struct of_reconfig_data *rd = arg;
>  	struct platform_device *pdev_parent, *pdev;
> +	struct amba_device *adev_p, *adev;
>  	bool children_left;
>  
>  	switch (of_reconfig_get_state_change(action, rd)) {
> @@ -677,17 +700,34 @@ static int of_platform_notify(struct notifier_block *nb,
>  		if (of_node_check_flag(rd->dn, OF_POPULATED))
>  			return NOTIFY_OK;
>  
> -		/* pdev_parent may be NULL when no bus platform device */
> -		pdev_parent = of_find_device_by_node(rd->dn->parent);
> -		pdev = of_platform_device_create(rd->dn, NULL,
> -				pdev_parent ? &pdev_parent->dev : NULL);
> -		of_dev_put(pdev_parent);
> -
> -		if (pdev == NULL) {
> -			pr_err("%s: failed to create for '%pOF'\n",
> -					__func__, rd->dn);
> -			/* of_platform_device_create tosses the error code */
> -			return notifier_from_errno(-EINVAL);
> +		if (of_device_is_compatible(rd->dn, "arm,primecell")) {
> +			/* adev_p may be NULL when no bus amba device */
> +			adev_p = of_find_amba_device_by_node(rd->dn->parent);
> +			adev = of_amba_device_create(rd->dn, NULL, NULL,
> +					adev_p ? &adev_p->dev : NULL);
> +

> +			if (adev_p)
> +				put_device(&adev_p->dev);

Please follow the same model as of_dev_put() here, create a new function
of_amba_dev_put() to implement these two lines.


> +
> +			if (adev == NULL) {
> +				pr_err("%s: failed to create for '%s'\n",
> +						__func__, rd->dn->full_name);
> +				/* of_amba_device_create tosses the error */
> +				return notifier_from_errno(-EINVAL);
> +			}
> +		} else {
> +			/* pdev_parent may be NULL when no bus platform device*/
> +			pdev_parent = of_find_device_by_node(rd->dn->parent);
> +			pdev = of_platform_device_create(rd->dn, NULL,
> +					pdev_parent ? &pdev_parent->dev : NULL);
> +			of_dev_put(pdev_parent);
> +
> +			if (pdev == NULL) {
> +				pr_err("%s: failed to create for '%pOF'\n",
> +						__func__, rd->dn);
> +				/* of_platform_device_create tosses the error */
> +				return notifier_from_errno(-EINVAL);
> +			}
>  		}
>  		break;
>  
> @@ -698,15 +738,28 @@ static int of_platform_notify(struct notifier_block *nb,
>  			return NOTIFY_OK;
>  
>  		/* find our device by node */
> -		pdev = of_find_device_by_node(rd->dn);
> -		if (pdev == NULL)
> -			return NOTIFY_OK;	/* no? not meant for us */
> -
> -		/* unregister takes one ref away */
> -		of_platform_device_destroy(&pdev->dev, &children_left);
> -
> -		/* and put the reference of the find */
> -		of_dev_put(pdev);
> +		if (of_device_is_compatible(rd->dn, "arm,primecell")) {
> +			adev = of_find_amba_device_by_node(rd->dn);
> +			if (adev == NULL)
> +				return NOTIFY_OK; /* no? not meant for us */
> +
> +			/* unregister takes one ref away */
> +			of_platform_device_destroy(&adev->dev, &children_left);
> +
> +			/* and put the reference of the find */

> +			if (adev)
> +				put_device(&adev->dev);

of_amba_dev_put() here also

-Frank


> +		} else {
> +			pdev = of_find_device_by_node(rd->dn);
> +			if (pdev == NULL)
> +				return NOTIFY_OK; /* no? not meant for us */
> +
> +			/* unregister takes one ref away */
> +			of_platform_device_destroy(&pdev->dev, &children_left);
> +
> +			/* and put the reference of the find */
> +			of_dev_put(pdev);
> +		}
>  		break;
>  	}
>  
> 


  reply	other threads:[~2018-10-30 23:04 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-25 16:39 [PATCH] of/platform: Support dynamic device tree on AMBA bus Jaewon Kim
2018-10-30 23:04 ` Frank Rowand [this message]
2018-10-31 15:32   ` Jaewon Kim
2018-10-31 16:06     ` Frank Rowand
2018-11-01 15:36       ` Jaewon Kim
2018-10-31 18:31 ` Rob Herring
     [not found]   ` <1f7b35fd-7900-0c48-50a2-4f84481a208c@gmail.com>
2018-11-06 13:11     ` Rob Herring

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=25f61a9b-af37-18b1-9975-cb4ccbbb3aa7@gmail.com \
    --to=frowand.list@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jaewon02.kim@gmail.com \
    --cc=jaewon02.kim@samsung.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).