All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Simek <michal.simek@xilinx.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/4] fdt: Introduce fdtdec_get_alias_highest_id()
Date: Thu, 31 Jan 2019 11:14:15 +0100	[thread overview]
Message-ID: <ce01bbe9-7546-ff6b-eefc-26c35288333c@xilinx.com> (raw)
In-Reply-To: <CAPnjgZ0+_MdJeM+cTcEgnLV9W8g_JEfryFogHAaZTY8_5Xa-zw@mail.gmail.com>

On 31. 01. 19 11:04, Simon Glass wrote:
> Hi Michal,
> 
> On Fri, 18 Jan 2019 at 08:13, Michal Simek <michal.simek@xilinx.com> wrote:
>>
>> Find out the highest alias ID used for certain subsystem.
>> This call will be used for alocating IDs for i2c buses which are not
>> described in DT.
>>
>> Signed-off-by: Michal Simek <michal.simek@xilinx.com>
>> ---
>>
>>  include/fdtdec.h | 13 +++++++++++++
>>  lib/fdtdec.c     | 33 +++++++++++++++++++++++++++++++++
>>  2 files changed, 46 insertions(+)
>>
>> diff --git a/include/fdtdec.h b/include/fdtdec.h
>> index f1bcbf837ffb..c2dd87ede226 100644
>> --- a/include/fdtdec.h
>> +++ b/include/fdtdec.h
>> @@ -626,6 +626,19 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int node,
>>                          int *seqp);
>>
>>  /**
>> + * Get the highest alias number for susbystem.
>> + *
>> + * It parses all aliases and find out highest recorded alias for subsystem.
>> + * Aliases are of the form <base><num> where <num> is the sequence number.
>> + *
>> + * @param blob         Device tree blob (if NULL, then error is returned)
>> + * @param base         Base name for alias susbystem (before the number)
>> + *
>> + * @return 0 highest alias ID, -1 if not found
>> + */
>> +int fdtdec_get_alias_highest_id(const void *blob, const char *base);
>> +
>> +/**
>>   * Get a property from the /chosen node
>>   *
>>   * @param blob         Device tree blob (if NULL, then NULL is returned)
>> diff --git a/lib/fdtdec.c b/lib/fdtdec.c
>> index 18663ce6bdac..55811975ef54 100644
>> --- a/lib/fdtdec.c
>> +++ b/lib/fdtdec.c
>> @@ -549,6 +549,39 @@ int fdtdec_get_alias_seq(const void *blob, const char *base, int offset,
>>         return -ENOENT;
>>  }
>>
>> +int fdtdec_get_alias_highest_id(const void *blob, const char *base)
>> +{
>> +       int base_len = strlen(base);
>> +       int prop_offset;
>> +       int aliases;
>> +       int max = -1;
>> +
>> +       debug("Looking for highest alias id for '%s'\n", base);
>> +
>> +       aliases = fdt_path_offset(blob, "/aliases");
>> +       for (prop_offset = fdt_first_property_offset(blob, aliases);
>> +            prop_offset > 0;
>> +            prop_offset = fdt_next_property_offset(blob, prop_offset)) {
>> +               const char *prop;
>> +               const char *name;
>> +               int len, val;
>> +
>> +               prop = fdt_getprop_by_offset(blob, prop_offset, &name, &len);
>> +               debug("   - %s, %s\n", name, prop);
>> +               if (*prop != '/' || prop[len - 1] ||
>> +                   strncmp(name, base, base_len))
>> +                       continue;
>> +
>> +               val = trailing_strtol(name);
>> +               if (val > max) {
>> +                       debug("Found seq %d\n", val);
>> +                       max = val;
>> +               }
>> +       }
>> +
>> +       return max;
> 
> This looks right to me. Can you please add a test that calls this for
> a few sandbox aliases?

let's see how this can be done.

M

  reply	other threads:[~2019-01-31 10:14 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-18 15:13 [U-Boot] [PATCH 0/4] Align U-Boot I2C DM bus ID handling with Linux Michal Simek
2019-01-18 15:13 ` [U-Boot] [PATCH 1/4] dm: core: Add of_alias_get_highest_id() Michal Simek
2019-01-28 12:35   ` Michal Simek
2019-01-31 10:04   ` Simon Glass
2019-01-31 10:19     ` Michal Simek
2019-02-02  6:05       ` Simon Glass
2019-01-18 15:13 ` [U-Boot] [PATCH 2/4] fdt: Introduce fdtdec_get_alias_highest_id() Michal Simek
2019-01-31 10:04   ` Simon Glass
2019-01-31 10:14     ` Michal Simek [this message]
2019-01-18 15:13 ` [U-Boot] [PATCH 3/4] i2c: dm: Record maximum id of devices before probing devices Michal Simek
2019-01-31 10:04   ` Simon Glass
2019-01-31 11:03     ` Michal Simek
2019-02-02  6:05       ` Simon Glass
2019-02-02  6:22         ` Michal Simek
2019-01-18 15:13 ` [U-Boot] [PATCH 4/4] i2c: mux: Add support for not listed sub-buses Michal Simek
2019-01-24  8:27   ` Michal Simek
2019-01-31 10:04   ` Simon Glass
2019-01-31 15:05     ` Michal Simek
2019-01-18 15:24 ` [U-Boot] [PATCH 0/4] Align U-Boot I2C DM bus ID handling with Linux Michal Simek

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=ce01bbe9-7546-ff6b-eefc-26c35288333c@xilinx.com \
    --to=michal.simek@xilinx.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.