From patchwork Thu Jan 31 15:30:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1034326 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="RBPQqw9h"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43r47Z1PxMz9s9G for ; Fri, 1 Feb 2019 02:35:38 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id C0F17C21EB1; Thu, 31 Jan 2019 15:32:28 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id C4036C21FAA; Thu, 31 Jan 2019 15:31:40 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 210D2C21F9E; Thu, 31 Jan 2019 15:31:18 +0000 (UTC) Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by lists.denx.de (Postfix) with ESMTPS id 35F74C21F38 for ; Thu, 31 Jan 2019 15:31:15 +0000 (UTC) Received: by mail-wr1-f66.google.com with SMTP id f7so3829897wrp.1 for ; Thu, 31 Jan 2019 07:31:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=be50Anu1SfY1xK4ug6YgUl9klqVTV5VKa5Rfq3Vjh7w=; b=RBPQqw9hPzp8IJFt2rlCMjqfyTVzu6uf7zoh8n7syVzb9fu8aIqA4ZNaNgEfEqmfMu CvqdAa9g6gmEgdAKJL3D0BuJe34eVBu/9dtCZ8LudS4oBP9euHMwfewoZw9AfrhTawnv texdPlLWM1832SAi8bVkFBkbB9VetVBEp8UIlAsIvu4J5VNDGMBN6QwaRLdzYkcVWSVI w9C2d5fpAayaZuFE698f0+5tJaVQz+LmQ5TG3V11Zzd2KkqF9ZwNPyt5MoKyi84tsfLz cq8pVtDIUBC25DfHPDdWcd1Zm4sdjRUXP7BAa2jY4C3wPnZw9ZJyhBGQQUOLUKjtHnIy 2yLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:in-reply-to:references; bh=be50Anu1SfY1xK4ug6YgUl9klqVTV5VKa5Rfq3Vjh7w=; b=QRmJWGrGpMNR+2w4wl3rRfzcinlrQZtyjIBylGjm8yFzOGLfU8BOPcRsnFXq5dvkDz huh4AfPp0d1/dPsfx6IGHSjeJZ+VQ5Nhza+R/KZkulbSXa58cE38cSE9pKc7A02KSyME 7JcODPOy1Nkz4NSc98pLPJ5mH394xTX36XYCDYhKB4XDSIxgZewCyZNoXVQz7KnKbnuO TrzZJowd5bpvqw0LKcvBwIE5i1wAs8+7yk+ORktlzZcmgFsenIX6T6Dwf0PQmIdI2d1/ 7eUjW1ZX//jpMWB/ZyM5E/mr/xUhEGnO+0bWrSN4HieCtLb6HH3N+pK1PfIF5IgX75CY tZpg== X-Gm-Message-State: AJcUukfIj1ftDT5+G4zQeSOpbC5nB2EWpnbdTjqQ0028M3tcfbrvedz2 acXPIZngLiS7xSpMnb7pHtA7BmJ5YRBrSg== X-Google-Smtp-Source: ALg8bN4SkYWZ9ZvdHasEjc4a/MYxlV2GTFrhAHFQFMgnwku/uJaYSPzhYKOG9LUC84PK5KmF5zJd8w== X-Received: by 2002:adf:9323:: with SMTP id 32mr34204074wro.213.1548948671818; Thu, 31 Jan 2019 07:31:11 -0800 (PST) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id f10sm2646412wmb.35.2019.01.31.07.31.08 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 31 Jan 2019 07:31:08 -0800 (PST) From: Michal Simek To: u-boot@lists.denx.de, Simon Glass Date: Thu, 31 Jan 2019 16:30:57 +0100 Message-Id: <17aae762d4e43774b24d7884ee56bf5ba417f274.1548948659.git.michal.simek@xilinx.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: Subject: [U-Boot] [PATCH v2 1/7] dm: core: Add of_alias_get_highest_id() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" The same functionality was added to Linux for i2c bus registration with this commit message: " of: base: add function to get highest id of an alias stem I2C supports adding adapters using either a dynamic or fixed id. The latter is provided by aliases in the DT case. To prevent id collisions of those two types, install this function which gives us the highest fixed id, so we can then let the dynamically created ones come after this highest number. Signed-off-by: Wolfram Sang Acked-by: Rob Herring Signed-off-by: Wolfram Sang " Add it also to U-Boot for DM I2C support. Signed-off-by: Michal Simek Reviewed-by: Heiko Schocher Reviewed-by: Simon Glass --- Changes in v2: - Update kernel-doc binding - Return -1 in case of error. -1 means that the next free alias is 0. drivers/core/of_access.c | 18 ++++++++++++++++++ include/dm/of_access.h | 10 ++++++++++ 2 files changed, 28 insertions(+) diff --git a/drivers/core/of_access.c b/drivers/core/of_access.c index 14c020a687b7..945b81448cce 100644 --- a/drivers/core/of_access.c +++ b/drivers/core/of_access.c @@ -812,6 +812,24 @@ int of_alias_get_id(const struct device_node *np, const char *stem) return id; } +int of_alias_get_highest_id(const char *stem) +{ + struct alias_prop *app; + int id = -1; + + mutex_lock(&of_mutex); + list_for_each_entry(app, &aliases_lookup, link) { + if (strcmp(app->stem, stem) != 0) + continue; + + if (app->id > id) + id = app->id; + } + mutex_unlock(&of_mutex); + + return id; +} + struct device_node *of_get_stdout(void) { return of_stdout; diff --git a/include/dm/of_access.h b/include/dm/of_access.h index 5ed1a0cdb427..13fedb7cf5e6 100644 --- a/include/dm/of_access.h +++ b/include/dm/of_access.h @@ -425,6 +425,16 @@ int of_alias_scan(void); int of_alias_get_id(const struct device_node *np, const char *stem); /** + * of_alias_get_highest_id - Get highest alias id for the given stem + * @stem: Alias stem to be examined + * + * The function travels the lookup table to get the highest alias id for the + * given alias stem. + * @return alias ID, if found, else -1 + */ +int of_alias_get_highest_id(const char *stem); + +/** * of_get_stdout() - Get node to use for stdout * * @return node referred to by stdout-path alias, or NULL if none From patchwork Thu Jan 31 15:30:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1034319 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="vIEXDzEy"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43r43D44vWz9s9G for ; Fri, 1 Feb 2019 02:31:52 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 4CE97C21F80; Thu, 31 Jan 2019 15:31:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 3866AC21FAB; Thu, 31 Jan 2019 15:31:30 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3E25CC21FBC; Thu, 31 Jan 2019 15:31:19 +0000 (UTC) Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) by lists.denx.de (Postfix) with ESMTPS id 775CDC21FB3 for ; Thu, 31 Jan 2019 15:31:16 +0000 (UTC) Received: by mail-wr1-f46.google.com with SMTP id p4so3755742wrt.7 for ; Thu, 31 Jan 2019 07:31:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=poWk7FScwTqw+KajKlbzTvYBPL0D30DNBKo6msZqGK8=; b=vIEXDzEy93UhrxfA00ELoF7HYxhywr50v+eOr3yTFsRfJb01//EFHRC2EJPRgnETZh 6tEFYh67GHmhYXT7/jqcdSbyhFotjIxA/FpbLM4oHv1dzWRoFaKmlsL6GNpwlt/M2VjS isqE6PjqqQeqvIP7sa12EFqf8sWUGIdjFW7c9/N1gVxLRIyAJC/jlp0Rr/UHrKgzeR9L 5R6VLz5AiL86pXI46fRIjFBwZxD765wGSrOPSFV/TpEQKuiUyhIjB/LU/AgBjnVPtvpR KxsoP/bcgcW2OX74kOQfL+icKdHTZHZlbwmwEXItrl3X7hfQuR2UcKOgNJKc1oCN702g VmOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:in-reply-to:references; bh=poWk7FScwTqw+KajKlbzTvYBPL0D30DNBKo6msZqGK8=; b=r3TCgKPB3MwoAIf5qni90L7E9pgQynZQ1v2xuIdjHepRVYRg41zH1Ud61Eu7avEcWT F0ZG3a/Sou/oqC7Xcgjw1CgVztwXpLv3aY0/Yjk+7mCczZwhQZD2LKrrXwY5Z1i72cfR PZJSTeUNjN23HUSMCEn3GMrAK9aQSBeyl9OnhiGFDtCTqPH2yi9/WIOUHbgMXwCc263P A2728eaoF5iSLmHzQHtf1DPsnm2o/X8aH5iJCTvFThA50ZyuryTR3fwxV4iWLlgdS8n8 TGcDEaG9arXxS/g1usXfVGyMNjWw8OolggWu8ukPG6lIR/Sa1HlScb0ejMuUps0qA4r2 ljaQ== X-Gm-Message-State: AJcUukeMD2XXP/O8MnesYyj9aojJKbi5hJXK45K7OTaEmYgFNFyYbzXR gaOqdkqstWgdLjpS5LanItuC5P9FkrmsGQ== X-Google-Smtp-Source: ALg8bN5v9npin7InVoBcwvJR3v1yBeBxvqjCj0FR2IIMEXgJ4R1KiPfwVVEgirPqAwGppDx+j6GGrA== X-Received: by 2002:a5d:4303:: with SMTP id h3mr35455497wrq.273.1548948675826; Thu, 31 Jan 2019 07:31:15 -0800 (PST) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id a1sm5451709wrw.76.2019.01.31.07.31.14 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 31 Jan 2019 07:31:14 -0800 (PST) From: Michal Simek To: u-boot@lists.denx.de, Simon Glass Date: Thu, 31 Jan 2019 16:30:58 +0100 Message-Id: X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: Subject: [U-Boot] [PATCH v2 2/7] fdt: Introduce fdtdec_get_alias_highest_id() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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 Reviewed-by: Heiko Schocher Reviewed-by: Simon Glass --- Changes in v2: None 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 where 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; +} + const char *fdtdec_get_chosen_prop(const void *blob, const char *name) { int chosen_node; From patchwork Thu Jan 31 15:30:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1034324 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="p2UBbJLw"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43r45s0kRXz9sBQ for ; Fri, 1 Feb 2019 02:34:09 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id B8D1AC21FC6; Thu, 31 Jan 2019 15:32:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 4F696C21EE0; Thu, 31 Jan 2019 15:31:34 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id CC80FC21F0B; Thu, 31 Jan 2019 15:31:21 +0000 (UTC) Received: from mail-wm1-f66.google.com (mail-wm1-f66.google.com [209.85.128.66]) by lists.denx.de (Postfix) with ESMTPS id 24710C21FAB for ; Thu, 31 Jan 2019 15:31:18 +0000 (UTC) Received: by mail-wm1-f66.google.com with SMTP id n190so2962498wmd.0 for ; Thu, 31 Jan 2019 07:31:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=rOA9N66B7d8OuM13ldJSti/T2TKazrd0uH+AinPSxEo=; b=p2UBbJLwo59iAPwKFsf8Ob7bgnpUIsNgFp0RW4jGikdIjsiq92NdECc+NQ/FpK4p2q A6XwxacpfUGbvySGR/AWXkm2CG4CpLGftIb57XDkcMsWAYNF+boUk+YbOFCfgUf1GvQp Ltn2VXw+lqmPWOB+ExzckCCXVqTo1zbPaaHqBRjt35ctBUF2QmsheMQwFMVZWoxWaYsj C84vTsWY7STwF2cyWt/Cbe5+3C6RmzOL0g3Vscj9B3kYOVvMUFmL5kBTdRO4HZfkvWgy EZMs/BuAgmEuzuYsrk7gIgj20jhbzi9ysalqUuT5rNN/c9xB8q975MglX/E7NseWdM23 Rzxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:in-reply-to:references; bh=rOA9N66B7d8OuM13ldJSti/T2TKazrd0uH+AinPSxEo=; b=tJAHVfCSGQeJ0w4vZoKwwML/lfGVilDXoj2BVSoJNgZd/jwQYzJske97tyWGG+cXoB g0blz1pU5ujMGRZznYuirxLsgDIUAqC6TrPIC0wPnKsV61DEnoeD7Qop9Y9EQF5vy6dF frchiKoSfgKThZptuXOPyNQtcLGdRDYb/hLQ8iiYKcI6BC9cPw01GYDywT7YAt/8bYw4 ITM+O0r/pSA83eIuJKkoGwR1Bs+9AkR3xTFw9vpdTc/7083GDr6xtP2N017ogmDul6IR B3K8GqCMfqBMxgV2/bhxsAeOfkCS61ihN0PJwwOPHWys1E3jYf3biqZoFRUjmVl5AIUz 2pNg== X-Gm-Message-State: AJcUukeSarUYXhxuWANPtSxmDZayFRIApHmTK/gSdJK3bWTE7U0VEX/z n8l5/8A21glUB2fopQx3QuM9ORIBGt2I5g== X-Google-Smtp-Source: ALg8bN5JBC3+Kf2SayzL1TX+L8TZVDbdg9Tff+ETjF8s/w6Z9bKwAG4CrR3IuJf0MEnqB2QRYWuWpg== X-Received: by 2002:a1c:26c1:: with SMTP id m184mr28830200wmm.25.1548948677351; Thu, 31 Jan 2019 07:31:17 -0800 (PST) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id c65sm6599985wma.24.2019.01.31.07.31.16 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 31 Jan 2019 07:31:16 -0800 (PST) From: Michal Simek To: u-boot@lists.denx.de, Simon Glass Date: Thu, 31 Jan 2019 16:30:59 +0100 Message-Id: <1525da17d6e1c823b9f6af14ef6eada0aac3bdc5.1548948659.git.michal.simek@xilinx.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: Subject: [U-Boot] [PATCH v2 3/7] dm: core: Introduce dev_read_alias_highest_id() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" It is wrapper for calling of_alias_get_highest_id() when live tree is enabled and fdtdec_get_alias_highest_id() if not. Signed-off-by: Michal Simek Reviewed-by: Heiko Schocher Reviewed-by: Simon Glass --- Changes in v2: - New patch drivers/core/read.c | 8 ++++++++ include/dm/read.h | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/drivers/core/read.c b/drivers/core/read.c index 3c46b3674ed6..6bda077a34b9 100644 --- a/drivers/core/read.c +++ b/drivers/core/read.c @@ -264,3 +264,11 @@ u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr) { return ofnode_translate_address(dev_ofnode(dev), in_addr); } + +int dev_read_alias_highest_id(const char *stem) +{ + if (of_live_active()) + return of_alias_get_highest_id(stem); + + return fdtdec_get_alias_highest_id(gd->fdt_blob, stem); +} diff --git a/include/dm/read.h b/include/dm/read.h index 389e30e7fb44..60b727cbd821 100644 --- a/include/dm/read.h +++ b/include/dm/read.h @@ -510,6 +510,17 @@ int dev_read_resource_byname(struct udevice *dev, const char *name, * @return the translated address; OF_BAD_ADDR on error */ u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_addr); + +/** + * dev_read_alias_highest_id - Get highest alias id for the given stem + * @stem: Alias stem to be examined + * + * The function travels the lookup table to get the highest alias id for the + * given alias stem. + * @return alias ID, if found, else -1 + */ +int dev_read_alias_highest_id(const char *stem); + #else /* CONFIG_DM_DEV_READ_INLINE is enabled */ static inline int dev_read_u32(struct udevice *dev, @@ -740,6 +751,11 @@ static inline u64 dev_translate_address(struct udevice *dev, const fdt32_t *in_a return ofnode_translate_address(dev_ofnode(dev), in_addr); } +static inline int dev_read_alias_highest_id(const char *stem) +{ + return fdtdec_get_alias_highest_id(gd->fdt_blob, stem); +} + #endif /* CONFIG_DM_DEV_READ_INLINE */ /** From patchwork Thu Jan 31 15:31:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1034322 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="wSWGA9ry"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43r45g1b6Rz9s9G for ; Fri, 1 Feb 2019 02:33:59 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id E594FC21FAB; Thu, 31 Jan 2019 15:32:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 5E9A9C21F1D; Thu, 31 Jan 2019 15:31:41 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 5DD1FC21F62; Thu, 31 Jan 2019 15:31:23 +0000 (UTC) Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by lists.denx.de (Postfix) with ESMTPS id CB3B3C21F92 for ; Thu, 31 Jan 2019 15:31:19 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id t27so3769019wra.6 for ; Thu, 31 Jan 2019 07:31:19 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=FpQSNaPYCXSYEBnFQqrTBKK9INGNoG9PlUp9vwjb6Bo=; b=wSWGA9ryYSUpW/ic1dARajUaZBLyWFSS3qAyX79FRh4Wa53GOcEbjukOwI9O+Q1afZ TIg/SMDdyLLD9sQcNH1kAM9e0Hr/JMBI4+cuEJ8Q9yy3UrTFkZONONpq+fomBJbr9abv HKLxs/1SYrLTURiHd1AkNYlAH0j+qIqpt3Ykg0t8Crztgb48pDWWxuh1QjO2NFtlflEk YDCjb9ZVnHcsi0nNk6YPVz5ySg9x+9cggna58oqViUDEDcoKRf9GO9uVZeaAS/DRqXC9 XGhcvPxOpy+LzRd7O8dDb5/1C51c0H7+9VFOzN4ZVKU8Z1X5gdDoVyD2OYB/1W6tk3Zr g4jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references:in-reply-to:references; bh=FpQSNaPYCXSYEBnFQqrTBKK9INGNoG9PlUp9vwjb6Bo=; b=YFPUH3RwYb6DhxeKHI1T/vXeqrV7dWYUpVJrJjeYjqloBTyDJyHmjP6il1nsahSNt2 7XAwtkn9phczNfXKgDV/qxl0ojDfMqSLdmm39HfTbJCtHGhbrnRGL1GPyTUwWDvuRwGd AjwTBdpav2Z9gKtvDjcAXLsjoBPMN1zHnRHlsZnMFmnVwfphvFg140okg3C07iHH75mB mJs+H+Ie8AiukVaAr6C30MixJJ9MDtR0C5ETjrdoMvKoqoRauGdQoMTxRsegmZjQVeLm qi5i8zNsRTdXJXIIoihbtheDN9MPqW2xl5ySYH3ncaJgyM6D+wtb2CEVcKr5CrMyGNy1 nKAQ== X-Gm-Message-State: AJcUukc2L4Obb/cmdcBz4ASdOnYUCEpo+dBoPSYdCyD+qYUSqXCWDU40 nb7Jvqk+DDTTktz3A7GztrZCt2IuYXq8bw== X-Google-Smtp-Source: ALg8bN5brNl5opd+21dHWGeAVF8c2KTZvgnHz564zDXQMs5s1dmMRDs+iPtvtFxDqTGrZu+qZp7Shw== X-Received: by 2002:adf:e08c:: with SMTP id c12mr33238613wri.199.1548948679006; Thu, 31 Jan 2019 07:31:19 -0800 (PST) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id v1sm9866903wrw.90.2019.01.31.07.31.18 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 31 Jan 2019 07:31:18 -0800 (PST) From: Michal Simek To: u-boot@lists.denx.de, Simon Glass Date: Thu, 31 Jan 2019 16:31:00 +0100 Message-Id: <6acaec7fd5c7cff1f1a8e803d949d9efb7e3ff9b.1548948659.git.michal.simek@xilinx.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: Subject: [U-Boot] [PATCH v2 4/7] dm: core: Add tests for dev_read_alias_highest_id() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" It is checking the highest alias ID for eth, gpio, pci, i2c and error code on non existing alias. Signed-off-by: Michal Simek Reviewed-by: Heiko Schocher Reviewed-by: Simon Glass --- Changes in v2: - New patch test/dm/test-fdt.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c index 984b80c02c81..be16c99e170e 100644 --- a/test/dm/test-fdt.c +++ b/test/dm/test-fdt.c @@ -219,6 +219,29 @@ static int dm_test_fdt(struct unit_test_state *uts) } DM_TEST(dm_test_fdt, 0); +static int dm_test_alias_highest_id(struct unit_test_state *uts) +{ + int ret; + + ret = dev_read_alias_highest_id("eth"); + ut_asserteq(5, ret); + + ret = dev_read_alias_highest_id("gpio"); + ut_asserteq(2, ret); + + ret = dev_read_alias_highest_id("pci"); + ut_asserteq(2, ret); + + ret = dev_read_alias_highest_id("i2c"); + ut_asserteq(0, ret); + + ret = dev_read_alias_highest_id("deadbeef"); + ut_asserteq(-1, ret); + + return 0; +} +DM_TEST(dm_test_alias_highest_id, 0); + static int dm_test_fdt_pre_reloc(struct unit_test_state *uts) { struct uclass *uc; From patchwork Thu Jan 31 15:31:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1034320 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="COpx48IR"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43r43F2rGkz9sBQ for ; Fri, 1 Feb 2019 02:31:53 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id E1A00C21F0B; Thu, 31 Jan 2019 15:31:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A8C08C21F80; Thu, 31 Jan 2019 15:31:33 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 35DA3C21FAF; Thu, 31 Jan 2019 15:31:23 +0000 (UTC) Received: from mail-wr1-f65.google.com (mail-wr1-f65.google.com [209.85.221.65]) by lists.denx.de (Postfix) with ESMTPS id 9CA37C21FB7 for ; Thu, 31 Jan 2019 15:31:21 +0000 (UTC) Received: by mail-wr1-f65.google.com with SMTP id r10so3736396wrs.10 for ; Thu, 31 Jan 2019 07:31:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=BZheIlRwGPFSIKq5qjyLnl0tvMeHhrur0LALZEP2O1o=; b=COpx48IRrZrlefjLkwsjITevss6W/7j6OeXSU2fnCp3vRbc2lzP8Isyeib9J3px51k IrRs/vzPQNjFVe0mUUW6kxEfIR/H8puXTXjuqg1u1el8q8B03Tuqfp20LljTswcP3+uG q5YSb6OhLFzLA4oIiZ/L2a0YAYWLWcIQGB6PFTtYJH9+FiPK8XBFRP9JO3OGccBVYzgJ K92RIaCaGxfTf4gSr7gh8HHQJEwvPzEQIEW/exhjFHxVqdQjkj5t7CZo4fW518WUonYd c7ih09B2ocvzordNiBxnBfOorS1tDxzDRKQA++l0CqAeo9PPMl3Pkutgf0Dj4YVXB6zV NZvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:in-reply-to:references; bh=BZheIlRwGPFSIKq5qjyLnl0tvMeHhrur0LALZEP2O1o=; b=E3y39Fl8avvdm5WBJ0roBfS5+72xIkIEJW88N8O6ru9ldeP/csID9kpBq0HQmsvxcC P5e1PcC7r9Y/KYIDSLa3WXiGENFDsG1LaUWo6iNzyJxPEfMKjWhOuZSGqvCMiWeD8Qu6 G4wJYLvgt58Jj4u41y1RiFKdb0+tHs+XmPH930s3WDY2TqD6bQyGs26HnnvW5rSEkI/G asDrkL1VYKRhpS1UrH8hcrrupTjt5OLgHgQ3f9YLTLITpCeTkqH3mKQBolJmLld8hF5o pHvwJmezfraIqyXkECcJI6MzeJRFGkEiBOPS7J3zJ/IFcsWFElRXlwerN58eKyoPlhvX iwzg== X-Gm-Message-State: AJcUukfNUatPLBm3IIAddtI/Z6NFgS/Kk5L90U4b4XhsvROCEdK2NrgA zzJ9nVNs3YUToV1dw1perxfduCpFBhuKig== X-Google-Smtp-Source: ALg8bN5Lcatg8IEWL5v9MjztyUwRvjAXgpPC4bW4BXtVI7pAbYXrqJJ17vCDLWyi61fwyDd5y718NA== X-Received: by 2002:a5d:6549:: with SMTP id z9mr33910072wrv.116.1548948680894; Thu, 31 Jan 2019 07:31:20 -0800 (PST) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id k128sm9206604wmd.37.2019.01.31.07.31.20 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 31 Jan 2019 07:31:20 -0800 (PST) From: Michal Simek To: u-boot@lists.denx.de, Simon Glass Date: Thu, 31 Jan 2019 16:31:01 +0100 Message-Id: <1082bb6e39c47693ef08726590993ff18fb85d92.1548948659.git.michal.simek@xilinx.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: Subject: [U-Boot] [PATCH v2 5/7] i2c: dm: Record maximum id of devices before probing devices X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" There is a need to find out the first free i2c ID which can be used for i2s buses (including i2c buses connected to i2c mux). Do it early in init and share this variable with other i2c classes for uniq bus identification. Signed-off-by: Michal Simek Reviewed-by: Heiko Schocher --- Changes in v2: - Use dev_read_alias_highest_id() - Use uclass private data drivers/i2c/i2c-uclass.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c index 975318e5f254..b26602f3de95 100644 --- a/drivers/i2c/i2c-uclass.c +++ b/drivers/i2c/i2c-uclass.c @@ -619,6 +619,26 @@ static int i2c_child_post_bind(struct udevice *dev) #endif } +struct i2c_priv { + int max_id; +}; + +int i2c_uclass_init(struct uclass *class) +{ + struct i2c_priv *priv = class->priv; + + /* Just for sure */ + if (!priv) + return -ENOMEM; + + /* Get the last allocated alias. */ + priv->max_id = dev_read_alias_highest_id("i2c"); + + debug("%s: highest alias id is %d\n", __func__, priv->max_id); + + return 0; +} + UCLASS_DRIVER(i2c) = { .id = UCLASS_I2C, .name = "i2c", @@ -626,6 +646,8 @@ UCLASS_DRIVER(i2c) = { #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) .post_bind = dm_scan_fdt_dev, #endif + .init = i2c_uclass_init, + .priv_auto_alloc_size = sizeof(struct i2c_priv), .post_probe = i2c_post_probe, .per_device_auto_alloc_size = sizeof(struct dm_i2c_bus), .per_child_platdata_auto_alloc_size = sizeof(struct dm_i2c_chip), From patchwork Thu Jan 31 15:31:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1034327 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="y64KNSt5"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43r47p2STpz9s9G for ; Fri, 1 Feb 2019 02:35:50 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 14E1FC21FAE; Thu, 31 Jan 2019 15:32:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 0F028C21FC2; Thu, 31 Jan 2019 15:31:45 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 4CFAFC21FAE; Thu, 31 Jan 2019 15:31:23 +0000 (UTC) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by lists.denx.de (Postfix) with ESMTPS id 12C55C21ED5 for ; Thu, 31 Jan 2019 15:31:23 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id p6so3025314wmc.1 for ; Thu, 31 Jan 2019 07:31:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=2KmjhJr/NDCoWM8OHuFmtDMsdQmFsDI+ySVGhrulb2Y=; b=y64KNSt5JwN9Jq/BwH/Snoqz6quoJBQWfTJym751SSPPYxAvq49jcsdE2/TdnynWZF FvWQwKrgJLFBr7epdro2WUnacx5XrVYUdAvkExBtu7HvogCuLneyAb4SAX8K8CSbLfYE RIo6APhjeVnW0uU9vUSOu4dw7DpS+beDF9GikCH7eyxSa27xoiMXc2EaYSS8sPA2Dgvp djQBwFYJUN0Z7hLZiyDfJgPvfA4VJNF++8aH1L1s0Rr8aQl11Zp51IWH/FD4aBR/K205 L5RuMDyU/j32A/VJN6E5lQq3jfZ9nFAQVgyM9McTw/+kScYbqXECXnzJmjg3SeSdGSOS tSJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:in-reply-to:references; bh=2KmjhJr/NDCoWM8OHuFmtDMsdQmFsDI+ySVGhrulb2Y=; b=M/hYKNW2m1XKn+P2RUCkXdYs/rIt1cMh1NM2+YFMifVxX9i8yUEYp1BXwTezMv5Bse 5tXtc1mUWnBkgZslAcl8dyxneaqn0RKiDoGiGY6dh2Nzc2aS937RVbcK/Ye2pOHlfzI+ MO2g8eRYIALSiNW3ucI7jgWxTLcUzZ5aTnEvgGuYL9Djhz1MoP5AqyYPjpUc58PvHmR7 kIkAKhYj1GNn6HVxNsgJhGucefeleEyDBvN2af9ByTHqAZzMzACGfAQ4DqbLxplR10Xt cycmBtBuIzV9zos0UdAPraPDI+uCNNECNrhXYbzix08JiFwvhGoEkL1bjiBd2/NrhdWS O6dg== X-Gm-Message-State: AJcUukd3xPQmV+b0nUls1KXHARZHRKr3CFok2SfLJ7uDaMlB+TxAh869 76KRJAzLftFEOZXLvqd7n5wlGHdtHZqbig== X-Google-Smtp-Source: ALg8bN4m1ZV57lYrakUiXtlQcO/OQDOUeHkOGKXqrsJmejd6xooe+eo0plsnTHZIqm/Vj6L4MqToow== X-Received: by 2002:a1c:8c13:: with SMTP id o19mr28680614wmd.56.1548948682398; Thu, 31 Jan 2019 07:31:22 -0800 (PST) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id w18sm5487595wru.54.2019.01.31.07.31.21 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 31 Jan 2019 07:31:21 -0800 (PST) From: Michal Simek To: u-boot@lists.denx.de, Simon Glass Date: Thu, 31 Jan 2019 16:31:02 +0100 Message-Id: X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: Subject: [U-Boot] [PATCH v2 6/7] i2c: Fill req_seq in i2c_post_bind() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" For i2c controllers which are missing alias in DT there is no req_seq setup. This function is setting up proper ID based on highest found alias ID. On zcu102 this is the behavior when patch is applied. ZynqMP> i2c bus Bus 0: i2c@ff020000 20: gpio@20, offset len 1, flags 0 21: gpio@21, offset len 1, flags 0 75: i2c-mux@75, offset len 1, flags 0 Bus 2: i2c@0 Bus 3: i2c@1 Bus 4: i2c@2 Bus 1: i2c@ff030000 (active 1) 74: i2c-mux@74, offset len 1, flags 0 75: i2c-mux@75, offset len 1, flags 0 Bus 5: i2c@0 (active 5) 54: eeprom@54, offset len 1, flags 0 Bus 6: i2c@1 Bus 7: i2c@2 Bus 8: i2c@3 Bus 9: i2c@4 Bus 10: i2c@0 Bus 11: i2c@1 Bus 12: i2c@2 Bus 13: i2c@3 Bus 14: i2c@4 Bus 15: i2c@5 Bus 16: i2c@6 Bus 17: i2c@7 Before this patch applied (controllers have -1 ID) ZynqMP> i2c bus Bus 0: i2c@ff020000 20: gpio@20, offset len 1, flags 0 21: gpio@21, offset len 1, flags 0 75: i2c-mux@75, offset len 1, flags 0 Bus -1: i2c@0 Bus -1: i2c@1 Bus -1: i2c@2 Bus 1: i2c@ff030000 (active 1) 74: i2c-mux@74, offset len 1, flags 0 75: i2c-mux@75, offset len 1, flags 0 Bus -1: i2c@0 (active 0) 54: eeprom@54, offset len 1, flags 0 Bus -1: i2c@1 Bus -1: i2c@2 Bus -1: i2c@3 Bus -1: i2c@4 Bus -1: i2c@0 Bus -1: i2c@1 Bus -1: i2c@2 Bus -1: i2c@3 Bus -1: i2c@4 Bus -1: i2c@5 Bus -1: i2c@6 Bus -1: i2c@7 Signed-off-by: Michal Simek Reviewed-by: Heiko Schocher --- Changes in v2: - Use private uclass data drivers/i2c/i2c-uclass.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c index b26602f3de95..6f3fca2d2326 100644 --- a/drivers/i2c/i2c-uclass.c +++ b/drivers/i2c/i2c-uclass.c @@ -623,6 +623,30 @@ struct i2c_priv { int max_id; }; +static int i2c_post_bind(struct udevice *dev) +{ + struct uclass *class = dev->uclass; + struct i2c_priv *priv = class->priv; + int ret = 0; + + /* Just for sure */ + if (!priv) + return -ENOMEM; + + debug("%s: %s, req_seq=%d\n", __func__, dev->name, dev->req_seq); + + /* if there is no alias ID, use the first free */ + if (dev->req_seq == -1) + dev->req_seq = ++priv->max_id; + + debug("%s: %s, new req_seq=%d\n", __func__, dev->name, dev->req_seq); + +#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) + ret = dm_scan_fdt_dev(dev); +#endif + return ret; +} + int i2c_uclass_init(struct uclass *class) { struct i2c_priv *priv = class->priv; @@ -643,9 +667,7 @@ UCLASS_DRIVER(i2c) = { .id = UCLASS_I2C, .name = "i2c", .flags = DM_UC_FLAG_SEQ_ALIAS, -#if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) - .post_bind = dm_scan_fdt_dev, -#endif + .post_bind = i2c_post_bind, .init = i2c_uclass_init, .priv_auto_alloc_size = sizeof(struct i2c_priv), .post_probe = i2c_post_probe, From patchwork Thu Jan 31 15:31:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michal Simek X-Patchwork-Id: 1034323 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=xilinx.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=monstr-eu.20150623.gappssmtp.com header.i=@monstr-eu.20150623.gappssmtp.com header.b="Yu3xbEnn"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 43r45r5bVGz9s9G for ; Fri, 1 Feb 2019 02:34:08 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 565D2C21FBF; Thu, 31 Jan 2019 15:32:14 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 04CF2C21FA3; Thu, 31 Jan 2019 15:31:38 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 863BEC21FAE; Thu, 31 Jan 2019 15:31:25 +0000 (UTC) Received: from mail-wm1-f67.google.com (mail-wm1-f67.google.com [209.85.128.67]) by lists.denx.de (Postfix) with ESMTPS id C90D2C21FAF for ; Thu, 31 Jan 2019 15:31:24 +0000 (UTC) Received: by mail-wm1-f67.google.com with SMTP id f188so2990058wmf.5 for ; Thu, 31 Jan 2019 07:31:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monstr-eu.20150623.gappssmtp.com; s=20150623; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=WeorYckOu3E4CKNApenSO5gp/xxw2y2tc83lNZU2xcY=; b=Yu3xbEnnuK3Vy0o5/bS13TcZGa6I0IdMZIWL0uPAQRJla+2z0Gazw/b5uqZkHplS/f Zx4gvPQUyG6T2saIbOiYA2ws8YEVOepBEkopvVKgovxIQnxq61aFIE4jOg0qBOzsBkFN ezITp5k87l3hSMR7YOdu+zRlq9/sTCCI4dofYByh6gXjd1em10BS3alD/D3w7RH1p4FZ HJLxbqGhoTqvFqaxrzcpchXbbYSoTPw2G1MgsgGCACwzCQdu9vjrjaguxCVjtompQjRd r6FXRmA0Bx/E+H8qlslr+e4hUmnzteCDGWq+9W16KpUcRDGAek1MpeTrS0s9hudMzLYN AcBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:in-reply-to:references; bh=WeorYckOu3E4CKNApenSO5gp/xxw2y2tc83lNZU2xcY=; b=FuvPMerkTBz+EAbOcJs4Z+DFnNT0ADBlkKbQ+hIoP/fopF46uysIteF1h+LruNkwj1 FyKiGycNiEKS0IzYYsDca8bjInaaJrhbueA09vDBS2KTI4hiUSM/1OPiXeqXY+2Efx5u PoYVxkzHRWvFdPXU7yUWqtVRQ/sjiD5R1kuUugTlh/c6hPneg2ckeMcTMHjQtK9Yvb2P S5/WgY6t0gVmyUUd6e7ZTG8kTbUZ6skCL3ryBw4LkmXGcqyJKBMpghGe1zltwlPF2GYJ ANMlX+c5ZiG5ah1kH5YEL7COYju0+avUNk+9XyfNMUDbbg7LLv2I505WyfIX0+03QWMK JDeA== X-Gm-Message-State: AHQUAuYLM54EcqkLwq/dxkd1+KsmuB2mjzDKb0kwlqzMATwtPtNAOdaY UEDg5pifxVJT1q4L5qmgwiCHdtkDQ7KmrQ== X-Google-Smtp-Source: AHgI3IZI138UhFBq345QT+iaEyFCEbekdVW25BKS2trv5cWoubgv1joE3MISnJ2ygJ0SlfXOwQAJ+Q== X-Received: by 2002:a1c:2902:: with SMTP id p2mr3450339wmp.19.1548948684020; Thu, 31 Jan 2019 07:31:24 -0800 (PST) Received: from localhost (nat-35.starnet.cz. [178.255.168.35]) by smtp.gmail.com with ESMTPSA id a6sm5977584wmh.10.2019.01.31.07.31.23 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Thu, 31 Jan 2019 07:31:23 -0800 (PST) From: Michal Simek To: u-boot@lists.denx.de, Simon Glass Date: Thu, 31 Jan 2019 16:31:03 +0100 Message-Id: X-Mailer: git-send-email 1.9.1 In-Reply-To: References: In-Reply-To: References: Subject: [U-Boot] [PATCH v2 7/7] i2c: mux: Generate longer i2c mux name X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" For !DM case busses are listed as ZynqMP> i2c bus Bus 0: zynq_0 Bus 1: zynq_0->PCA9544A@0x75:0 Bus 2: zynq_0->PCA9544A@0x75:1 Bus 3: zynq_0->PCA9544A@0x75:2 Bus 4: zynq_1 Bus 5: zynq_1->PCA9548@0x74:0 Bus 6: zynq_1->PCA9548@0x74:1 Bus 7: zynq_1->PCA9548@0x74:2 Bus 8: zynq_1->PCA9548@0x74:3 Bus 9: zynq_1->PCA9548@0x74:4 Bus 10: zynq_1->PCA9548@0x75:0 Bus 11: zynq_1->PCA9548@0x75:1 Bus 12: zynq_1->PCA9548@0x75:2 Bus 13: zynq_1->PCA9548@0x75:3 Bus 14: zynq_1->PCA9548@0x75:4 Bus 15: zynq_1->PCA9548@0x75:5 Bus 16: zynq_1->PCA9548@0x75:6 Bus 17: zynq_1->PCA9548@0x75:7 where is exactly describing i2c bus topology. By moving to DM case i2c mux buses are using names from DT and because i2c-muxes describing sub busses with the same names like i2c@0, etc it is hard to identify which bus is where. Linux is adding topology information to i2c-mux busses to identify them better. This patch is doing the same and composing bus name with topology information. When patch is applied with topology information on zcu102-revA. ZynqMP> i2c bus Bus 0: i2c@ff020000 20: gpio@20, offset len 1, flags 0 21: gpio@21, offset len 1, flags 0 75: i2c-mux@75, offset len 1, flags 0 Bus 2: i2c@ff020000->i2c-mux@75->i2c@0 Bus 3: i2c@ff020000->i2c-mux@75->i2c@1 Bus 4: i2c@ff020000->i2c-mux@75->i2c@2 Bus 1: i2c@ff030000 (active 1) 74: i2c-mux@74, offset len 1, flags 0 75: i2c-mux@75, offset len 1, flags 0 Bus 5: i2c@ff030000->i2c-mux@74->i2c@0 (active 5) 54: eeprom@54, offset len 1, flags 0 Bus 6: i2c@ff030000->i2c-mux@74->i2c@1 Bus 7: i2c@ff030000->i2c-mux@74->i2c@2 Bus 8: i2c@ff030000->i2c-mux@74->i2c@3 Bus 9: i2c@ff030000->i2c-mux@74->i2c@4 Bus 10: i2c@ff030000->i2c-mux@75->i2c@0 Bus 11: i2c@ff030000->i2c-mux@75->i2c@1 Bus 12: i2c@ff030000->i2c-mux@75->i2c@2 Bus 13: i2c@ff030000->i2c-mux@75->i2c@3 Bus 14: i2c@ff030000->i2c-mux@75->i2c@4 Bus 15: i2c@ff030000->i2c-mux@75->i2c@5 Bus 16: i2c@ff030000->i2c-mux@75->i2c@6 Bus 17: i2c@ff030000->i2c-mux@75->i2c@7 Behavior before the patch is applied. ZynqMP> i2c bus Bus 0: i2c@ff020000 20: gpio@20, offset len 1, flags 0 21: gpio@21, offset len 1, flags 0 75: i2c-mux@75, offset len 1, flags 0 Bus 2: i2c@0 Bus 3: i2c@1 Bus 4: i2c@2 Bus 1: i2c@ff030000 (active 1) 74: i2c-mux@74, offset len 1, flags 0 75: i2c-mux@75, offset len 1, flags 0 Bus 5: i2c@0 (active 5) 54: eeprom@54, offset len 1, flags 0 Bus 6: i2c@1 Bus 7: i2c@2 Bus 8: i2c@3 Bus 9: i2c@4 Bus 10: i2c@0 Bus 11: i2c@1 Bus 12: i2c@2 Bus 13: i2c@3 Bus 14: i2c@4 Bus 15: i2c@5 Bus 16: i2c@6 Bus 17: i2c@7 Signed-off-by: Michal Simek Reviewed-by: Simon Glass Reviewed-by: Heiko Schocher --- Changes in v2: - Fix headers - Change patch description to focus only on bus name drivers/i2c/muxes/i2c-mux-uclass.c | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-uclass.c b/drivers/i2c/muxes/i2c-mux-uclass.c index a680ee176253..8b1149997a19 100644 --- a/drivers/i2c/muxes/i2c-mux-uclass.c +++ b/drivers/i2c/muxes/i2c-mux-uclass.c @@ -59,11 +59,34 @@ static int i2c_mux_post_bind(struct udevice *mux) dev_for_each_subnode(node, mux) { struct udevice *dev; const char *name; + const char *arrow = "->"; + char *full_name; + int parent_name_len, arrow_len, mux_name_len, name_len; name = ofnode_get_name(node); - ret = device_bind_driver_to_node(mux, "i2c_mux_bus_drv", name, - node, &dev); - debug(" - bind ret=%d, %s\n", ret, dev ? dev->name : NULL); + + /* Calculate lenghts of strings */ + parent_name_len = strlen(mux->parent->name); + arrow_len = strlen(arrow); + mux_name_len = strlen(mux->name); + name_len = strlen(name); + + full_name = calloc(1, parent_name_len + arrow_len + + mux_name_len + arrow_len + name_len + 1); + if (!full_name) + return -ENOMEM; + + /* Compose bus name */ + strcat(full_name, mux->parent->name); + strcat(full_name, arrow); + strcat(full_name, mux->name); + strcat(full_name, arrow); + strcat(full_name, name); + + ret = device_bind_driver_to_node(mux, "i2c_mux_bus_drv", + full_name, node, &dev); + debug(" - bind ret=%d, %s, req_seq %d\n", ret, + dev ? dev->name : NULL, dev->req_seq); if (ret) return ret; }