From patchwork Wed Apr 18 02:38:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133590 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp5390214ljb; Tue, 17 Apr 2018 19:39:30 -0700 (PDT) X-Google-Smtp-Source: AIpwx48NVv71emox4t3FRBQh77gI7uR3etO8LXwd4VQX+6Y7BFhOWvKGMhDtYLXGwOKGtIUhlcWa X-Received: by 10.80.152.227 with SMTP id j90mr762561edb.89.1524019170851; Tue, 17 Apr 2018 19:39:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524019170; cv=none; d=google.com; s=arc-20160816; b=M7mgFylIyLt0Jhy1b8hz9lU44aCjwXMCm3ZEHBVSMQP9DZcBkdavVbH9PrAszLKEmB kHo0Au+r063Ri34l0J102Sp/O8V2v+kaOaYE+QV8+DinqihFwc+j9X5mjg9VQoTuRtyS yz+ltp4Y8unRUjBzGu2kOP4F+MZbanRJGkSuiyTKZd8VZIe/IbXDx2bQO53kMVflG2Hi Ev3gtwIbuuG+8t/qnTDe+yXH9788g2voxY7qQJi7P7zH+E8HRdPAese2DMtumJ1/MMKU hg67/bgtAnwL7/ixeLnpID4SFon18Znc+dhsPZhn0oSR1xxNfs46FUVOuDNeyM4U1QZ+ JwDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:dkim-filter:arc-authentication-results; bh=Xer/VdxesjFfDw1RoWtDZS9346EH8Rm1+dEQFpsyX1E=; b=fFlQyAjI04UOnxJEgNryGHBqH5nmP9imIhxkyC7v+p7gYt7cQQHudDzZq7whCxI+wv T9WP8c4t9G30M/C//uIGYIbL4/0vcIB3kEIVtIrBiQHucWHY6t7/qqnO0hxsWJwuy47w biStx69gpWGyrhxHL0kQhMApnRaiepckiNp9rxVNycS0FKdCXj74bhIUxLPKjUD64Ze+ DqZ23MGWAmEOmTX8qj+dh5vzcr5OpP+bkwbNRT/xsWnHh6mCqgnN2jdUbKYSureRpMDJ qvfyzDSSdrYwE9jniPbRPomV06oYOzVX7cbFP9YvAyY9BqJRLj8IEccGwH6lXpFoZndi IH3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=eBFWsj8v; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id q11si498925edj.185.2018.04.17.19.39.29; Tue, 17 Apr 2018 19:39:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=eBFWsj8v; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id B7F60C21DF3; Wed, 18 Apr 2018 02:39: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=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 3B969C21DF3; Wed, 18 Apr 2018 02:39:26 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 8D78CC21E0F; Wed, 18 Apr 2018 02:39:24 +0000 (UTC) Received: from conuserg-08.nifty.com (conuserg-08.nifty.com [210.131.2.75]) by lists.denx.de (Postfix) with ESMTPS id 9877EC21C27 for ; Wed, 18 Apr 2018 02:39:23 +0000 (UTC) Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id w3I2culD028728; Wed, 18 Apr 2018 11:38:57 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com w3I2culD028728 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1524019138; bh=EaN3uTWbbNm2sWREhMs42a3PNI2jBtIthmWf2mrpiaU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eBFWsj8vBOWmnB83UayGGCu3Y9HrmXsyu4syNzm4EzQzzLcYh18cpahdw5WaNfDED q4/qD+S4+LLi7PtKFLHZNN8/Ji2VAn1OfEpkL8NL/IL9aXp69B5/s491KS56cphMRb fIQ09y9reGIkmgO7lpBkxxdZkdBY60ZuE5udEPEsVWQM+aNLhYtzMy8cLKx25Q42YL n3QSC9XIyoMc3SPSN6JaUvUVbpGS2MAe1xfA0cFJ2zW9UQ81P/WUSbeYBXrHUK+GtM uKGC/sB/pou9Ckp2YnFqvyT+X8kEs4+8X/92w0Gvo4PnDXfzf5+tpRkXESKKDvwhBC 3JzeDZcMGm50Q== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Wed, 18 Apr 2018 11:38:42 +0900 Message-Id: <1524019125-26287-2-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524019125-26287-1-git-send-email-yamada.masahiro@socionext.com> References: <1524019125-26287-1-git-send-email-yamada.masahiro@socionext.com> Subject: [U-Boot] [PATCH 1/4] regmap: clean up regmap allocation 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" Putting zero length array at the end of struct is a common technique to embed arbitrary length of members. There is no good reason to let regmap_alloc_count() branch by "if (count <= 1)". As far as I understood the code, regmap->base is an alias of regmap->ranges[0].start, but it is not helpful but make the code just ugly. Rename regmap_alloc_count() to regmap_alloc() because the _count suffix seems pointless. Signed-off-by: Masahiro Yamada Reviewed-by: Simon Glass --- drivers/core/regmap.c | 31 +++++++++---------------------- include/regmap.h | 7 ++----- 2 files changed, 11 insertions(+), 27 deletions(-) diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c index 8a0e00f..6c3dbe9 100644 --- a/drivers/core/regmap.c +++ b/drivers/core/regmap.c @@ -18,22 +18,13 @@ DECLARE_GLOBAL_DATA_PTR; -static struct regmap *regmap_alloc_count(int count) +static struct regmap *regmap_alloc(int count) { struct regmap *map; - map = malloc(sizeof(struct regmap)); + map = malloc(sizeof(*map) + sizeof(map->ranges[0]) * count); if (!map) return NULL; - if (count <= 1) { - map->range = &map->base_range; - } else { - map->range = malloc(count * sizeof(struct regmap_range)); - if (!map->range) { - free(map); - return NULL; - } - } map->range_count = count; return map; @@ -46,12 +37,11 @@ int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count, struct regmap_range *range; struct regmap *map; - map = regmap_alloc_count(count); + map = regmap_alloc(count); if (!map) return -ENOMEM; - map->base = *reg; - for (range = map->range; count > 0; reg += 2, range++, count--) { + for (range = map->ranges; count > 0; reg += 2, range++, count--) { range->start = *reg; range->size = reg[1]; } @@ -84,11 +74,11 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp) if (!count) return -EINVAL; - map = regmap_alloc_count(count); + map = regmap_alloc(count); if (!map) return -ENOMEM; - for (range = map->range, index = 0; count > 0; + for (range = map->ranges, index = 0; count > 0; count--, range++, index++) { fdt_size_t sz; if (of_live_active()) { @@ -102,7 +92,6 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp) range->size = sz; } } - map->base = map->range[0].start; *mapp = map; @@ -116,15 +105,13 @@ void *regmap_get_range(struct regmap *map, unsigned int range_num) if (range_num >= map->range_count) return NULL; - range = &map->range[range_num]; + range = &map->ranges[range_num]; return map_sysmem(range->start, range->size); } int regmap_uninit(struct regmap *map) { - if (map->range_count > 1) - free(map->range); free(map); return 0; @@ -132,7 +119,7 @@ int regmap_uninit(struct regmap *map) int regmap_read(struct regmap *map, uint offset, uint *valp) { - uint32_t *ptr = map_physmem(map->base + offset, 4, MAP_NOCACHE); + u32 *ptr = map_physmem(map->ranges[0].start + offset, 4, MAP_NOCACHE); *valp = le32_to_cpu(readl(ptr)); @@ -141,7 +128,7 @@ int regmap_read(struct regmap *map, uint offset, uint *valp) int regmap_write(struct regmap *map, uint offset, uint val) { - uint32_t *ptr = map_physmem(map->base + offset, 4, MAP_NOCACHE); + u32 *ptr = map_physmem(map->ranges[0].start + offset, 4, MAP_NOCACHE); writel(cpu_to_le32(val), ptr); diff --git a/include/regmap.h b/include/regmap.h index 493a5d8..858aa7e 100644 --- a/include/regmap.h +++ b/include/regmap.h @@ -22,15 +22,12 @@ struct regmap_range { /** * struct regmap - a way of accessing hardware/bus registers * - * @base: Base address of register map * @range_count: Number of ranges available within the map - * @range: Pointer to the list of ranges, allocated if @range_count > 1 - * @base_range: If @range_count is <= 1, @range points here + * @ranges: Array of ranges */ struct regmap { - phys_addr_t base; int range_count; - struct regmap_range *range, base_range; + struct regmap_range ranges[]; }; /* From patchwork Wed Apr 18 02:38:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133594 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp5392008ljb; Tue, 17 Apr 2018 19:42:23 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/VibhQSdZX10lvHGNmO/IpChSzTHt2JwV4ylxNHADfSCaopwBfAJWgjy4Yp9t4D9VfciCG X-Received: by 10.80.163.144 with SMTP id s16mr755229edb.271.1524019343446; Tue, 17 Apr 2018 19:42:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524019343; cv=none; d=google.com; s=arc-20160816; b=XV9OnihqAvFr9tiHgVhAZ4+9130OoZLpbeQG3N2In8SOIZYXJi/uSP3kcoiES3/OQG tkKTy/Oi6Ig0dW8G+T1OlrFzZki/ZV53sF+xyWTyFdpKYkWXCIYschJ5mAJFXVkPDnOe s7dk/K7x01yWJnOII9VnuYTmnCB75NcTOMllwGTEoEfN4tYocEJsr4r0CLreTY/1jHNZ VaYCi4Om1FBzEPzIfMfy/6WnwvbFPKM5QZiuK/7frr0mXJdd0bWAQ92InxD8Uu1sht16 ZS/S1KEtyyf+3Fm5J1EJgX9U6WUrUD8BbJ1DJm8RKzfOVc+iuPFd0SMDH7Jbs8A4Mi5e Oa4g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:dkim-filter:arc-authentication-results; bh=kNTrLxu6rZ6kAz37ZAsICKa2FDYE0ocy+7wfCvi1lbw=; b=i68eUjda3ADTzF4xYcK1wMQWhawrn9Ll1ZWzxI/7jIm8oeUw7VMPrM7eBSf74/8s40 piu+5s3wUrcdWdIY/ENo0wZRcFQZpydUpmRRKOx/hwAaElPvwDmQLp6yBVYSjnVC6bvQ P3E/WO0/EmTiFh3F5NklvQkVeMSAQED0D0pYFPDZGpwxnEYvcdzWCH5Aye8FN/g69742 94eSYa422UDK8PiGa7yvdVxNr32MbFsyExb7HiCv5QDWMr+292MTVpWOaQKGYgLiZcBO jZuT17f2Om541xKSfP/wjW28ekWAUT16dlSJWflk+7yWY85/Md+GG6BxkvGcZ232k5VN EcVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=YVCPbxps; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id a19si272421edb.453.2018.04.17.19.42.23; Tue, 17 Apr 2018 19:42:23 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=YVCPbxps; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id 0BDC0C21E34; Wed, 18 Apr 2018 02:40:05 +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 ECD08C21E88; Wed, 18 Apr 2018 02:39:28 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id B7579C21C29; Wed, 18 Apr 2018 02:39:24 +0000 (UTC) Received: from conuserg-08.nifty.com (conuserg-08.nifty.com [210.131.2.75]) by lists.denx.de (Postfix) with ESMTPS id C9FF7C21C2C for ; Wed, 18 Apr 2018 02:39:23 +0000 (UTC) Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id w3I2culE028728; Wed, 18 Apr 2018 11:38:58 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com w3I2culE028728 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1524019138; bh=IxrpUlyh1+x6LHtl4CLbBCJX2JB4A8iZ2BBMpoxwNs8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YVCPbxps7FPoSqLUzEonz1M4/IYBE37Ed8Jvr0QEgOSxuslnSsFzPWDacGRWZGaUW 2GbA3a1S3nKOAyzGsq7s/LWPtAlysc1Ph7X6gmtj7sfhQVQr0FdTGLuiJ2Cc0vayNp KCV6oCmOzhKqR+FTKV0vYzjuBgbWmzpKGtq3TwwsdOIwtGtM8jOFw9CpcZtEWAvCdz srFIDFlwY3cQhGqjPsSAAQuxMCU/5f8cBPjhLAgDu6KPjCM+IFwIxOBcZ9BDHnfuFG 2Uf7TLiJG78+y7DJ0lpZMFRXG3gyZaKOWLvA9wCw+usp4WwNYEuRnt7I4jXfXPq6MR xFvx/Nv8tm3oQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Wed, 18 Apr 2018 11:38:43 +0900 Message-Id: <1524019125-26287-3-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524019125-26287-1-git-send-email-yamada.masahiro@socionext.com> References: <1524019125-26287-1-git-send-email-yamada.masahiro@socionext.com> Subject: [U-Boot] [PATCH 2/4] dm: ofnode: add ofnode_device_is_compatible() helper 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" device_is_compatible() takes udevice, but there is no such a helper that takes ofnode. Signed-off-by: Masahiro Yamada --- drivers/core/device.c | 8 +------- drivers/core/ofnode.c | 11 +++++++++++ include/dm/ofnode.h | 11 +++++++++++ 3 files changed, 23 insertions(+), 7 deletions(-) diff --git a/drivers/core/device.c b/drivers/core/device.c index 940a153..8d95787 100644 --- a/drivers/core/device.c +++ b/drivers/core/device.c @@ -709,13 +709,7 @@ int device_set_name(struct udevice *dev, const char *name) bool device_is_compatible(struct udevice *dev, const char *compat) { - const void *fdt = gd->fdt_blob; - ofnode node = dev_ofnode(dev); - - if (ofnode_is_np(node)) - return of_device_is_compatible(ofnode_to_np(node), compat, NULL, NULL); - else - return !fdt_node_check_compatible(fdt, ofnode_to_offset(node), compat); + return ofnode_device_is_compatible(dev_ofnode(dev), compat); } bool of_machine_is_compatible(const char *compat) diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c index 5909a25..ee2109b 100644 --- a/drivers/core/ofnode.c +++ b/drivers/core/ofnode.c @@ -687,3 +687,14 @@ u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr) else return fdt_translate_address(gd->fdt_blob, ofnode_to_offset(node), in_addr); } + +int ofnode_device_is_compatible(ofnode node, const char *compat) +{ + if (ofnode_is_np(node)) + return of_device_is_compatible(ofnode_to_np(node), compat, + NULL, NULL); + else + return !fdt_node_check_compatible(gd->fdt_blob, + ofnode_to_offset(node), + compat); +} diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h index 0d00840..a2c6a50 100644 --- a/include/dm/ofnode.h +++ b/include/dm/ofnode.h @@ -681,4 +681,15 @@ int ofnode_read_resource_byname(ofnode node, const char *name, * @return the translated address; OF_BAD_ADDR on error */ u64 ofnode_translate_address(ofnode node, const fdt32_t *in_addr); + +/** + * ofnode_device_is_compatible() - check if the node is compatible with compat + * + * This allows to check whether the node is comaptible with the compat. + * + * @node: Device tree node for which compatible needs to be verified. + * @compat: Compatible string which needs to verified in the given node. + * @return true if OK, false if the compatible is not found + */ +int ofnode_device_is_compatible(ofnode node, const char *compat); #endif From patchwork Wed Apr 18 02:38:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133592 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp5391475ljb; Tue, 17 Apr 2018 19:41:29 -0700 (PDT) X-Google-Smtp-Source: AIpwx48zwBqhisgLpHgsRFsokNQFzSZdhQvWbebKc4Qdz6QFqSsGlRK53UE/fuGyNsUS1J83gC7U X-Received: by 10.80.128.5 with SMTP id 5mr796014eda.130.1524019289207; Tue, 17 Apr 2018 19:41:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524019289; cv=none; d=google.com; s=arc-20160816; b=rjBu0LTo5QEuNQOfnSAc4m5geN9pj97wnk4QSdOdwuE/zYsPYRqirWgmQ6uhTXiMm5 rBVGdg6CCjP0A0I/aYfGbsZoz0H4fZthLKeeOw3PoUcKSxOCASvhpXTjBs9w4ZuyaxB/ ZlXQ2UiH4868SqxcJMtelF9NDd/9ubVozj2fntKW5wBCMRLPIqlbPAhfpDKR42OnQrbm eIVHG/vvDAGs/zTD2F/W0O02UIEyOedm6K8UzY3lC0xdfx/AjviAibtSV8plfKjhuImL yv+a6txXp8OAA/xz/QTMeBM8OT5wk/FuJxjLkNDE0Pml2Moq0ImQ0c+w88q0J6hZuQJs LyTw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:dkim-filter:arc-authentication-results; bh=w0VDYYHB++DRVhETIKsduI3socrNcDjFugVvkktP1BU=; b=YTW7F1warMoF0/BUtZijrK0aXfYvoy4n4IeozKr8sDEId58R1Najo0U3XTwAtbLMTI ttwerUUQzK2fJSnLJfO4LkXDYfU7kPBDnNYUUpFpCii/C+od2mM/53Ni30tQcuJG1gXM JL7TLLuXfRdubKHTPx5Ikv64R8jO2uAU6li3G9SNYMClzbmUGnW5/jli4C3FxtkSgi0K ZPYqtkPseryIGW4YG/b6N+rnyi1otwhoWnf6S672lyrvHbwSFak5b/s90airz+gJRxgL 5MqyazQ5gEfVogWru5JNnTywms4owDKPzkfCGpNPfec0w6l49fKNEQCHyR6royeoSEtO 6ERQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=q+0Jf+Wm; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id h1si195681ede.397.2018.04.17.19.41.28; Tue, 17 Apr 2018 19:41:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=q+0Jf+Wm; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id C4FA9C21E3B; Wed, 18 Apr 2018 02:40:38 +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 E229CC21E76; Wed, 18 Apr 2018 02:40:22 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 6CBE8C21E76; Wed, 18 Apr 2018 02:39:39 +0000 (UTC) Received: from conuserg-08.nifty.com (conuserg-08.nifty.com [210.131.2.75]) by lists.denx.de (Postfix) with ESMTPS id 9E24BC21E89 for ; Wed, 18 Apr 2018 02:39:35 +0000 (UTC) Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id w3I2culF028728; Wed, 18 Apr 2018 11:38:59 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com w3I2culF028728 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1524019139; bh=qlqzDsi+mBcuG6yjjndvpMtS6Hzfuesej+nDjtQxORM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q+0Jf+WmGrpPzbtHGXY8t4tkIKEJND3G4aPm9Nl4cwoiUuDSNQLI7zc4Rys1M0PRk 0Hox+GfftCzrEqKOapzJH2PcnSsklRINxcre5wqFOPOlhnrr7Dgwyr393D3C+NwC9e 41446Ccfvcm1jS/HmCCXv+8+poU+T3S1+WF9DoSNB1AkqHrRsaEad878lo6V6Fhh+P bdJa8EcKHTUVoy+faQzuORyv8H51PHOx1DCmL5MK6Eyui+CaJfLFjfUdfrsqhkyA5U /r32ue8lTJiS6g5QzrJNrS4WrMWFnIlhUZO03HXEfG8gbKikymkF5eZOnBNmE7iq21 RS9qO3yDDDRkQ== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Wed, 18 Apr 2018 11:38:44 +0900 Message-Id: <1524019125-26287-4-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524019125-26287-1-git-send-email-yamada.masahiro@socionext.com> References: <1524019125-26287-1-git-send-email-yamada.masahiro@socionext.com> Subject: [U-Boot] [PATCH 3/4] regmap: change regmap_init_mem() to take ofnode instead udevice 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" Currently, regmap_init_mem() takes udevice. This requires the node has already been associated with a device. It prevents syscon/regmap from behaving like those in Linux. Change the first argumenet to take the device node. Signed-off-by: Masahiro Yamada Acked-by: Neil Armstrong --- arch/arm/mach-aspeed/ast2500/sdram_ast2500.c | 2 +- drivers/core/regmap.c | 11 +++++------ drivers/core/syscon-uclass.c | 2 +- drivers/phy/meson-gxl-usb2.c | 2 +- drivers/phy/meson-gxl-usb3.c | 2 +- drivers/ram/rockchip/dmc-rk3368.c | 2 +- drivers/ram/rockchip/sdram_rk3188.c | 2 +- drivers/ram/rockchip/sdram_rk322x.c | 2 +- drivers/ram/rockchip/sdram_rk3288.c | 2 +- drivers/ram/rockchip/sdram_rk3399.c | 2 +- drivers/ram/stm32mp1/stm32mp1_ram.c | 2 +- drivers/reset/reset-meson.c | 2 +- include/regmap.h | 4 ++-- 13 files changed, 18 insertions(+), 19 deletions(-) diff --git a/arch/arm/mach-aspeed/ast2500/sdram_ast2500.c b/arch/arm/mach-aspeed/ast2500/sdram_ast2500.c index 6383f72..f267c58 100644 --- a/arch/arm/mach-aspeed/ast2500/sdram_ast2500.c +++ b/arch/arm/mach-aspeed/ast2500/sdram_ast2500.c @@ -392,7 +392,7 @@ static int ast2500_sdrammc_ofdata_to_platdata(struct udevice *dev) struct regmap *map; int ret; - ret = regmap_init_mem(dev, &map); + ret = regmap_init_mem(dev_ofnode(dev), &map); if (ret) return ret; diff --git a/drivers/core/regmap.c b/drivers/core/regmap.c index 6c3dbe9..1185a44 100644 --- a/drivers/core/regmap.c +++ b/drivers/core/regmap.c @@ -51,7 +51,7 @@ int regmap_init_mem_platdata(struct udevice *dev, fdt_val_t *reg, int count, return 0; } #else -int regmap_init_mem(struct udevice *dev, struct regmap **mapp) +int regmap_init_mem(ofnode node, struct regmap **mapp) { struct regmap_range *range; struct regmap *map; @@ -59,14 +59,13 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp) int addr_len, size_len, both_len; int len; int index; - ofnode node = dev_ofnode(dev); struct resource r; - addr_len = dev_read_simple_addr_cells(dev->parent); - size_len = dev_read_simple_size_cells(dev->parent); + addr_len = ofnode_read_simple_addr_cells(ofnode_get_parent(node)); + size_len = ofnode_read_simple_size_cells(ofnode_get_parent(node)); both_len = addr_len + size_len; - len = dev_read_size(dev, "reg"); + len = ofnode_read_size(node, "reg"); if (len < 0) return len; len /= sizeof(fdt32_t); @@ -87,7 +86,7 @@ int regmap_init_mem(struct udevice *dev, struct regmap **mapp) range->size = r.end - r.start + 1; } else { range->start = fdtdec_get_addr_size_fixed(gd->fdt_blob, - dev_of_offset(dev), "reg", index, + ofnode_to_offset(node), "reg", index, addr_len, size_len, &sz, true); range->size = sz; } diff --git a/drivers/core/syscon-uclass.c b/drivers/core/syscon-uclass.c index a69937e..c99409b 100644 --- a/drivers/core/syscon-uclass.c +++ b/drivers/core/syscon-uclass.c @@ -41,7 +41,7 @@ static int syscon_pre_probe(struct udevice *dev) return regmap_init_mem_platdata(dev, plat->reg, ARRAY_SIZE(plat->reg), &priv->regmap); #else - return regmap_init_mem(dev, &priv->regmap); + return regmap_init_mem(dev_ofnode(dev), &priv->regmap); #endif } diff --git a/drivers/phy/meson-gxl-usb2.c b/drivers/phy/meson-gxl-usb2.c index 15c9c89..7242bf6 100644 --- a/drivers/phy/meson-gxl-usb2.c +++ b/drivers/phy/meson-gxl-usb2.c @@ -195,7 +195,7 @@ int meson_gxl_usb2_phy_probe(struct udevice *dev) struct phy_meson_gxl_usb2_priv *priv = dev_get_priv(dev); int ret; - ret = regmap_init_mem(dev, &priv->regmap); + ret = regmap_init_mem(dev_ofnode(dev), &priv->regmap); if (ret) return ret; diff --git a/drivers/phy/meson-gxl-usb3.c b/drivers/phy/meson-gxl-usb3.c index a385fbd..47a41fd 100644 --- a/drivers/phy/meson-gxl-usb3.c +++ b/drivers/phy/meson-gxl-usb3.c @@ -166,7 +166,7 @@ int meson_gxl_usb3_phy_probe(struct udevice *dev) struct phy_meson_gxl_usb3_priv *priv = dev_get_priv(dev); int ret; - ret = regmap_init_mem(dev, &priv->regmap); + ret = regmap_init_mem(dev_ofnode(dev), &priv->regmap); if (ret) return ret; diff --git a/drivers/ram/rockchip/dmc-rk3368.c b/drivers/ram/rockchip/dmc-rk3368.c index bfcb1dd..9bf64bf 100644 --- a/drivers/ram/rockchip/dmc-rk3368.c +++ b/drivers/ram/rockchip/dmc-rk3368.c @@ -880,7 +880,7 @@ static int rk3368_dmc_ofdata_to_platdata(struct udevice *dev) #if !CONFIG_IS_ENABLED(OF_PLATDATA) struct rk3368_sdram_params *plat = dev_get_platdata(dev); - ret = regmap_init_mem(dev, &plat->map); + ret = regmap_init_mem(dev_ofnode(dev), &plat->map); if (ret) return ret; #endif diff --git a/drivers/ram/rockchip/sdram_rk3188.c b/drivers/ram/rockchip/sdram_rk3188.c index 365d00e..c0a2618 100644 --- a/drivers/ram/rockchip/sdram_rk3188.c +++ b/drivers/ram/rockchip/sdram_rk3188.c @@ -842,7 +842,7 @@ static int rk3188_dmc_ofdata_to_platdata(struct udevice *dev) printf("%s: Cannot read rockchip,sdram-params\n", __func__); return -EINVAL; } - ret = regmap_init_mem(dev, ¶ms->map); + ret = regmap_init_mem(dev_ofnode(dev), ¶ms->map); if (ret) return ret; #endif diff --git a/drivers/ram/rockchip/sdram_rk322x.c b/drivers/ram/rockchip/sdram_rk322x.c index cc3138b..dca07db 100644 --- a/drivers/ram/rockchip/sdram_rk322x.c +++ b/drivers/ram/rockchip/sdram_rk322x.c @@ -744,7 +744,7 @@ static int rk322x_dmc_ofdata_to_platdata(struct udevice *dev) printf("%s: Cannot read rockchip,sdram-params\n", __func__); return -EINVAL; } - ret = regmap_init_mem(dev, ¶ms->map); + ret = regmap_init_mem(dev_ofnode(dev), ¶ms->map); if (ret) return ret; #endif diff --git a/drivers/ram/rockchip/sdram_rk3288.c b/drivers/ram/rockchip/sdram_rk3288.c index 95efb11..ffb663c 100644 --- a/drivers/ram/rockchip/sdram_rk3288.c +++ b/drivers/ram/rockchip/sdram_rk3288.c @@ -1003,7 +1003,7 @@ static int rk3288_dmc_ofdata_to_platdata(struct udevice *dev) priv->is_veyron = !fdt_node_check_compatible(blob, 0, "google,veyron"); #endif - ret = regmap_init_mem(dev, ¶ms->map); + ret = regmap_init_mem(dev_ofnode(dev), ¶ms->map); if (ret) return ret; #endif diff --git a/drivers/ram/rockchip/sdram_rk3399.c b/drivers/ram/rockchip/sdram_rk3399.c index 5cb470c..6e2a39e 100644 --- a/drivers/ram/rockchip/sdram_rk3399.c +++ b/drivers/ram/rockchip/sdram_rk3399.c @@ -1100,7 +1100,7 @@ static int rk3399_dmc_ofdata_to_platdata(struct udevice *dev) __func__, ret); return ret; } - ret = regmap_init_mem(dev, &plat->map); + ret = regmap_init_mem(dev_ofnode(dev), &plat->map); if (ret) printf("%s: regmap failed %d\n", __func__, ret); diff --git a/drivers/ram/stm32mp1/stm32mp1_ram.c b/drivers/ram/stm32mp1/stm32mp1_ram.c index 9599444..a4d5906 100644 --- a/drivers/ram/stm32mp1/stm32mp1_ram.c +++ b/drivers/ram/stm32mp1/stm32mp1_ram.c @@ -149,7 +149,7 @@ static int stm32mp1_ddr_probe(struct udevice *dev) debug("STM32MP1 DDR probe\n"); priv->dev = dev; - ret = regmap_init_mem(dev, &map); + ret = regmap_init_mem(dev_ofnode(dev), &map); if (ret) return ret; diff --git a/drivers/reset/reset-meson.c b/drivers/reset/reset-meson.c index 5324f86..c41d176 100644 --- a/drivers/reset/reset-meson.c +++ b/drivers/reset/reset-meson.c @@ -77,7 +77,7 @@ static int meson_reset_probe(struct udevice *dev) { struct meson_reset_priv *priv = dev_get_priv(dev); - return regmap_init_mem(dev, &priv->regmap); + return regmap_init_mem(dev_ofnode(dev), &priv->regmap); } U_BOOT_DRIVER(meson_reset) = { diff --git a/include/regmap.h b/include/regmap.h index 858aa7e..c8a1df0 100644 --- a/include/regmap.h +++ b/include/regmap.h @@ -48,10 +48,10 @@ int regmap_read(struct regmap *map, uint offset, uint *valp); * * Use regmap_uninit() to free it. * - * @dev: Device that uses this map + * @node: Device node that uses this map * @mapp: Returns allocated map */ -int regmap_init_mem(struct udevice *dev, struct regmap **mapp); +int regmap_init_mem(ofnode node, struct regmap **mapp); /** * regmap_init_mem_platdata() - Set up a new memory register map for of-platdata From patchwork Wed Apr 18 02:38:45 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Masahiro Yamada X-Patchwork-Id: 133591 Delivered-To: patch@linaro.org Received: by 10.46.84.18 with SMTP id i18csp5390692ljb; Tue, 17 Apr 2018 19:40:13 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/kFfzLa8XpZBhV7eK6gdIQ+vrSadglXIYYziMq0Ggv6HV0tWxBz29bkgHqGCq+bykha0ej X-Received: by 10.80.179.92 with SMTP id r28mr776294edd.145.1524019213365; Tue, 17 Apr 2018 19:40:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524019213; cv=none; d=google.com; s=arc-20160816; b=j02Fk6D5YmxKk823+2963xgwHL5vZMMNRGrnJCEEPSvZ0s2JNORtppO4m0SRNiG87Z 89Pky9N5DZEl6kQ7FPyqbIDOdQQwUec5DPqbQ9kk4nCK9G39mGIBVe5v7aM7n2z4gBrd UdauxvdyKRzFuEACqbIyzt6jG99aT35mACpnygXlQlyW8t/L6siYdnhf/q3s6S8ZO+CH V00w0csjos+MVeWTYgvp0gyVmwQ90cOBA099iGiqAYUKWSB0hPdaarJR2f50m0Uka+cj YUxBFhCC2CdNUKtApCUr17EKb2MBNi//8RkXXZ9Kwj0l4bTQa+44Ct8sSSRDVCa5iP4E d/wQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:dkim-filter:arc-authentication-results; bh=pSZlg7H8I8Vtgamg4XKPRLqvNlDkG1S2wJpoJidgMFQ=; b=ZgagWpzMXmC740fsj2wShTkBla1jHm4FQI/tzZHKbW/LrOgIIdmYqnosy0iP0FjCA1 fM/yeJO+153xxPYstfnCs0hihMhFpF3vSAWm4Lmkqjq7xZth541afftHRbJXC2bS84J3 3SsEBFp6sQn/wDqhZ+JIPFg6fUJP55Dzj9I3GHX0RFg5FY7/oW6V2tGmJ4AINE7PdIjL kj7gzJeDAk0h69XOBB9Gp6qYhEmjX9fx6yBx7PUQQ4aHoZEb9fCmw29UWBUpyi/QRWwU PaLIrhT6wl/165Vky3sh7r+eWQxqieAuYcMHJW4dRxti/xiIhSKevImfe5yGc2ENEK0Y dFYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=YWt0lc86; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id o2si345756edf.305.2018.04.17.19.40.13; Tue, 17 Apr 2018 19:40:13 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@nifty.com header.s=dec2015msa header.b=YWt0lc86; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by lists.denx.de (Postfix, from userid 105) id E3775C21E70; Wed, 18 Apr 2018 02:39:45 +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 110A8C21E68; Wed, 18 Apr 2018 02:39:28 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A1BFCC21C27; Wed, 18 Apr 2018 02:39:24 +0000 (UTC) Received: from conuserg-08.nifty.com (conuserg-08.nifty.com [210.131.2.75]) by lists.denx.de (Postfix) with ESMTPS id AA504C21C29 for ; Wed, 18 Apr 2018 02:39:23 +0000 (UTC) Received: from pug.e01.socionext.com (p14092-ipngnfx01kyoto.kyoto.ocn.ne.jp [153.142.97.92]) (authenticated) by conuserg-08.nifty.com with ESMTP id w3I2culG028728; Wed, 18 Apr 2018 11:38:59 +0900 DKIM-Filter: OpenDKIM Filter v2.10.3 conuserg-08.nifty.com w3I2culG028728 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nifty.com; s=dec2015msa; t=1524019140; bh=GfNL4XrKT+ma3+l4z+n5IcK+wqYQg/KGgCBHJDi8bB0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YWt0lc86Gw0Q6H3S9u2QawurxFgK23QIy+GDJIgZf79Ox4cNTEj9QBugemcFvPnx4 qUY2Mar6ZEIbWRajucJNq2LOGsByTas2uj67dq+YP3kkmE2S3vIXVRtjqw9mGWEQ9S 4nfiO1m/OMFYK4hO7O2oRW1HMb7ghLmBLTfKu8C7wke6PpdhK4SpwRQXLrCr+72EAs FU4EJmIKIffU73of5y0bbtjoag0sVeScfRqeElICxr2/dXjNhsyN8IqUS5MU69C1JE EfnGWKqhr2On9MEQ+8Y8/Wnd/YKFIVsZ8AnUZ4bfgYwIhAPBBb1khaVK8U5+1HvasV u02tEfBcvw8BA== X-Nifty-SrcIP: [153.142.97.92] From: Masahiro Yamada To: u-boot@lists.denx.de Date: Wed, 18 Apr 2018 11:38:45 +0900 Message-Id: <1524019125-26287-5-git-send-email-yamada.masahiro@socionext.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1524019125-26287-1-git-send-email-yamada.masahiro@socionext.com> References: <1524019125-26287-1-git-send-email-yamada.masahiro@socionext.com> Subject: [U-Boot] [PATCH 4/4] syscon: add Linux-compatible syscon API 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 syscon implementation in U-Boot is different from that in Linux. Thus, DT files imported from Linux do not work for U-Boot. In U-Boot driver model, each node is bound to a dedicated driver that is the most compatible to it. This design gets along with the concept of DT, and the syscon in Linux originally worked like that. However, Linux commit bdb0066df96e ("mfd: syscon: Decouple syscon interface from platform devices") changed the behavior because it is useful to let a device bind to another driver, but still works as a syscon provider. That change had happened before U-Boot initially supported the syscon driver by commit 6f98b7504f70 ("dm: Add support for generic system controllers (syscon)"). So, the U-Boot's syscon works differently from the beginning. I'd say this is mis-implementation given that DT is not oriented to a particular project, but Linux is the canon of DT in practice. The problem typically arises in the combination of "syscon" and "simple-mfd" compatibles. In Linux, they are orthogonal, i.e., the order between "syscon" and "simple-mfd" does not matter at all. Assume the following compatible. compatible = "foo,bar-syscon", "syscon", "simple-mfd"; In U-Boot, this device node is bound to the syscon driver (driver/core/syscon-uclass.c) since the "syscon" is found to be the most compatible. Then, syscon_get_regmap() succeeds. However, compatible = "foo,bar-syscon", "simple-mfd", "syscon"; does not work because this node is bound to the simple-bus driver (drivers/core/simple-bus.c) in the favor of "simple-mfd" compatible. The compatible string "syscon" is just dismissed. Moreover, compatible = "foo,bar-syscon", "syscon"; works like the first case because the syscon driver populates the child devices. This is wrong because populating children is the job of "simple-mfd" (or "simple-bus"). This commit ports syscon_node_to_regmap() from Linux. This API does not require the given node to be bound to a driver in any way. Reported-by: Kunihiko Hayashi Signed-off-by: Masahiro Yamada --- drivers/core/syscon-uclass.c | 63 ++++++++++++++++++++++++++++++++++++++++++++ include/syscon.h | 8 ++++++ 2 files changed, 71 insertions(+) diff --git a/drivers/core/syscon-uclass.c b/drivers/core/syscon-uclass.c index c99409b..bd2f681 100644 --- a/drivers/core/syscon-uclass.c +++ b/drivers/core/syscon-uclass.c @@ -15,6 +15,14 @@ #include #include +/* + * Caution: + * This API requires the given node has already been bound to "syscon". + * compatible = "syscon", "simple-mfd"; + * works, but + * compatible = "simple-mfd", "syscon"; + * does not. This behavior is different from Linux. + */ struct regmap *syscon_get_regmap(struct udevice *dev) { struct syscon_uc_info *priv; @@ -109,3 +117,58 @@ U_BOOT_DRIVER(generic_syscon) = { #endif .of_match = generic_syscon_ids, }; + +/* + * Linux-compatible syscon-to-regmap + * The syscon node can be bound to another driver, but still works + * as a syscon provider. + */ +static LIST_HEAD(syscon_list); + +struct syscon { + ofnode node; + struct regmap *regmap; + struct list_head list; +}; + +static struct syscon *of_syscon_register(ofnode node) +{ + struct syscon *syscon; + int ret; + + if (!ofnode_device_is_compatible(node, "syscon")) + return ERR_PTR(-EINVAL); + + syscon = malloc(sizeof(*syscon)); + if (!syscon) + return ERR_PTR(-ENOMEM); + + ret = regmap_init_mem(node, &syscon->regmap); + if (ret) { + free(syscon); + return ERR_PTR(ret); + } + + list_add_tail(&syscon->list, &syscon_list); + + return syscon; +} + +struct regmap *syscon_node_to_regmap(ofnode node) +{ + struct syscon *entry, *syscon = NULL; + + list_for_each_entry(entry, &syscon_list, list) + if (ofnode_equal(entry->node, node)) { + syscon = entry; + break; + } + + if (!syscon) + syscon = of_syscon_register(node); + + if (IS_ERR(syscon)) + return ERR_CAST(syscon); + + return syscon->regmap; +} diff --git a/include/syscon.h b/include/syscon.h index 5d52b1c..a019345 100644 --- a/include/syscon.h +++ b/include/syscon.h @@ -8,6 +8,7 @@ #ifndef __SYSCON_H #define __SYSCON_H +#include #include /** @@ -82,4 +83,11 @@ struct regmap *syscon_get_regmap_by_driver_data(ulong driver_data); */ void *syscon_get_first_range(ulong driver_data); +/** + * syscon_node_to_regmap - Linux-compat syscon lookup + * + * @node: Device node of syscon + */ +struct regmap *syscon_node_to_regmap(ofnode node); + #endif