All of lore.kernel.org
 help / color / mirror / Atom feed
From: Claudiu.Beznea at microchip.com <Claudiu.Beznea@microchip.com>
To: u-boot@lists.denx.de
Subject: [PATCH 03/22] dm: core: add support for device re-parenting
Date: Tue, 4 Aug 2020 07:24:42 +0000	[thread overview]
Message-ID: <1fadabeb-b2e9-88c4-1752-6db2f7f4fce2@microchip.com> (raw)
In-Reply-To: <CAPnjgZ03RB7B97_sL97OFZxaBpC8qf9jEQ52iYYM4LxJrz-shQ@mail.gmail.com>



On 04.08.2020 05:00, Simon Glass wrote:
> EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
> 
> Hi Claudiu,
> 
> On Wed, 29 Jul 2020 at 08:51, Claudiu Beznea
> <claudiu.beznea@microchip.com> wrote:
>>
>> In common clock framework the relation b/w parent and child clocks is
>> determined based on the udevice parent/child information. A clock
>> parent could be changed based on devices needs. In case this is happen
>> the functionalities for clock who's parent is changed are broken. Add
>> a function that reparent a device. This will be used in clk-uclass.c
>> to reparent a clock device.
>>
>> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com>
>> ---
>>  drivers/core/device.c        | 26 ++++++++++++++++++++++++++
>>  include/dm/device-internal.h |  9 +++++++++
>>  2 files changed, 35 insertions(+)
> 
> Please add a sandbox test for this function.

OK.

> 
>>
>> diff --git a/drivers/core/device.c b/drivers/core/device.c
>> index a7408d9c76c6..f149d55ac1e1 100644
>> --- a/drivers/core/device.c
>> +++ b/drivers/core/device.c
>> @@ -267,6 +267,32 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
>>                         devp);
>>  }
>>
>> +int device_reparent(struct udevice *dev, struct udevice *new_parent)
>> +{
>> +       struct udevice *cparent;
>> +       struct udevice *pos, *n;
>> +
>> +       if (!dev || !new_parent)
>> +               return -EINVAL;
>> +
> 
> This is an error by the caller and would not be present in production
> code. Perhaps use assert()?

OK, I'll use assert().

> 
>> +       if (!dev->parent)
>> +               return -ENODEV;
> 
> This can't happen. Every device except for the root one has a parent.

Sure, I'll remove it.

> 
>> +
>> +       list_for_each_entry_safe(pos, n, &dev->parent->child_head,
>> +                                sibling_node) {
>> +               if (pos->driver != dev->driver)
>> +                       continue;
>> +
>> +               list_del(&dev->sibling_node);
>> +               list_add_tail(&dev->sibling_node, &new_parent->child_head);
>> +               dev->parent = new_parent;
>> +
>> +               return 0;
>> +       }
>> +
>> +       return -ENODEV;
> 
> What does this error mean?

That the device who needs re-parenting has no parent. But you already
pointed that this should not happen. This means that the above loop will
always have a match and here we should return success code.

> 
>> +}
>> +
>>  static void *alloc_priv(int size, uint flags)
>>  {
>>         void *priv;
>> diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h
>> index 294d6c18105a..c5d7ec0650f9 100644
>> --- a/include/dm/device-internal.h
>> +++ b/include/dm/device-internal.h
>> @@ -84,6 +84,15 @@ int device_bind_by_name(struct udevice *parent, bool pre_reloc_only,
>>                         const struct driver_info *info, struct udevice **devp);
>>
>>  /**
>> + * device_reparent: reparent the device to a new parent
>> + *
>> + * @dev: pointer to device to be reparented
>> + * @new_parent: pointer to new parent device
>> + * @return 0 if OK, -ve on error
>> + */
>> +int device_reparent(struct udevice *dev, struct udevice *new_parent);
>> +
>> +/**
>>   * device_ofdata_to_platdata() - Read platform data for a device
>>   *
>>   * Read platform data for a device (typically from the device tree) so that
>> --
>> 2.7.4
>>
> 
> Regards,
> Simon
> 

  reply	other threads:[~2020-08-04  7:24 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-07-29 14:51 [PATCH 00/22] clk: at91: add sama7g5 support Claudiu Beznea
2020-07-29 14:51 ` [PATCH 01/22] clk: check hw and hw->dev before dereference it Claudiu Beznea
2020-08-04  2:00   ` Simon Glass
2020-08-04  7:19     ` Claudiu.Beznea at microchip.com
2020-08-04 15:08       ` Simon Glass
2020-08-04 15:25         ` Claudiu.Beznea at microchip.com
2020-08-04 15:29           ` Simon Glass
2020-08-04 15:55             ` Claudiu.Beznea at microchip.com
2020-07-29 14:51 ` [PATCH 02/22] clk: check pointer returned by dev_get_parent() Claudiu Beznea
2020-08-04  2:00   ` Simon Glass
2020-08-04  7:19     ` Claudiu.Beznea at microchip.com
2020-07-29 14:51 ` [PATCH 03/22] dm: core: add support for device re-parenting Claudiu Beznea
2020-08-04  2:00   ` Simon Glass
2020-08-04  7:24     ` Claudiu.Beznea at microchip.com [this message]
2020-07-29 14:51 ` [PATCH 04/22] clk: bind clk to new parent device Claudiu Beznea
2020-08-04  2:00   ` Simon Glass
2020-08-04  7:24     ` Claudiu.Beznea at microchip.com
2020-07-29 14:51 ` [PATCH 05/22] clk: do not disable clock if it is critical Claudiu Beznea
2020-08-04  2:00   ` Simon Glass
2020-07-29 14:51 ` [PATCH 06/22] clk: get clock pointer before proceeding Claudiu Beznea
2020-08-04  2:00   ` Simon Glass
2020-08-04  7:26     ` Claudiu.Beznea at microchip.com
2020-07-29 14:51 ` [PATCH 07/22] clk: at91: add pre-requisite headers for AT91 clock architecture Claudiu Beznea
2020-07-29 14:51 ` [PATCH 08/22] clk: at91: pmc: add helpers for clock drivers Claudiu Beznea
2020-07-29 14:51 ` [PATCH 09/22] clk: at91: move clock code to compat.c Claudiu Beznea
2020-07-29 14:51 ` [PATCH 10/22] clk: at91: sckc: add driver compatible with ccf Claudiu Beznea
2020-07-29 14:51 ` [PATCH 11/22] clk: at91: clk-main: " Claudiu Beznea
2020-07-29 14:51 ` [PATCH 12/22] clk: at91: sam9x60-pll: " Claudiu Beznea
2020-07-29 14:51 ` [PATCH 13/22] clk: at91: clk-master: " Claudiu Beznea
2020-07-29 14:51 ` [PATCH 14/22] clk: at91: clk-master: add support for sama7g5 Claudiu Beznea
2020-07-29 14:51 ` [PATCH 15/22] clk: at91: clk-utmi: add driver compatible with ccf Claudiu Beznea
2020-07-29 14:51 ` [PATCH 16/22] clk: at91: clk-utmi: add support for sama7g5 Claudiu Beznea
2020-07-29 14:51 ` [PATCH 17/22] clk: at91: clk-programmable: add driver compatible with ccf Claudiu Beznea
2020-07-29 14:51 ` [PATCH 18/22] clk: at91: clk-system: " Claudiu Beznea
2020-07-29 14:51 ` [PATCH 19/22] clk: at91: clk-peripheral: " Claudiu Beznea
2020-07-29 14:51 ` [PATCH 20/22] clk: at91: clk-generic: " Claudiu Beznea
2020-07-29 14:51 ` [PATCH 21/22] clk: at91: pmc: add generic clock ops Claudiu Beznea
2020-07-29 14:51 ` [PATCH 22/22] clk: at91: sama7g5: add clock support Claudiu Beznea

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=1fadabeb-b2e9-88c4-1752-6db2f7f4fce2@microchip.com \
    --to=claudiu.beznea@microchip.com \
    --cc=u-boot@lists.denx.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.