From patchwork Wed Mar 8 15:31:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66294 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp403423wrd; Wed, 8 Mar 2023 07:34:34 -0800 (PST) X-Google-Smtp-Source: AK7set9MrUYNOHiwA0b1mZL+WGAkaybDtU1igHTfSEUPxC3yqY5AGQERiZsK3WjeqJBFXMN5vOZ0 X-Received: by 2002:a17:902:c389:b0:19e:7880:a5a with SMTP id g9-20020a170902c38900b0019e78800a5amr16457804plg.39.1678289674425; Wed, 08 Mar 2023 07:34:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678289674; cv=none; d=google.com; s=arc-20160816; b=Js/+drd4mwfvw2gUQtOv7HPFzwbRMBWLqrSgxrfrJzO8o0dFny1zHMnYV08IVjrXDh 435nx1k5dw4ssJTfc7DrLAhWjDm88/bQcLWf96Hvs++JZMMQ1yN4SHO5jJ1316ymGFgE EBn3mEYgoZTISkUhbIAOH+0KlENO886zAoCR6YCPL6M5omMmRKv0epgNZmePMbqp649R 7Lk+gXr8E3Yp6+FuaegKfNv9B1llkMznlAnpAQ1B2avIwmwfl3EknzicvElxId7HdaJk hJHN97jaQY3X3wW/j4qyp/UbyU59dfpRuNXo3OnXicLRyxUJKtqBxlRQKmyPWJghXz3u vSAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=IJ3o8unBTMIe9q90/GtJ5ny60FdItpVL7wHmQ3YSkUw=; b=CODOWyWc5Yt0aup0tL8oeXwYTUSsRAmlf49jFLZfHHkP8WYuzcsJpwZVsbIJRtGUi/ qVFF9rphNoPQXRbOthShcpkZSN2Y3t5WoKL+wY5VMR6iJPnO1AHTx0lNMUL4LVKEXv7X Ni0CPDpa+9gp+5N3tmTTiv9R9aQ0YbIhk0/qTNvflsk6cJKomxj5eZN76WZH0RcDugxp vDPc7d7KkWwXKUd40WUlaJC1LGQomZJiHSCYeda50bPtEO6BcTXAV9Z5Lm8IUvHVmL/K yny2lHv+cyJNx6wyF+uIqDBZK+xr9Htzlee1fV0cLiY14zgtQpM9cx0fRBK6z6IhAi/g O37A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=CJFcNjdd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h19-20020a63df53000000b004fb647a765esi14591003pgj.329.2023.03.08.07.34.18; Wed, 08 Mar 2023 07:34:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=CJFcNjdd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231975AbjCHPcN (ORCPT + 99 others); Wed, 8 Mar 2023 10:32:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231816AbjCHPcI (ORCPT ); Wed, 8 Mar 2023 10:32:08 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A2A5B8C514; Wed, 8 Mar 2023 07:32:06 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 9C810FF80F; Wed, 8 Mar 2023 15:32:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289525; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IJ3o8unBTMIe9q90/GtJ5ny60FdItpVL7wHmQ3YSkUw=; b=CJFcNjdd9fcOXVkHGwRZGNuoq0mkCfr5tUfdHT1Pa1l85hzCFkDM2s5KFO7RIKnuk7LhI8 sRJqdVpg8k3Zz8hwucefY4gQTbjof3zCKTM+m9I8AnXN7UoRzpGMhfkej83IQ9apvsy+vr hBBDAi5nlLRO8eaTxB/EAykV1zvGhJ9231v7hkONWBhvYsz2xC0RpZN5ovtcvLsoGhMrN7 4hRALJR3alssliRMa17xCMgXk9Fu/HgMdkBWZwAgD7jRClxxOmzrdybgfED7R8JVww3lRK kJunlnjLlRd+Wi5ZGAgzF770Fa1sWhqrb3Lc2p5U63d8UlCWxKaNrhAqRGLyaQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal , Stephen Boyd , Peter Chen , Rob Herring Subject: [PATCH v3 01/20] of: Fix modalias string generation Date: Wed, 8 Mar 2023 16:31:41 +0100 Message-Id: <20230308153200.682248-2-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814273664042309?= X-GMAIL-MSGID: =?utf-8?q?1759814273664042309?= The helper generating an OF based modalias (of_device_get_modalias()) works fine, but due to the use of snprintf() internally it needs a buffer one byte longer than what should be needed just for the entire string (excluding the '\0'). Most users of this helper are sysfs hooks providing the modalias string to users. They all provide a PAGE_SIZE buffer which is way above the number of bytes required to fit the modalias string and hence do not suffer from this issue. There is another user though, of_device_request_module(), which is only called by drivers/usb/common/ulpi.c. This request module function is faulty, but maybe because in most cases there is an alternative, ULPI driver users have not noticed it. In this function, of_device_get_modalias() is called twice. The first time without buffer just to get the number of bytes required by the modalias string (excluding the null byte), and a second time, after buffer allocation, to fill the buffer. The allocation asks for an additional byte, in order to store the trailing '\0'. However, the buffer *length* provided to of_device_get_modalias() excludes this extra byte. The internal use of snprintf() with a length that is exactly the number of bytes to be written has the effect of using the last available byte to store a '\0', which then smashes the last character of the modalias string. Provide the actual size of the buffer to of_device_get_modalias() to fix this issue. Note: the "str[size - 1] = '\0';" line is not really needed as snprintf will anyway end the string with a null byte, but there is a possibility that this function might be called on a struct device_node without compatible, in this case snprintf() would not be executed. So we keep it just to avoid possible unbounded strings. Cc: Stephen Boyd Cc: Peter Chen Fixes: 9c829c097f2f ("of: device: Support loading a module with OF based modalias") Signed-off-by: Miquel Raynal Reviewed-by: Rob Herring --- drivers/of/device.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 955bfb3d1a83..c91bb5899256 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -297,12 +297,15 @@ int of_device_request_module(struct device *dev) if (size < 0) return size; - str = kmalloc(size + 1, GFP_KERNEL); + /* Reserve an additional byte for the trailing '\0' */ + size++; + + str = kmalloc(size, GFP_KERNEL); if (!str) return -ENOMEM; of_device_get_modalias(dev, str, size); - str[size] = '\0'; + str[size - 1] = '\0'; ret = request_module(str); kfree(str); From patchwork Wed Mar 8 15:31:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66311 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp406937wrd; Wed, 8 Mar 2023 07:41:21 -0800 (PST) X-Google-Smtp-Source: AK7set/I8OBnWCjSxyoFKxd/LDlPs9zhevoPXYy1bGPw5iI2XCBkXlrFOf/oCcJXnXHMn7I3X1kN X-Received: by 2002:a17:902:7787:b0:19e:4bc3:b1ef with SMTP id o7-20020a170902778700b0019e4bc3b1efmr2360325pll.64.1678290080749; Wed, 08 Mar 2023 07:41:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678290080; cv=none; d=google.com; s=arc-20160816; b=OteYGTOa03A06DDa8wgM8JrQp2kkK3qdkUQ/1HFZnQSwtwbF2SCIlJjjgRm9Hyx+6b r6ycDIcNtfLopYuF05vvZmCe2CiyyqHT/TICS6Amg9C32Vpb9cv1DwODntmXixxBvPXc 240liu81aBAwuliElAvWoG0M3SP6e+EvuFpsKdCB1Fbt36+n8O4jBzobo2hk9nmQMGg0 qmCWXIXTqCeOaPMY0Ac0m5/XDoPZlQt/R+zwKxqa0t3A4xMO5hoYt++sOcpTWNab5aIQ mtPvMyyvqO0nKhb+sEst6jTcrWUa0cwZ2QqtaVS5clFYuNDT9qLrpEMEzZrAegM3NHpW Kr3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=d7F2M8VnDDXmy9O162M9BQ7Ae5cMRG6sexpSbXAe5/s=; b=NElLVCV+Bke2VY/sqlZgiaBE3UHJeKI6P0PU/R13FNjrAmNrRSeQMls6lgVPDH4NPq VtHm92AAWzAynm8bvczI7rwH5piLrK7T0foO740DSJG+4Ms3+Clvd3PV8m/LNZLqmVmZ UJQstJC6nt4e/gUUVZV+brbp5X6dDxqbHOcL2wneuqYo/3BW7kAQTkheDZE2Hm0iO/ce 5ngA5Cch7Tbx1Nz2S1D0QeAXMgE1EGfT+4JN0+0F3K4e+wF79rZu7lJMwylkcWAWisYU 1JhRCLbxXg59wkAvXDfDZ8T9PY4H+TVjRN/iMlXeQ8sjUcA+Y3YhiFPpvANXJCC85YIM R5zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=K5yRydIe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id kc12-20020a17090333cc00b0019e665d6b54si14329098plb.13.2023.03.08.07.41.07; Wed, 08 Mar 2023 07:41:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=K5yRydIe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232181AbjCHPcX (ORCPT + 99 others); Wed, 8 Mar 2023 10:32:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49626 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232126AbjCHPcK (ORCPT ); Wed, 8 Mar 2023 10:32:10 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CBADD00BB; Wed, 8 Mar 2023 07:32:08 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 92C2EFF811; Wed, 8 Mar 2023 15:32:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289527; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=d7F2M8VnDDXmy9O162M9BQ7Ae5cMRG6sexpSbXAe5/s=; b=K5yRydIedYdQ7/AlZQzh/LnhSX7R0EnGUcHlKj8ANFe1L3+s7ZSEuoVY34sDhCrNCe7LA1 tzZ3cx+gKgM3z5zflDmxJ3zJQDGHUG1b0mXfIyPBSvYhtbmrnegnydxZ58fTNOVbKdfH4Q +FFVIeGLta5TA29rym45xbKWMMaZxDXd+5/vTdgbNsndmmQaMZDhCwLpUC6LJTvEyo38u1 7W+tarQNhvOh/xK85+oLKi4QuxAdUnqCIEc1t7jNoUjOL5ukWX69VNHPgrMIDlj2n+Lygx NY7uteHJnSlJSNbtlUPa9FMA/TqM06ZeEnXDQ8Xh0FahlD3p1/P76SQKDPspRg== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal , Rob Herring Subject: [PATCH v3 02/20] of: Update of_device_get_modalias() Date: Wed, 8 Mar 2023 16:31:42 +0100 Message-Id: <20230308153200.682248-3-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814699617286403?= X-GMAIL-MSGID: =?utf-8?q?1759814699617286403?= This function only needs a "struct device_node" to work, but for convenience the author (and only user) of this helper did use a "struct device" and put it in device.c. Let's convert this helper to take a "struct device node" instead. This change asks for two additional changes: renaming it "of_modalias()" to fit the current naming, and moving it outside of device.c which will be done in a follow-up commit. Signed-off-by: Miquel Raynal Reviewed-by: Rob Herring --- Hello, please mind that I am on purpose dropping the check for of_node_reused in the request_module helper because I believe this check simply does not apply here. If I am misunderstanding something please let me know. Thanks! --- drivers/of/device.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index c91bb5899256..351c505ecb50 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -248,7 +248,7 @@ const void *of_device_get_match_data(const struct device *dev) } EXPORT_SYMBOL(of_device_get_match_data); -static ssize_t of_device_get_modalias(const struct device *dev, char *str, ssize_t len) +static ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len) { const char *compat; char *c; @@ -256,19 +256,16 @@ static ssize_t of_device_get_modalias(const struct device *dev, char *str, ssize ssize_t csize; ssize_t tsize; - if ((!dev) || (!dev->of_node) || dev->of_node_reused) - return -ENODEV; - /* Name & Type */ /* %p eats all alphanum characters, so %c must be used here */ - csize = snprintf(str, len, "of:N%pOFn%c%s", dev->of_node, 'T', - of_node_get_device_type(dev->of_node)); + csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T', + of_node_get_device_type(np)); tsize = csize; len -= csize; if (str) str += csize; - of_property_for_each_string(dev->of_node, "compatible", p, compat) { + of_property_for_each_string(np, "compatible", p, compat) { csize = strlen(compat) + 1; tsize += csize; if (csize > len) @@ -293,7 +290,10 @@ int of_device_request_module(struct device *dev) ssize_t size; int ret; - size = of_device_get_modalias(dev, NULL, 0); + if (!dev || !dev->of_node) + return -ENODEV; + + size = of_modalias(dev->of_node, NULL, 0); if (size < 0) return size; @@ -304,7 +304,7 @@ int of_device_request_module(struct device *dev) if (!str) return -ENOMEM; - of_device_get_modalias(dev, str, size); + of_modalias(dev->of_node, str, size); str[size - 1] = '\0'; ret = request_module(str); kfree(str); @@ -321,7 +321,12 @@ EXPORT_SYMBOL_GPL(of_device_request_module); */ ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len) { - ssize_t sl = of_device_get_modalias(dev, str, len - 2); + ssize_t sl; + + if (!dev || !dev->of_node || dev->of_node_reused) + return -ENODEV; + + sl = of_modalias(dev->of_node, str, len - 2); if (sl < 0) return sl; if (sl > len - 2) @@ -386,8 +391,8 @@ int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env * if (add_uevent_var(env, "MODALIAS=")) return -ENOMEM; - sl = of_device_get_modalias(dev, &env->buf[env->buflen-1], - sizeof(env->buf) - env->buflen); + sl = of_modalias(dev->of_node, &env->buf[env->buflen-1], + sizeof(env->buf) - env->buflen); if (sl < 0) return sl; if (sl >= (sizeof(env->buf) - env->buflen)) From patchwork Wed Mar 8 15:31:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66310 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp406885wrd; Wed, 8 Mar 2023 07:41:14 -0800 (PST) X-Google-Smtp-Source: AK7set+LphytE0cwIQ8RvIJxNCoW2Q1XhZGCrcSKJ0iaFj/JNfJCtqAdP7AdPRUn4ZJRfO3XX1Fo X-Received: by 2002:a05:6a00:4a:b0:5a7:6ee6:66f9 with SMTP id i10-20020a056a00004a00b005a76ee666f9mr16173434pfk.19.1678290074139; Wed, 08 Mar 2023 07:41:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678290074; cv=none; d=google.com; s=arc-20160816; b=p/zxv32NIq6G4lfOhu4ix7NMYzll7uLgoTgifiifdwY8/4i9zRuRIUvm2pG0KmCvl9 6jjY3wY9gAQRemUE41VFWJ6klb2NNGA8EYxsaYBxNvHzRGM6Gj5iR+wKwm8BWsp6X7fO N5nd4kr+scY4WgPqC0qvK6u+Bvxl7Wgd129YijGQn4Nk8OhSylY3a1ynZEz23wHJjJZX 1oXMdRnBAX54Zm2KicIkf8mKpSGmo+ir54jPnaYSGHCOyPD5z9q9FtoBB/+YF4AW95LR NkDZPLEbZO3J7/GyxTWeSaxVPbpANxfPizIhXDT0xyYDohaNXgb0q9VUuNYq3bSBwwx8 Ns/w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Qi5NJbrismetNR4VDnzqWtfOpjOiDr0LEcWi51muTR4=; b=u0PwyjC+siJcNOgvKfOGXd5T6gtlspy+Sa7TTI1DVom0/PRZ7soyPgJXQAQhWqEqmm BIF0LTgQMtbjf84TpVkxb5WFDLc8h9IueGpwPnS2WTkiSzb3RGRQWsYOsTY2fvMWqOPm Bp1mwV77UdL+KRP/PB7yNUVcdQD3wNaVVi2IWY46QRf8dR9ttZ0x6+jbaHGlRMSC/NFf 5sViYu88o2cGfaKMj9aikDbj52rMNOTHdIYxLfwY5mqWvXqe61aWdmg4P1HRSSO+i7vr kLhM0VcfFBOlnOPTqtGqjxfLvNxEcdg3Rsa8CK//HDxTIEbDyt2SmmqtsL4WlPC1yZwe FEjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Riju3GbA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k13-20020aa79d0d000000b005a91f5ed6b2si12526447pfp.147.2023.03.08.07.41.00; Wed, 08 Mar 2023 07:41:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Riju3GbA; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232155AbjCHPc0 (ORCPT + 99 others); Wed, 8 Mar 2023 10:32:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231816AbjCHPcU (ORCPT ); Wed, 8 Mar 2023 10:32:20 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FB03D5A68; Wed, 8 Mar 2023 07:32:11 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 505FDFF816; Wed, 8 Mar 2023 15:32:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289530; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qi5NJbrismetNR4VDnzqWtfOpjOiDr0LEcWi51muTR4=; b=Riju3GbA5tXdErg/6M2b21kX9z8p23mbQF+XZ8vMJMFDtxac8NmHofRTkAyRm16KCnElFH paRLZ6veJY2ZcijqgBW8k3nl0T6PlF2ZTmwFraJ7BQwrX3Vt0ADPeso4vgy9ELYhaU9zgB YzXmZ9v0qF8Q4h84Re8OkhUIy4dXSTlrZ/Cy4b9Qpumsyrp5lvbnE9CjiwHfRTyrw9wpcD TYQOeAIyl1M3RXgmuODOSEAT8Qk9NDaiTHMddV8Yel0ekm6YC/Y/JkRjMDOR4x8gKaWjxa jvHs+VhlQtK0/WsfCggDp2JW4P1bZBDSZ88JM5N+t1Np3DIV+r3ZaETRsaMnGg== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal , "Rafael J . Wysocki" , Len Brown , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , Sebastian Reichel , Wolfram Sang , Mark Brown , Rob Herring Subject: [PATCH v3 03/20] of: Rename of_modalias_node() Date: Wed, 8 Mar 2023 16:31:43 +0100 Message-Id: <20230308153200.682248-4-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814693110343175?= X-GMAIL-MSGID: =?utf-8?q?1759814693110343175?= This helper does not produce a real modalias, but tries to get the "product" compatible part of the "vendor,product" compatibles only. It is far from creating a purely useful modalias string and does not seem to be used like that directly anyway, so let's try to give this helper a more meaningful name before moving there a real modalias helper (already existing under of/device.c). Also update the various documentations to refer to the strings as "aliases" rather than "modaliases" which has a real meaning in the Linux kernel. There is no functional change. Cc: Rafael J. Wysocki Cc: Len Brown Cc: Maarten Lankhorst Cc: Maxime Ripard Cc: Thomas Zimmermann Cc: Sebastian Reichel Cc: Wolfram Sang Cc: Mark Brown Signed-off-by: Miquel Raynal Reviewed-by: Rob Herring Acked-by: Mark Brown --- drivers/acpi/bus.c | 7 ++++--- drivers/gpu/drm/drm_mipi_dsi.c | 2 +- drivers/hsi/hsi_core.c | 2 +- drivers/i2c/busses/i2c-powermac.c | 2 +- drivers/i2c/i2c-core-of.c | 2 +- drivers/of/base.c | 18 +++++++++++------- drivers/spi/spi.c | 4 ++-- include/linux/of.h | 3 ++- 8 files changed, 23 insertions(+), 17 deletions(-) diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c index 9531dd0fef50..fc74c786a867 100644 --- a/drivers/acpi/bus.c +++ b/drivers/acpi/bus.c @@ -817,9 +817,10 @@ static bool acpi_of_modalias(struct acpi_device *adev, * @modalias: Pointer to buffer that modalias value will be copied into * @len: Length of modalias buffer * - * This is a counterpart of of_modalias_node() for struct acpi_device objects. - * If there is a compatible string for @adev, it will be copied to @modalias - * with the vendor prefix stripped; otherwise, @default_id will be used. + * This is a counterpart of of_alias_from_compatible() for struct acpi_device + * objects. If there is a compatible string for @adev, it will be copied to + * @modalias with the vendor prefix stripped; otherwise, @default_id will be + * used. */ void acpi_set_modalias(struct acpi_device *adev, const char *default_id, char *modalias, size_t len) diff --git a/drivers/gpu/drm/drm_mipi_dsi.c b/drivers/gpu/drm/drm_mipi_dsi.c index b41aaf2bb9f1..b62f5e4425f4 100644 --- a/drivers/gpu/drm/drm_mipi_dsi.c +++ b/drivers/gpu/drm/drm_mipi_dsi.c @@ -160,7 +160,7 @@ of_mipi_dsi_device_add(struct mipi_dsi_host *host, struct device_node *node) int ret; u32 reg; - if (of_modalias_node(node, info.type, sizeof(info.type)) < 0) { + if (of_alias_from_compatible(node, info.type, sizeof(info.type)) < 0) { drm_err(host, "modalias failure on %pOF\n", node); return ERR_PTR(-EINVAL); } diff --git a/drivers/hsi/hsi_core.c b/drivers/hsi/hsi_core.c index 8fda8f1d064d..acbf82f755a8 100644 --- a/drivers/hsi/hsi_core.c +++ b/drivers/hsi/hsi_core.c @@ -207,7 +207,7 @@ static void hsi_add_client_from_dt(struct hsi_port *port, if (!cl) return; - err = of_modalias_node(client, name, sizeof(name)); + err = of_alias_from_compatible(client, name, sizeof(name)); if (err) goto err; diff --git a/drivers/i2c/busses/i2c-powermac.c b/drivers/i2c/busses/i2c-powermac.c index 2e74747eec9c..ec706a3aba26 100644 --- a/drivers/i2c/busses/i2c-powermac.c +++ b/drivers/i2c/busses/i2c-powermac.c @@ -284,7 +284,7 @@ static bool i2c_powermac_get_type(struct i2c_adapter *adap, */ /* First try proper modalias */ - if (of_modalias_node(node, tmp, sizeof(tmp)) >= 0) { + if (of_alias_from_compatible(node, tmp, sizeof(tmp)) >= 0) { snprintf(type, type_size, "MAC,%s", tmp); return true; } diff --git a/drivers/i2c/i2c-core-of.c b/drivers/i2c/i2c-core-of.c index bce6b796e04c..8941a30574e3 100644 --- a/drivers/i2c/i2c-core-of.c +++ b/drivers/i2c/i2c-core-of.c @@ -27,7 +27,7 @@ int of_i2c_get_board_info(struct device *dev, struct device_node *node, memset(info, 0, sizeof(*info)); - if (of_modalias_node(node, info->type, sizeof(info->type)) < 0) { + if (of_alias_from_compatible(node, info->type, sizeof(info->type)) < 0) { dev_err(dev, "of_i2c: modalias failure on %pOF\n", node); return -EINVAL; } diff --git a/drivers/of/base.c b/drivers/of/base.c index ac6fde53342f..3c1badab287f 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c @@ -1208,19 +1208,23 @@ struct device_node *of_find_matching_node_and_match(struct device_node *from, EXPORT_SYMBOL(of_find_matching_node_and_match); /** - * of_modalias_node - Lookup appropriate modalias for a device node + * of_alias_from_compatible - Lookup appropriate alias for a device node + * depending on compatible * @node: pointer to a device tree node - * @modalias: Pointer to buffer that modalias value will be copied into - * @len: Length of modalias value + * @modalias: Pointer to buffer that alias value will be copied into + * @len: Length of alias value * * Based on the value of the compatible property, this routine will attempt - * to choose an appropriate modalias value for a particular device tree node. + * to choose an appropriate alias value for a particular device tree node. * It does this by stripping the manufacturer prefix (as delimited by a ',') * from the first entry in the compatible list property. * + * Note: The matching on just the "product" side of the compatible is a relic + * from I2C and SPI. Please do not add any new user. + * * Return: This routine returns 0 on success, <0 on failure. */ -int of_modalias_node(struct device_node *node, char *modalias, int len) +int of_alias_from_compatible(const struct device_node *node, char *alias, int len) { const char *compatible, *p; int cplen; @@ -1229,10 +1233,10 @@ int of_modalias_node(struct device_node *node, char *modalias, int len) if (!compatible || strlen(compatible) > cplen) return -ENODEV; p = strchr(compatible, ','); - strscpy(modalias, p ? p + 1 : compatible, len); + strscpy(alias, p ? p + 1 : compatible, len); return 0; } -EXPORT_SYMBOL_GPL(of_modalias_node); +EXPORT_SYMBOL_GPL(of_alias_from_compatible); /** * of_find_node_by_phandle - Find a node given a phandle diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 44b85a8d47f1..3bbdc5fe3b99 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2354,8 +2354,8 @@ of_register_spi_device(struct spi_controller *ctlr, struct device_node *nc) } /* Select device driver */ - rc = of_modalias_node(nc, spi->modalias, - sizeof(spi->modalias)); + rc = of_alias_from_compatible(nc, spi->modalias, + sizeof(spi->modalias)); if (rc < 0) { dev_err(&ctlr->dev, "cannot find modalias for %pOF\n", nc); goto err_out; diff --git a/include/linux/of.h b/include/linux/of.h index 0af611307db2..b1eea8569043 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -373,7 +373,8 @@ extern int of_n_addr_cells(struct device_node *np); extern int of_n_size_cells(struct device_node *np); extern const struct of_device_id *of_match_node( const struct of_device_id *matches, const struct device_node *node); -extern int of_modalias_node(struct device_node *node, char *modalias, int len); +extern int of_alias_from_compatible(const struct device_node *node, char *alias, + int len); extern void of_print_phandle_args(const char *msg, const struct of_phandle_args *args); extern int __of_parse_phandle_with_args(const struct device_node *np, const char *list_name, const char *cells_name, int cell_count, From patchwork Wed Mar 8 15:31:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66295 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp403536wrd; Wed, 8 Mar 2023 07:34:45 -0800 (PST) X-Google-Smtp-Source: AK7set8craJIAcNkPTBefGFme4+uTcKHnx6iYGbiMRw5kYf3KMmHsH/Fl+1FDFkTT9UoWMS6XOGj X-Received: by 2002:a17:90b:4d07:b0:23a:87cf:de93 with SMTP id mw7-20020a17090b4d0700b0023a87cfde93mr17332094pjb.15.1678289685551; Wed, 08 Mar 2023 07:34:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678289685; cv=none; d=google.com; s=arc-20160816; b=gaqVUixrOshnIa1clEJNlwLrwDsbOY4P+mp+/5F5/HSZUUUOHKYM/ey8AYBfxqryCJ PRDQjlQnyLXJJ92RetdWIxsCdHN6b9PxShTsgGWcysdtgo6dUR2cj72MiHAUT04RN39G S61E+vvMuuFA2Aj1Wiu/AlEaXq4rAj0mu0NXyrJaJ9HuOlE7yahd+2yamvlJT7bmlN/F Rr9aWkEDuONG5PV481cLYkgufOk9cE1aRdqL6fc5FHMLhiXkighvO3r4aOimBMhqfRB4 uY9u7HF6yXCqFwTm8eNzw6dT62MewT139bn9CkuC48+27pwjEN0Ssn96J0JG/jZ517bT 0Drg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=cCRvTyHEH13tgqdLoox49Vvo8WKTA3FYHLaY4F7HdhE=; b=DNyzsMHr2LIRPDep/W4l7Xe7LkjdJ59aD5767c8WoyCdRqNCPS6s2SAeeLZusvgwxL sX2LUMb22tolCRWAuyrYBw8jCizrl8OMhtSf+/Y03T6uMrnQWmGF6fSz8KF8jQtbcoiW 9j6qan9tbulvzQN5JRBvSSPqyBfIiojt0mutqlWyPjuTWroIb6bNeAoBLY5wqvesSxkJ FvKGpINzOS1DuLqcSMSensHnInf2K94iDe0Dg8ofLYX8elXaBw4kv09ZDcCW6+j/oj4Q h4Kso2lYxVKyYxuERdPM6lasfW5F7cK/jKux3CvgzoBkRDly19lHfuAfEoQkhVnTyY4i /F8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=db9WcWXP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u189-20020a6385c6000000b004fc29a7445bsi14489324pgd.761.2023.03.08.07.34.30; Wed, 08 Mar 2023 07:34:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=db9WcWXP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232217AbjCHPc3 (ORCPT + 99 others); Wed, 8 Mar 2023 10:32:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232147AbjCHPcV (ORCPT ); Wed, 8 Mar 2023 10:32:21 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 456E7D161E; Wed, 8 Mar 2023 07:32:13 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 84E10FF80B; Wed, 8 Mar 2023 15:32:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289531; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cCRvTyHEH13tgqdLoox49Vvo8WKTA3FYHLaY4F7HdhE=; b=db9WcWXPG0BqmKl4wuY1F5Z4kjpiVeo3v8YcfPKwV9zeS6VC2K52hrg0T+nUulYqH+77iy yjtQwYmv1i12pvRf/C80rCLGqVCMaYu6HuRYledmMuyHiiNgkGvLCSeB/2BNOmxh+AGPRm JL3P6OdYxV0zHw85EWfPPQw0NELCxioFZEj8zb7amuGKHlZeFDNlndHxKUYYMx6t1YIHIg 83sqoPPspNsvhRBn4a3ZDeL8hWzgg/mAG0LgY/UoGD5Ip8WCRAMIpy4HBc2Sj04LCRBgNk M4Ama5kdLViEPzSK0MzYCDWhJdgHvh09A5pvGksgraPv++7QbbotmdqqwNAymA== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v3 04/20] of: Move of_modalias() to module.c Date: Wed, 8 Mar 2023 16:31:44 +0100 Message-Id: <20230308153200.682248-5-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814285719425081?= X-GMAIL-MSGID: =?utf-8?q?1759814285719425081?= Create a specific .c file for OF related module handling. Move of_modalias() inside as a first step. The helper is exposed through of.h even though it is only used by core files because the users from device.c will soon be split into an OF-only helper in module.c as well as a device-oriented inline helper in of_device.h. Putting this helper in of_private.h would require to include of_private.h from of_device.h, which is not acceptable. Suggested-by: Rob Herring Signed-off-by: Miquel Raynal Reviewed-by: Rob Herring --- drivers/of/Makefile | 2 +- drivers/of/device.c | 37 ------------------------------------- drivers/of/module.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 9 +++++++++ 4 files changed, 54 insertions(+), 38 deletions(-) create mode 100644 drivers/of/module.c diff --git a/drivers/of/Makefile b/drivers/of/Makefile index e0360a44306e..ae9923fd2940 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -1,5 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 -obj-y = base.o device.o platform.o property.o +obj-y = base.o device.o module.o platform.o property.o obj-$(CONFIG_OF_KOBJ) += kobj.o obj-$(CONFIG_OF_DYNAMIC) += dynamic.o obj-$(CONFIG_OF_FLATTREE) += fdt.o diff --git a/drivers/of/device.c b/drivers/of/device.c index 351c505ecb50..7183cfd754db 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -1,5 +1,4 @@ // SPDX-License-Identifier: GPL-2.0 -#include #include #include #include @@ -248,42 +247,6 @@ const void *of_device_get_match_data(const struct device *dev) } EXPORT_SYMBOL(of_device_get_match_data); -static ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len) -{ - const char *compat; - char *c; - struct property *p; - ssize_t csize; - ssize_t tsize; - - /* Name & Type */ - /* %p eats all alphanum characters, so %c must be used here */ - csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T', - of_node_get_device_type(np)); - tsize = csize; - len -= csize; - if (str) - str += csize; - - of_property_for_each_string(np, "compatible", p, compat) { - csize = strlen(compat) + 1; - tsize += csize; - if (csize > len) - continue; - - csize = snprintf(str, len, "C%s", compat); - for (c = str; c; ) { - c = strchr(c, ' '); - if (c) - *c++ = '_'; - } - len -= csize; - str += csize; - } - - return tsize; -} - int of_device_request_module(struct device *dev) { char *str; diff --git a/drivers/of/module.c b/drivers/of/module.c new file mode 100644 index 000000000000..4c59752bc8d6 --- /dev/null +++ b/drivers/of/module.c @@ -0,0 +1,44 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Linux kernel module helpers. + */ + +#include +#include +#include + +ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len) +{ + const char *compat; + char *c; + struct property *p; + ssize_t csize; + ssize_t tsize; + + /* Name & Type */ + /* %p eats all alphanum characters, so %c must be used here */ + csize = snprintf(str, len, "of:N%pOFn%c%s", np, 'T', + of_node_get_device_type(np)); + tsize = csize; + len -= csize; + if (str) + str += csize; + + of_property_for_each_string(np, "compatible", p, compat) { + csize = strlen(compat) + 1; + tsize += csize; + if (csize > len) + continue; + + csize = snprintf(str, len, "C%s", compat); + for (c = str; c; ) { + c = strchr(c, ' '); + if (c) + *c++ = '_'; + } + len -= csize; + str += csize; + } + + return tsize; +} diff --git a/include/linux/of.h b/include/linux/of.h index b1eea8569043..be26c7e8ef9e 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -385,6 +385,9 @@ extern int of_parse_phandle_with_args_map(const struct device_node *np, extern int of_count_phandle_with_args(const struct device_node *np, const char *list_name, const char *cells_name); +/* module functions */ +extern ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len); + /* phandle iterator functions */ extern int of_phandle_iterator_init(struct of_phandle_iterator *it, const struct device_node *np, @@ -742,6 +745,12 @@ static inline int of_count_phandle_with_args(const struct device_node *np, return -ENOSYS; } +static inline ssize_t of_modalias(const struct device_node *np, char *str, + ssize_t len) +{ + return -ENODEV; +} + static inline int of_phandle_iterator_init(struct of_phandle_iterator *it, const struct device_node *np, const char *list_name, From patchwork Wed Mar 8 15:31:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66304 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp405522wrd; Wed, 8 Mar 2023 07:38:29 -0800 (PST) X-Google-Smtp-Source: AK7set9ria+9Ao6P7kr6hX+Vh66yPvyM8Kp9tSrjTdAst+DdtlQDuGLsY2P9pP+PMMpc59iPNhad X-Received: by 2002:a17:902:e746:b0:19e:6bc5:8769 with SMTP id p6-20020a170902e74600b0019e6bc58769mr24730943plf.69.1678289908827; Wed, 08 Mar 2023 07:38:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678289908; cv=none; d=google.com; s=arc-20160816; b=mlfgwxW1hlvEwQYC0mu+atpMwOKv68RD/Ov3YGPehLZS6sENbI7yICZHG5/hUfnksH DhAughL/PIp5n/t+cVnzfTZdH759TuGWORYjtK65Q6RORvXN9TKY4xs08Dn9NZ02v9ZC LotUJNACfTGvHNBpCQ9Do20idUArdNPfdjyajbWgYfNbCtaUnQiaqbJEe3UZ3UREzc// W/H+ux7fuD6VhyZMt6/IX7DRZE6bI/hXk54BIFTRSp6M+YhB/4HXk1TJt5iH1ErOGi56 PcYSIQhcNCbk3LcXG/FNGsghnIzhcl7iS+bGjD32SX8+ZsUMLsw45XwiXhgjxjf9GBGG Vqbg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qSIaLowzQOIsdvJKYrUeSvZLlLef3hpg/zogwF151qc=; b=PNFFwCKpwLEPKb+UkAK4QSWM5TS/SDgUar9oVrghYHVt/TuHqeFfteB4t501xSb8Dc jHXqQQfehyRk42DHMSONjlhu5m0w7JAJicxvdjjFc1FTfV3jqFfABjvL9TpndRIXnQBb B2a05jeB/VTK2O9zz7vo+3FBnbr7xvX7wtgBhvST1C2hzqyEuptSc/0SWiVe7qEcA7Hr IH6qiXCMpOSr8m7cHRRplJkxmYNZyUE+9wFWIX3DhMmMB0+yLgUnBe2gIs1ZdJBMUNVa SrpbSLlJngUxh+vDJavxWf6CWAeOjltbGh+x9ywJtUKgePOUGyOovA0qhlVYwTlO0Bpk /I+A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=jjiE7Y9m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v1-20020a170902b7c100b001930212bebfsi4878730plz.530.2023.03.08.07.38.15; Wed, 08 Mar 2023 07:38:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=jjiE7Y9m; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232223AbjCHPcg (ORCPT + 99 others); Wed, 8 Mar 2023 10:32:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232065AbjCHPcW (ORCPT ); Wed, 8 Mar 2023 10:32:22 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2243D6E90; Wed, 8 Mar 2023 07:32:14 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 0F9CEFF811; Wed, 8 Mar 2023 15:32:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289533; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qSIaLowzQOIsdvJKYrUeSvZLlLef3hpg/zogwF151qc=; b=jjiE7Y9mibAmaq9V923vzVBEc+jLOeK2Tq4IM56MhMTpU+O1HQbiNMAqIwySROQPValvvm +6yf07XU5n9z/JcLm2qUGbIMV+qtC7Y9xI29SCaZdK9s7Tt9eqY3c/qgSFIr39FAMtIkwT ldRUp786l0VI0Hj77w7eDGCCeq7NJJW9ZiGg0tzATXv8lBftQldzULD92fMF/4vzp7BbrC Jr2jSkabfdYmujBQSwn5ISurJfBb6Rx/+vN88OOCMDw5c/99NWkRxJ7sn8OMeZlps1NixO DytCnuTMVk6Z+DO676KxbrLZnqg2B6XTaUUcDDzmCvvJonveOC7e15vKfPrAVg== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal , Rob Herring Subject: [PATCH v3 05/20] of: Move the request module helper logic to module.c Date: Wed, 8 Mar 2023 16:31:45 +0100 Message-Id: <20230308153200.682248-6-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814519432957021?= X-GMAIL-MSGID: =?utf-8?q?1759814519432957021?= Depending on device.c for pure OF handling is considered backwards. Let's extract the content of of_device_request_module() to have the real logic under module.c. The next step will be to convert users of of_device_request_module() to use the new helper. Signed-off-by: Miquel Raynal Reviewed-by: Rob Herring --- drivers/of/device.c | 25 ++----------------------- drivers/of/module.c | 30 ++++++++++++++++++++++++++++++ include/linux/of.h | 6 ++++++ 3 files changed, 38 insertions(+), 23 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 7183cfd754db..874a2e1f6308 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -8,7 +8,6 @@ #include /* for bus_dma_region */ #include #include -#include #include #include #include @@ -249,30 +248,10 @@ EXPORT_SYMBOL(of_device_get_match_data); int of_device_request_module(struct device *dev) { - char *str; - ssize_t size; - int ret; - - if (!dev || !dev->of_node) + if (!dev) return -ENODEV; - size = of_modalias(dev->of_node, NULL, 0); - if (size < 0) - return size; - - /* Reserve an additional byte for the trailing '\0' */ - size++; - - str = kmalloc(size, GFP_KERNEL); - if (!str) - return -ENOMEM; - - of_modalias(dev->of_node, str, size); - str[size - 1] = '\0'; - ret = request_module(str); - kfree(str); - - return ret; + return of_request_module(dev->of_node); } EXPORT_SYMBOL_GPL(of_device_request_module); diff --git a/drivers/of/module.c b/drivers/of/module.c index 4c59752bc8d6..0e8aa974f0f2 100644 --- a/drivers/of/module.c +++ b/drivers/of/module.c @@ -4,6 +4,7 @@ */ #include +#include #include #include @@ -42,3 +43,32 @@ ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len) return tsize; } + +int of_request_module(const struct device_node *np) +{ + char *str; + ssize_t size; + int ret; + + if (!np) + return -ENODEV; + + size = of_modalias(np, NULL, 0); + if (size < 0) + return size; + + /* Reserve an additional byte for the trailing '\0' */ + size++; + + str = kmalloc(size, GFP_KERNEL); + if (!str) + return -ENOMEM; + + of_modalias(np, str, size); + str[size - 1] = '\0'; + ret = request_module(str); + kfree(str); + + return ret; +} +EXPORT_SYMBOL_GPL(of_request_module); diff --git a/include/linux/of.h b/include/linux/of.h index be26c7e8ef9e..9b7a99499ef3 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -387,6 +387,7 @@ extern int of_count_phandle_with_args(const struct device_node *np, /* module functions */ extern ssize_t of_modalias(const struct device_node *np, char *str, ssize_t len); +extern int of_request_module(const struct device_node *np); /* phandle iterator functions */ extern int of_phandle_iterator_init(struct of_phandle_iterator *it, @@ -751,6 +752,11 @@ static inline ssize_t of_modalias(const struct device_node *np, char *str, return -ENODEV; } +static inline int of_request_module(const struct device_node *np) +{ + return -ENODEV; +} + static inline int of_phandle_iterator_init(struct of_phandle_iterator *it, const struct device_node *np, const char *list_name, From patchwork Wed Mar 8 15:31:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66306 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp405920wrd; Wed, 8 Mar 2023 07:39:20 -0800 (PST) X-Google-Smtp-Source: AK7set8ST7sEW48SwRMPdAowT4uXMaXkbXdJGflfyEPr7dzb9iuLciLCHq9vvB/WK6vvUm+Gb+GJ X-Received: by 2002:a17:902:c103:b0:19e:7611:7162 with SMTP id 3-20020a170902c10300b0019e76117162mr16119483pli.16.1678289960680; Wed, 08 Mar 2023 07:39:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678289960; cv=none; d=google.com; s=arc-20160816; b=cV8KJwAAu25D4trcOVBeGzgZymwPmTz0Y1DzAdsrHdTvlJ/942EjItDcz79L4KvK4G H9z7p8w4EOtWEltk276kKMS2onnSFeFJoqG4fpNWOaqKps8xk0F1ZXUCNpuq5Hm6DxvJ l86UVL3KKolvP54kdSKoxtk33AWoD4w7Q5Lumsf4K8qxe5FIYZ4fvfMJ/SnagKVMZH4d gLPybfnKeGI64YpfYd7W7FsE99y9ze43E5A5uSdylyvUTgksJiepnIQ10h9/gsRWnc3U 8/n9qcWzooAhdQw5wZOl7JnC04o0EcbGG+y+mdPIokNgFCwflGTcnPqsGItBapQhrp0y 7Y2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6Y6+DcGF5JnGzoC8RTbBsZslgXp5YAzj2GBjOQi6pCc=; b=tTTyDKdCiEG/kgVF7vaTCMUJLUzESk+JhC+6rfn+3XSI3fxPHjonntgrbovIlrCxWN Z8wBCd5sPPazTTWh8HbR0lRTgOvJwMQf87QSyjl0OBy0B0ANLYbcqXkiYh+9fpAKvsaF Ctor/AnFEknTA2x6m/LXNXBfp3jtK5uxCqhCnpHQRIcDmVZUiroqkCG/gsUivb5S7r4s 2upImHNUBo8g4/3es/wwKSXrokUGY68r9ss9E6nrTsTuqAvJ8vtePmFbxXGg6ppIglS7 6nn7x/nYbQYdYjwh8Q6kZfD+WcYkR6vxBExF8cQzQ0j0kPyIAOZBr2hGHb/WvoLnkegi mF7w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=RXY03Pkj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o9-20020a170902d4c900b0019e9c8e51f4si15143832plg.165.2023.03.08.07.39.01; Wed, 08 Mar 2023 07:39:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=RXY03Pkj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232236AbjCHPcl (ORCPT + 99 others); Wed, 8 Mar 2023 10:32:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232180AbjCHPcX (ORCPT ); Wed, 8 Mar 2023 10:32:23 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 46E34D6EB5; Wed, 8 Mar 2023 07:32:17 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 80F5CFF813; Wed, 8 Mar 2023 15:32:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289535; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=6Y6+DcGF5JnGzoC8RTbBsZslgXp5YAzj2GBjOQi6pCc=; b=RXY03PkjeFHM2NDqV9I7fCm31fYfj/3+bXxGfa/4clZ/wfHidpfI/nwBN2YWx+ylk6/zXA PDgL+4a1PI/kG2LVNBlVgft/lKsloZGijKFh8pceDwKduQC/pd0kiGqrr+v5WLamrtG4+s 5OYlbM2RS/4m0QFxsOxUkR9swEVIK9myFDD28XRKAU0nP7tRv9w8JxPNPVp553eDO31vHl 1YwkOClnbqPdDK45y08YnTMoWRVmKKh6S8XwfIDHW1lk8KvFkcOHwthFmn4yzJ0WBwbDup GWF510OhB9Sxpae2q8u8cjgPZ1l0vZqprZsXyaQ74MhNwGUMndmiYIHd5Qf8hw== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal , Heikki Krogerus , Rob Herring Subject: [PATCH v3 06/20] usb: ulpi: Use of_request_module() Date: Wed, 8 Mar 2023 16:31:46 +0100 Message-Id: <20230308153200.682248-7-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814574012260761?= X-GMAIL-MSGID: =?utf-8?q?1759814574012260761?= There is a new helper supposed to replace of_device_request_module(), called of_request_module(). They are both strictly equivalent, besides the fact the latter receives a "struct device_node" directly. Use it. Cc: Heikki Krogerus Cc: Greg Kroah-Hartman Signed-off-by: Miquel Raynal Acked-by: Rob Herring Acked-by: Heikki Krogerus --- drivers/usb/common/ulpi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/usb/common/ulpi.c b/drivers/usb/common/ulpi.c index a98b2108376a..6977cf380838 100644 --- a/drivers/usb/common/ulpi.c +++ b/drivers/usb/common/ulpi.c @@ -229,7 +229,7 @@ static int ulpi_read_id(struct ulpi *ulpi) request_module("ulpi:v%04xp%04x", ulpi->id.vendor, ulpi->id.product); return 0; err: - of_device_request_module(&ulpi->dev); + of_request_module(ulpi->dev.of_node); return 0; } From patchwork Wed Mar 8 15:31:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66296 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp403547wrd; Wed, 8 Mar 2023 07:34:47 -0800 (PST) X-Google-Smtp-Source: AK7set+1muxyOOz9GG8UccxtyOXt3QdPRfWUoJsQm6SoUg+N+4FhG6eZRFpLg/HEe//jgwbsQ797 X-Received: by 2002:a17:902:da8d:b0:19e:9812:ad11 with SMTP id j13-20020a170902da8d00b0019e9812ad11mr18062570plx.23.1678289687363; Wed, 08 Mar 2023 07:34:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678289687; cv=none; d=google.com; s=arc-20160816; b=ww+61YVEUWcb3yvM38+zE3UbPlYtQIr99QwC9AEXCJGPTMkwZSDJ+dqMjLVCXPNdLZ viWtTdeNkCVfpujZNQKcNOuJ5+DwPCORcIABm7RwHF4Bnj551Cf0CGCTcHr+dCL7UQQH NBiMIxFGO+q9loFNgV01WD0DZh7u7pLU98OaxhuwAOWTgMDFc5gHYoiJ2BScdVITvGFR /oRycJYedu4ulBf/93+kRzZGIYieFcF9GkI0l0AiQLKIOTPjlEAveO2MyJK4umYFAKMJ wV/nfGNdK95dWw1mUO4nsBwmMmLPxacyLm52hXKzgNyG5lXJJU1AVuZ3yTrCh+8TAUK6 KkdQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+Fa7z9mAzOMi6AkU7brGc+2TjyQ76RAJaVPkouit7mo=; b=t0TA9GIaX+Numv9+iwiGzEVh3kKlS6/n73jAEPnzD68+e2cVTJEni/uaF5qjQuDEP2 WXS4EB/rDrbObxvOxBs6mGE2ulQGEIsUn9gOFSWq5rMoQWgNB9NRDs3mRpNX19UvWa0N Z9TNBuqjqgzrIJ89TXPJU6V+0m5av1zh1j6ww6dxUAyDEuoSorl9l/Ub7sstR7R/pnPw opZBooJclml++wBGxEVapuWjfhBFuFDsVNkFF421aXY62H3aZDNd6z228q7uU/Oz7rAs ccp1q7Ye6AOXWKzSciqQuvNRPkD0jNXn7Lpv29JAmDJg+j3xL03Do92eK+dSGclZjEmc 6Evw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="P/UTtYGy"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id iw4-20020a170903044400b0019a70c85427si14222803plb.275.2023.03.08.07.34.31; Wed, 08 Mar 2023 07:34:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b="P/UTtYGy"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230332AbjCHPcx (ORCPT + 99 others); Wed, 8 Mar 2023 10:32:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232198AbjCHPcZ (ORCPT ); Wed, 8 Mar 2023 10:32:25 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0242FD90C3; Wed, 8 Mar 2023 07:32:18 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 0361FFF807; Wed, 8 Mar 2023 15:32:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289537; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+Fa7z9mAzOMi6AkU7brGc+2TjyQ76RAJaVPkouit7mo=; b=P/UTtYGyVisjLPnxSNWkC+juOYc1uO12Iz/PRd8UahgGDTmZs7aX0/5GtH3tECGJq52XN5 EkamMgQcFrMmEeIbwRiAY/HNktUOduyGl+E5ULbpAReCdxKni8LXR/+/bqUQfYrzZxCoCN Z43Jx66ttDQIpSqYl+CRwbhR7kGmimm/QP4/AUaCnfgHfTzzIG+F7+OxzsmE6ZZ/sXqMv7 mX3TjttNr34EF9n+USydV6B8d8Q5zzxXg70R9bIy7YdVysHuOLPCoyrA5mkbnz9dX58cGG yA4QU7FDePP6vDQK2Wxpj/E02L7xseUPAE+qTmrI+aMEYjV2VkgYsSRuKCJGPQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal , Rob Herring Subject: [PATCH v3 07/20] of: device: Kill of_device_request_module() Date: Wed, 8 Mar 2023 16:31:47 +0100 Message-Id: <20230308153200.682248-8-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814287371590845?= X-GMAIL-MSGID: =?utf-8?q?1759814287371590845?= A new helper has been introduced, of_request_module(). Users have been converted, this helper can now be deleted. Signed-off-by: Miquel Raynal Reviewed-by: Rob Herring --- drivers/of/device.c | 9 --------- include/linux/of_device.h | 6 ------ 2 files changed, 15 deletions(-) diff --git a/drivers/of/device.c b/drivers/of/device.c index 874a2e1f6308..0f00f1b80708 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -246,15 +246,6 @@ const void *of_device_get_match_data(const struct device *dev) } EXPORT_SYMBOL(of_device_get_match_data); -int of_device_request_module(struct device *dev) -{ - if (!dev) - return -ENODEV; - - return of_request_module(dev->of_node); -} -EXPORT_SYMBOL_GPL(of_device_request_module); - /** * of_device_modalias - Fill buffer with newline terminated modalias string * @dev: Calling device diff --git a/include/linux/of_device.h b/include/linux/of_device.h index f4b57614979d..ce20d8b00b3e 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -33,7 +33,6 @@ extern void of_device_unregister(struct platform_device *ofdev); extern const void *of_device_get_match_data(const struct device *dev); extern ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len); -extern int of_device_request_module(struct device *dev); extern void of_device_uevent(const struct device *dev, struct kobj_uevent_env *env); extern int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env *env); @@ -78,11 +77,6 @@ static inline int of_device_modalias(struct device *dev, return -ENODEV; } -static inline int of_device_request_module(struct device *dev) -{ - return -ENODEV; -} - static inline int of_device_uevent_modalias(const struct device *dev, struct kobj_uevent_env *env) { From patchwork Wed Mar 8 15:31:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66305 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp405568wrd; Wed, 8 Mar 2023 07:38:34 -0800 (PST) X-Google-Smtp-Source: AK7set/wcKPLtIWl8PkQoQ4LvDvjN7A/Qd67GZ8YXcQyZlALHrU8gGOQXbedRsmooizNTkyIbfvZ X-Received: by 2002:a17:90b:3907:b0:234:b964:5703 with SMTP id ob7-20020a17090b390700b00234b9645703mr19721119pjb.18.1678289914121; Wed, 08 Mar 2023 07:38:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678289914; cv=none; d=google.com; s=arc-20160816; b=P/UO32HEWbWmsKvBeaAtiu3qSXqsVSQZrSvsXA1u+8k+w/78y0xcGHzj8hjIvv8Dpf NeDsZSYpzD8oOffF0iTddqiSwQZ/VUfxowYxf+oDcyEwOwTrIAjmAtprAVy7ZZUaUmgu m0CN9Rl8hdzoZo7Y5nBRMInj9Ybms+DufMxIjjpfv1j/09e+phyacU+1/pskDQfBhqVY +lNoLogmpPwQjN5kSCYpN6IFTslmy7YRRdpp2pEn9UIwEIKUPT5UQm1gxNxZioP30Dr3 LV4LY+Jrk4yhj+fpgeHVJOA2gm4kao7BdO2XlwpXwH47hGNZitVnDa3JkGbO6682YJAT Q4lg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kNiQMRKKx1J0SGYw53QECnkbm/nX4KdsySOgD3rc51A=; b=ZNoWx+/0JqtAKuaeFGRA2behlSF/BWAr3gfJGtTyNsByY5I4Jz5KVeC4fBvZ90L+9p 8HJql9wztFvaXzhaV9jUR1+6HM3+b9d6CNlZKZHfX4nYuZSuk2IltyKYKJA2HWb1AQky PyMdzU4Y1HrWY3+xnjQFjvX/CROhXC7qKutpjbx+h46eagoaEQruAddw8gkM8OWkzPFQ lZEqIvQmUwc++gTMIdDeUeWE9k2H5OCbPcHv5rUs4xZ/dR9S0y6ylAkO3Z5nR8ffalsK 4Zw9LCNgOiOTNT68Cks7f+6uu6dtxFBKMRTR3uLamwdpZFxkqgAL2goPzIcm+r38uNYI 8d5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ValhiiyM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p12-20020a631e4c000000b005030925d30asi14399362pgm.347.2023.03.08.07.38.20; Wed, 08 Mar 2023 07:38:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=ValhiiyM; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232220AbjCHPc5 (ORCPT + 99 others); Wed, 8 Mar 2023 10:32:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232208AbjCHPc1 (ORCPT ); Wed, 8 Mar 2023 10:32:27 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B609ADB6E6; Wed, 8 Mar 2023 07:32:20 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 88D64FF80F; Wed, 8 Mar 2023 15:32:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289539; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kNiQMRKKx1J0SGYw53QECnkbm/nX4KdsySOgD3rc51A=; b=ValhiiyM6SrLcoaOkM/zLc3zSvIrFPsSi3EARKIksMyS0+MUjkweSlzGiCM+ExWEznf+QP PspMCW7aXdpMsaUEOj0R5BHSRwlyb6Yfa9mQWbJJbCJIX/o+EAH9QshOvovWEE3aYem2nb wzwp1xPwquUnPXXAv97IUOp+ZsLVYT7ggvQb1NUXkEHyX8R7fXw2oVFe3pp9QrHZtlpN5+ MEgRtSZK0YB7fm/1Nvjvlmo5bOQgDRMH7hnrfcALLUe9ph1ErPt+6sXpTCYYHH7NquSTyQ iu68y8atPAAtonP0CvDcfv5EbrKG9DQ1OnGtI3JunJz2axuqhSESvS99osDrUA== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Colin Ian King , Miquel Raynal , Krzysztof Kozlowski Subject: [PATCH v3 08/20] dt-bindings: nvmem: Fix spelling mistake "platforn" -> "platform" Date: Wed, 8 Mar 2023 16:31:48 +0100 Message-Id: <20230308153200.682248-9-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814525226818411?= X-GMAIL-MSGID: =?utf-8?q?1759814525226818411?= From: Colin Ian King There is a spelling mistake in platforn-name. Fix it. Signed-off-by: Colin Ian King Signed-off-by: Miquel Raynal Acked-by: Krzysztof Kozlowski --- .../devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml b/Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml index 5a0e7671aa3f..714a6538cc7c 100644 --- a/Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml +++ b/Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml @@ -61,7 +61,7 @@ properties: type: object additionalProperties: false - platforn-name: + platform-name: type: object additionalProperties: false From patchwork Wed Mar 8 15:31:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66303 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp405482wrd; Wed, 8 Mar 2023 07:38:23 -0800 (PST) X-Google-Smtp-Source: AK7set/haUuNZKaNgYdjFNZVqPIOoo1mx2Rbat9x3L+iVzZ06Z6+q4jwwy8SKYqqTfuCpybKjD8j X-Received: by 2002:aa7:9607:0:b0:5e4:f700:f876 with SMTP id q7-20020aa79607000000b005e4f700f876mr16223656pfg.28.1678289903181; Wed, 08 Mar 2023 07:38:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678289903; cv=none; d=google.com; s=arc-20160816; b=tajbCfWeVizbtFsC9YcPyljzYDz4foKOTvE9uHrghYDXpTcdLcJcZD8ZBpS+cC+UhX yrbGQvpRKPS0DhsRx/Uk4Cp0fclcK9yPSULaI6JXNo6mCeg9loIj3jumcemNZ/bOuaWK 6VBgvlvdj9573pgzIGZfIkAjUCK9IRDM6+jURvdB9ybmKia6CGoTNa2PUhecGTTf3dbC 3XfY2Rg2z/7MzC/Nu5wvgTEBqMhbVoiSlVLFqqaeq5Y/S4qqw+tdfdPupWOH3o3pwwK5 yO0N1e6fdi/UOcH/TdjJB0MgvKa7zJtPh9pGN3jZXwqZXmWtyupCeDIggpjCmwosTcMD vKgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hVQeBtKQXrRO5C0cHH9lHvut6ra7Sd5DplTQYKV162c=; b=LJ57JBfnA5TXGwJdsjVqMezbcFC3hC+lyVJkMUpuo0Tr+XRtTseW42GXb6g6wH3pdI Zg8zBtfHVG5gaJDN3+UB5OanYwy+vbgMCJJQ+2H40n7F81XJY/xYrO9L0wHflTl0lXhq Q4SXbLBnprB6eIt9HKwZSY1pCeLb9Hea6RbsdmM3/2v2RwBJwlB+yzPr0XPM3Ou7yAy5 kMrE8F6AVEAy8bnKm9jMPiKYLMu+lSJ80S4BwY8kSecmx6XiVPUroU9FmLuyKVTxPwy7 ZHZo4uXF+RwDdGywZoisj79fbv+iaxJrilYj2Bjk7/ZrJgS6YTSVzaFq/q86x4UffiLd oGRQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=CJ3UYJyL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y64-20020a638a43000000b004fb97a4c536si15089579pgd.873.2023.03.08.07.38.10; Wed, 08 Mar 2023 07:38:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=CJ3UYJyL; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232180AbjCHPdG (ORCPT + 99 others); Wed, 8 Mar 2023 10:33:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232243AbjCHPcm (ORCPT ); Wed, 8 Mar 2023 10:32:42 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7C63D90F0; Wed, 8 Mar 2023 07:32:22 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 87582FF80A; Wed, 8 Mar 2023 15:32:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289541; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=hVQeBtKQXrRO5C0cHH9lHvut6ra7Sd5DplTQYKV162c=; b=CJ3UYJyLYmm0KU6XtYqxF7PriCiYflAhJs5uC4Fuopy/ydHc+fW9NO1gArYuw2VC0xxLSN OnRxFpDDvMC4zrglz/Mi47cIAEYX4DC2hXUEZSAuqk+bU1Lod+cYzrYsufXRnYZEDezMh+ uJrP1vxKs03ZPfMCM3mZkVQTLDh142kQPwNcM5eH1hXLp/cSuWR8aS+3PNnP5gac8003ld 7D7u1S6vH2bquDcQ1jFJFFVdRyFSTdUG2/kzvLR//iR3/8KIVOGq47mDT8Sc4ocQFQngHv XfPl49xgtqpvKVoYi4VasRLwFF2IOiG1wXYvtqVs54od1n8/BTCwdjOyWyUwCQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v3 09/20] nvmem: core: introduce NVMEM layouts Date: Wed, 8 Mar 2023 16:31:49 +0100 Message-Id: <20230308153200.682248-10-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814513900024163?= X-GMAIL-MSGID: =?utf-8?q?1759814513900024163?= From: Michael Walle NVMEM layouts are used to generate NVMEM cells during runtime. Think of an EEPROM with a well-defined conent. For now, the content can be described by a device tree or a board file. But this only works if the offsets and lengths are static and don't change. One could also argue that putting the layout of the EEPROM in the device tree is the wrong place. Instead, the device tree should just have a specific compatible string. Right now there are two use cases: (1) The NVMEM cell needs special processing. E.g. if it only specifies a base MAC address offset and you need to add an offset, or it needs to parse a MAC from ASCII format or some proprietary format. (Post processing of cells is added in a later commit). (2) u-boot environment parsing. The cells don't have a particular offset but it needs parsing the content to determine the offsets and length. Co-developed-by: Miquel Raynal Signed-off-by: Miquel Raynal Signed-off-by: Michael Walle --- Documentation/driver-api/nvmem.rst | 15 ++++ drivers/nvmem/Kconfig | 4 + drivers/nvmem/Makefile | 1 + drivers/nvmem/core.c | 120 +++++++++++++++++++++++++++++ drivers/nvmem/layouts/Kconfig | 5 ++ drivers/nvmem/layouts/Makefile | 4 + include/linux/nvmem-consumer.h | 7 ++ include/linux/nvmem-provider.h | 51 ++++++++++++ 8 files changed, 207 insertions(+) create mode 100644 drivers/nvmem/layouts/Kconfig create mode 100644 drivers/nvmem/layouts/Makefile diff --git a/Documentation/driver-api/nvmem.rst b/Documentation/driver-api/nvmem.rst index e3366322d46c..de221e91c8e3 100644 --- a/Documentation/driver-api/nvmem.rst +++ b/Documentation/driver-api/nvmem.rst @@ -185,3 +185,18 @@ ex:: ===================== See Documentation/devicetree/bindings/nvmem/nvmem.txt + +8. NVMEM layouts +================ + +NVMEM layouts are yet another mechanism to create cells. With the device +tree binding it is possible to specify simple cells by using an offset +and a length. Sometimes, the cells doesn't have a static offset, but +the content is still well defined, e.g. tag-length-values. In this case, +the NVMEM device content has to be first parsed and the cells need to +be added accordingly. Layouts let you read the content of the NVMEM device +and let you add cells dynamically. + +Another use case for layouts is the post processing of cells. With layouts, +it is possible to associate a custom post processing hook to a cell. It +even possible to add this hook to cells not created by the layout itself. diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 6dec38805041..ae2c5257ed97 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -21,6 +21,10 @@ config NVMEM_SYSFS This interface is mostly used by userspace applications to read/write directly into nvmem. +# Layouts + +source "drivers/nvmem/layouts/Kconfig" + # Devices config NVMEM_APPLE_EFUSES diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index 6a1efffa88f0..f82431ec8aef 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_NVMEM) += nvmem_core.o nvmem_core-y := core.o +obj-y += layouts/ # Devices obj-$(CONFIG_NVMEM_APPLE_EFUSES) += nvmem-apple-efuses.o diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 22024b830788..b9be1faeb7be 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -40,6 +40,7 @@ struct nvmem_device { nvmem_reg_write_t reg_write; nvmem_cell_post_process_t cell_post_process; struct gpio_desc *wp_gpio; + struct nvmem_layout *layout; void *priv; }; @@ -74,6 +75,9 @@ static LIST_HEAD(nvmem_lookup_list); static BLOCKING_NOTIFIER_HEAD(nvmem_notifier); +static DEFINE_SPINLOCK(nvmem_layout_lock); +static LIST_HEAD(nvmem_layouts); + static int __nvmem_reg_read(struct nvmem_device *nvmem, unsigned int offset, void *val, size_t bytes) { @@ -728,6 +732,101 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem) return 0; } +int __nvmem_layout_register(struct nvmem_layout *layout, struct module *owner) +{ + layout->owner = owner; + + spin_lock(&nvmem_layout_lock); + list_add(&layout->node, &nvmem_layouts); + spin_unlock(&nvmem_layout_lock); + + return 0; +} +EXPORT_SYMBOL_GPL(__nvmem_layout_register); + +void nvmem_layout_unregister(struct nvmem_layout *layout) +{ + spin_lock(&nvmem_layout_lock); + list_del(&layout->node); + spin_unlock(&nvmem_layout_lock); +} +EXPORT_SYMBOL_GPL(nvmem_layout_unregister); + +static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem) +{ + struct device_node *layout_np, *np = nvmem->dev.of_node; + struct nvmem_layout *l, *layout = NULL; + + layout_np = of_get_child_by_name(np, "nvmem-layout"); + if (!layout_np) + return NULL; + + spin_lock(&nvmem_layout_lock); + + list_for_each_entry(l, &nvmem_layouts, node) { + if (of_match_node(l->of_match_table, layout_np)) { + if (try_module_get(l->owner)) + layout = l; + + break; + } + } + + spin_unlock(&nvmem_layout_lock); + of_node_put(layout_np); + + return layout; +} + +static void nvmem_layout_put(struct nvmem_layout *layout) +{ + if (layout) + module_put(layout->owner); +} + +static int nvmem_add_cells_from_layout(struct nvmem_device *nvmem) +{ + struct nvmem_layout *layout = nvmem->layout; + int ret; + + if (layout && layout->add_cells) { + ret = layout->add_cells(&nvmem->dev, nvmem, layout); + if (ret) + return ret; + } + + return 0; +} + +#if IS_ENABLED(CONFIG_OF) +/** + * of_nvmem_layout_get_container() - Get OF node to layout container. + * + * @nvmem: nvmem device. + * + * Return: a node pointer with refcount incremented or NULL if no + * container exists. Use of_node_put() on it when done. + */ +struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvmem) +{ + return of_get_child_by_name(nvmem->dev.of_node, "nvmem-layout"); +} +EXPORT_SYMBOL_GPL(of_nvmem_layout_get_container); +#endif + +const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem, + struct nvmem_layout *layout) +{ + struct device_node __maybe_unused *layout_np; + const struct of_device_id *match; + + layout_np = of_nvmem_layout_get_container(nvmem); + match = of_match_node(layout->of_match_table, layout_np); + + return match ? match->data : NULL; +} +EXPORT_SYMBOL_GPL(nvmem_layout_get_match_data); + /** * nvmem_register() - Register a nvmem device for given nvmem_config. * Also creates a binary entry in /sys/bus/nvmem/devices/dev-name/nvmem @@ -834,6 +933,12 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) goto err_put_device; } + /* + * If the driver supplied a layout by config->layout, the module + * pointer will be NULL and nvmem_layout_put() will be a noop. + */ + nvmem->layout = config->layout ?: nvmem_layout_get(nvmem); + if (config->cells) { rval = nvmem_add_cells(nvmem, config->cells, config->ncells); if (rval) @@ -854,12 +959,17 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) if (rval) goto err_remove_cells; + rval = nvmem_add_cells_from_layout(nvmem); + if (rval) + goto err_remove_cells; + blocking_notifier_call_chain(&nvmem_notifier, NVMEM_ADD, nvmem); return nvmem; err_remove_cells: nvmem_device_remove_all_cells(nvmem); + nvmem_layout_put(nvmem->layout); if (config->compat) nvmem_sysfs_remove_compat(nvmem, config); err_put_device: @@ -881,6 +991,7 @@ static void nvmem_device_release(struct kref *kref) device_remove_bin_file(nvmem->base_dev, &nvmem->eeprom); nvmem_device_remove_all_cells(nvmem); + nvmem_layout_put(nvmem->layout); device_unregister(&nvmem->dev); } @@ -1246,6 +1357,15 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) return ERR_PTR(-EINVAL); } + /* nvmem layouts produce cells within the nvmem-layout container */ + if (of_node_name_eq(nvmem_np, "nvmem-layout")) { + nvmem_np = of_get_next_parent(nvmem_np); + if (!nvmem_np) { + of_node_put(cell_np); + return ERR_PTR(-EINVAL); + } + } + nvmem = __nvmem_device_get(nvmem_np, device_match_of_node); of_node_put(nvmem_np); if (IS_ERR(nvmem)) { diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig new file mode 100644 index 000000000000..9ad3911d1605 --- /dev/null +++ b/drivers/nvmem/layouts/Kconfig @@ -0,0 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0 + +menu "Layout Types" + +endmenu diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile new file mode 100644 index 000000000000..6fdb3c60a4fa --- /dev/null +++ b/drivers/nvmem/layouts/Makefile @@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 +# +# Makefile for nvmem layouts. +# diff --git a/include/linux/nvmem-consumer.h b/include/linux/nvmem-consumer.h index 1f62f7ba71ca..fa030d93b768 100644 --- a/include/linux/nvmem-consumer.h +++ b/include/linux/nvmem-consumer.h @@ -239,6 +239,7 @@ struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id); struct nvmem_device *of_nvmem_device_get(struct device_node *np, const char *name); +struct device_node *of_nvmem_layout_get_container(struct nvmem_device *nvmem); #else static inline struct nvmem_cell *of_nvmem_cell_get(struct device_node *np, const char *id) @@ -251,6 +252,12 @@ static inline struct nvmem_device *of_nvmem_device_get(struct device_node *np, { return ERR_PTR(-EOPNOTSUPP); } + +static inline struct device_node * +of_nvmem_layout_get_container(struct nvmem_device *nvmem) +{ + return ERR_PTR(-EOPNOTSUPP); +} #endif /* CONFIG_NVMEM && CONFIG_OF */ #endif /* ifndef _LINUX_NVMEM_CONSUMER_H */ diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 0262b86194eb..535c5f9f3309 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -88,6 +88,7 @@ struct nvmem_cell_info { * @stride: Minimum read/write access stride. * @priv: User context passed to read/write callbacks. * @ignore_wp: Write Protect pin is managed by the provider. + * @layout: Fixed layout associated with this nvmem device. * * Note: A default "nvmem" name will be assigned to the device if * no name is specified in its configuration. In such case "" is @@ -109,6 +110,7 @@ struct nvmem_config { bool read_only; bool root_only; bool ignore_wp; + struct nvmem_layout *layout; struct device_node *of_node; bool no_of_node; nvmem_reg_read_t reg_read; @@ -142,6 +144,33 @@ struct nvmem_cell_table { struct list_head node; }; +/** + * struct nvmem_layout - NVMEM layout definitions + * + * @name: Layout name. + * @of_match_table: Open firmware match table. + * @add_cells: Will be called if a nvmem device is found which + * has this layout. The function will add layout + * specific cells with nvmem_add_one_cell(). + * @owner: Pointer to struct module. + * @node: List node. + * + * A nvmem device can hold a well defined structure which can just be + * evaluated during runtime. For example a TLV list, or a list of "name=val" + * pairs. A nvmem layout can parse the nvmem device and add appropriate + * cells. + */ +struct nvmem_layout { + const char *name; + const struct of_device_id *of_match_table; + int (*add_cells)(struct device *dev, struct nvmem_device *nvmem, + struct nvmem_layout *layout); + + /* private */ + struct module *owner; + struct list_head node; +}; + #if IS_ENABLED(CONFIG_NVMEM) struct nvmem_device *nvmem_register(const struct nvmem_config *cfg); @@ -156,6 +185,14 @@ void nvmem_del_cell_table(struct nvmem_cell_table *table); int nvmem_add_one_cell(struct nvmem_device *nvmem, const struct nvmem_cell_info *info); +int __nvmem_layout_register(struct nvmem_layout *layout, struct module *owner); +#define nvmem_layout_register(layout) \ + __nvmem_layout_register(layout, THIS_MODULE) +void nvmem_layout_unregister(struct nvmem_layout *layout); + +const void *nvmem_layout_get_match_data(struct nvmem_device *nvmem, + struct nvmem_layout *layout); + #else static inline struct nvmem_device *nvmem_register(const struct nvmem_config *c) @@ -179,5 +216,19 @@ static inline int nvmem_add_one_cell(struct nvmem_device *nvmem, return -EOPNOTSUPP; } +static inline int nvmem_layout_register(struct nvmem_layout *layout) +{ + return -EOPNOTSUPP; +} + +static inline void nvmem_layout_unregister(struct nvmem_layout *layout) {} + +static inline const void * +nvmem_layout_get_match_data(struct nvmem_device *nvmem, + struct nvmem_layout *layout) +{ + return NULL; +} + #endif /* CONFIG_NVMEM */ #endif /* ifndef _LINUX_NVMEM_PROVIDER_H */ From patchwork Wed Mar 8 15:31:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66297 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp403683wrd; Wed, 8 Mar 2023 07:35:00 -0800 (PST) X-Google-Smtp-Source: AK7set9N0YsEACW7rRtQ4er/wvce7qluva3NDlOKHNQAiVth3UanbBpQ6SEC753svgINit8M1hzK X-Received: by 2002:a05:6a20:748c:b0:cc:5b1d:7d8d with SMTP id p12-20020a056a20748c00b000cc5b1d7d8dmr18104208pzd.17.1678289700626; Wed, 08 Mar 2023 07:35:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678289700; cv=none; d=google.com; s=arc-20160816; b=olHtHtKh1r6PBfWkG13ugJv06BD3slrlVUEs7TN+wiJpPsyMtZhlzb2530TmNHvukh IpJ/COIC0PxylQRYWp6Vp3EEoKw7SMCQGEH37bRWHKPlbgOz0mu3zms6if2dlRGTFRYj 3naSYutc08iT7CX74O1pZEyBzmFrwyrzf9YfX4MaITWCHcTMll4DUulYcQkPt+QqY4cw hD7GV1p0m0054dah0GmbQNJnpPwPIP87pFmFMP2zc4xQDhrSlIZNwgjpyAxTBa802Ls/ 3MwqWcmUuNaorES6ilxhRpHOuPIgqb6TiC4Yeg/2LOCN88G+9wptxUhGugwoS1gtbGst cRBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=7KeyBQUfcV1ky8pfB8UN0PcucnmwJo4XrlM30Q7JJvc=; b=EOBq37cOoGlaNl18fqViA3SYrFtM2xshYnv7XD1tdOLNT7Hu4xjKSB5JkMrxvpMi0s RXLUP3rX1YlK9gDXF4FsAWge9mxDmzbn1HxZT+FKbAZ9DpGYqKJplNat08UiG8S2TV/m Sw52hVvrFrucSchC+A5a9c7NrMVMOzgK43tP2SugOAccFUwbTE3hvZkVpUYRlmya0F00 gMDtJ2YF015UZfmEL0cd0tfDsjKRYdRM8BICq8YTq4YGPtzbokvjoHbfuNBtqS7hS1yr qoP/Bw1QkFf8Ooa6Ysv9NvIWDhHL5+cI7grX0Xca3lNF6Qfmcf2pjwHDUNj+0sc/n4VY imAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=AYiNuyBE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b10-20020a621b0a000000b005818631179asi15938481pfb.95.2023.03.08.07.34.43; Wed, 08 Mar 2023 07:35:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=AYiNuyBE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232243AbjCHPdK (ORCPT + 99 others); Wed, 8 Mar 2023 10:33:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231220AbjCHPcr (ORCPT ); Wed, 8 Mar 2023 10:32:47 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB963D5A7B; Wed, 8 Mar 2023 07:32:23 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 35ADAFF810; Wed, 8 Mar 2023 15:32:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289542; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7KeyBQUfcV1ky8pfB8UN0PcucnmwJo4XrlM30Q7JJvc=; b=AYiNuyBEWJM4eBys71tEUiEquTzUtgAJQyflZ4sppwXCsTUgHJ47x7esDynimmFQPBQTmk 0E7rYTs3WT06c8yQ8FYOLtiAa2cHqw0dSwYpwqzZ2adSjhrLmfl6Fh3K0KbhnAF16woWUR 7bsPuYHEk2JhrW4ImAu40iEmyvRmghwx/kI1rQM98XSwk/UNCo99MFP3jcyYzqAekIs3+q tEJ9sGW4mi7GwOk8x3MuwwIo9AZ3bhjAHInYfNloKADALFqZbKZXg944oDs9ulMGjY5E7k lTLll4LcLs5KXkHcvbuR1QccFZjWBlDDBNVhdazC1nGv45SAg3MSsNM65jTH7w== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v3 10/20] nvmem: core: handle the absence of expected layouts Date: Wed, 8 Mar 2023 16:31:50 +0100 Message-Id: <20230308153200.682248-11-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814300963473581?= X-GMAIL-MSGID: =?utf-8?q?1759814300963473581?= Make nvmem_layout_get() return -EPROBE_DEFER while the expected layout is not available. This condition cannot be triggered today as nvmem layout drivers are initialed as part of an early init call, but soon these drivers will be converted into modules and be initialized with a standard priority, so the unavailability of the drivers might become a reality that must be taken care of. Let's anticipate this by telling the caller the layout might not yet be available. A probe deferral is requested in this case. Please note this does not affect any nvmem device not using layouts, because an early check against the "nvmem-layout" container presence will return NULL in this case. Signed-off-by: Miquel Raynal Tested-by: Michael Walle --- drivers/nvmem/core.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index b9be1faeb7be..51fd792b8d70 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -755,7 +755,7 @@ EXPORT_SYMBOL_GPL(nvmem_layout_unregister); static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem) { struct device_node *layout_np, *np = nvmem->dev.of_node; - struct nvmem_layout *l, *layout = NULL; + struct nvmem_layout *l, *layout = ERR_PTR(-EPROBE_DEFER); layout_np = of_get_child_by_name(np, "nvmem-layout"); if (!layout_np) @@ -938,6 +938,13 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) * pointer will be NULL and nvmem_layout_put() will be a noop. */ nvmem->layout = config->layout ?: nvmem_layout_get(nvmem); + if (IS_ERR(nvmem->layout)) { + rval = PTR_ERR(nvmem->layout); + nvmem->layout = NULL; + + if (rval == -EPROBE_DEFER) + goto err_teardown_compat; + } if (config->cells) { rval = nvmem_add_cells(nvmem, config->cells, config->ncells); @@ -970,6 +977,7 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) err_remove_cells: nvmem_device_remove_all_cells(nvmem); nvmem_layout_put(nvmem->layout); +err_teardown_compat: if (config->compat) nvmem_sysfs_remove_compat(nvmem, config); err_put_device: From patchwork Wed Mar 8 15:31:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66312 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp407125wrd; Wed, 8 Mar 2023 07:41:41 -0800 (PST) X-Google-Smtp-Source: AK7set889kxpqm1C1AHXFdYLsktoJb3rPAtbSWYuHfU3frqepnrS1CdTsLN0zHW3Dt33KoESz0vp X-Received: by 2002:aa7:8704:0:b0:594:1f1c:3d3a with SMTP id b4-20020aa78704000000b005941f1c3d3amr20140684pfo.15.1678290101159; Wed, 08 Mar 2023 07:41:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678290101; cv=none; d=google.com; s=arc-20160816; b=HfJgaysmANN4HWE1Jg6+lxzVWySsBK2iqy99YjUok5iILEKC06YXd/Z8IGH9XKxlqv P8iuqLkqbrANrobl7GRdLsnGsA6CNeDfw2ocGKAuthCGcup/rzR41+V+Fp0edJ5YE2I5 6S74Ue0T/+QP2nQcQfVXBs3P5PuSYbuxSE27kN1XquZvB8PRm+MpNA9+XR39vg2OAyDn 4F/48vvkoI+c0r/UPUMIrzi5TREbWz+NKjBoIS/EZT5P787TUMrCAHm/TRGEXjsXoMpS +BrR9ukWoTkS0hOf65M9mRuJNCYaVgbqiwNvCI7bs7EH0dhGmddfeqye66+47PF5eMEO rhiQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=tqDLaqZ1GuVBw64kENerPspXdR7LpiuTsQla1HFP/KA=; b=FS98tWWrkOohX8z3AgnPi1WTplACL8sbCh8Quqn2PneD9ylRXKYBHBLwUNC+PfbaIY OthNrNK/8g6zQ/jhW0WsaevKY02CplT5VgDv2odKqJDBJi+CtXPbqMA+UDDuilY1HxlS nL/CYsypG1g/lQ5uaDX+vZ1dRf0y2a+IDUDLXHeYqon42F3tZBQY0YfF7wPjGHfNOclo SXtmDaWb054dabh6oemk84S6MAidtbIpBH61rAV8f9YjkxON4UdQ6z0BbwPGuspyqT1U CB5IbEa7JVwxBThAaUSrE4NjCwtPdJ+OjJaBPIqqLdj8CNArl0ei5HFDPZGTwcUFByro 3WRg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=cQ7VnWXm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t3-20020a625f03000000b005a9dd8ef30csi14567988pfb.216.2023.03.08.07.41.25; Wed, 08 Mar 2023 07:41:41 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=cQ7VnWXm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232218AbjCHPdU (ORCPT + 99 others); Wed, 8 Mar 2023 10:33:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51096 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232259AbjCHPcv (ORCPT ); Wed, 8 Mar 2023 10:32:51 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8ADE7D6EAE; Wed, 8 Mar 2023 07:32:25 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id B3B59FF813; Wed, 8 Mar 2023 15:32:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289544; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tqDLaqZ1GuVBw64kENerPspXdR7LpiuTsQla1HFP/KA=; b=cQ7VnWXm4rso7T5LFef6267qVl+4QhYqUFxU2isjgqiCwTqInek/KLy579lEji53gzli+B LrRilpvHwlhDCk3wz8+DKlOP+agaoxKT6CW8A49mBvQ+gFCcRI1b3w9RNVz1huEa9TIHfY yVX1CYkCnv3yL/cEPhmYuzI0uQ/wfFKE/eKIYy78/5pAsEQQefspKaHACG8aBN1z2RMtuc ypwOGfNgqyqv5ed1rZvjdpDIEFM1+W62NOjoaksmStTAf/fb6uouhXZxBjntlfv2AAKBYj SvISjtXfSImrrbkD8BuOaqqGZj6okeHftP9g4md7hRBYeXqcqDqV0YTCRLLBsw== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v3 11/20] nvmem: core: request layout modules loading Date: Wed, 8 Mar 2023 16:31:51 +0100 Message-Id: <20230308153200.682248-12-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814720830990247?= X-GMAIL-MSGID: =?utf-8?q?1759814720830990247?= When a storage device like an eeprom or an mtd device probes, it registers an nvmem device if the nvmem subsystem has been enabled (bool symbol). During nvmem registration, if the device is using layouts to expose dynamic nvmem cells, the core will first try to get a reference over the layout driver callbacks. In practice there is not relationship that can be described between the storage driver and the nvmem layout. So there is no way we can enforce both drivers will be built-in or both will be modules. If the storage device driver is built-in but the layout is built as a module, instead of badly failing with an endless probe deferral loop, lets just make a modprobe call in case the driver was made available in an initramfs with of_device_node_request_module(), and offer a fully functional system to the user. Signed-off-by: Miquel Raynal Tested-by: Michael Walle --- drivers/nvmem/core.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 51fd792b8d70..49b4bbaf59e8 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -17,6 +17,7 @@ #include #include #include +#include #include struct nvmem_device { @@ -761,6 +762,13 @@ static struct nvmem_layout *nvmem_layout_get(struct nvmem_device *nvmem) if (!layout_np) return NULL; + /* + * In case the nvmem device was built-in while the layout was built as a + * module, we shall manually request the layout driver loading otherwise + * we'll never have any match. + */ + of_request_module(layout_np); + spin_lock(&nvmem_layout_lock); list_for_each_entry(l, &nvmem_layouts, node) { From patchwork Wed Mar 8 15:31:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66307 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp405946wrd; Wed, 8 Mar 2023 07:39:23 -0800 (PST) X-Google-Smtp-Source: AK7set/dhHAnVyU+y9YAB7CviwiHwhF2dnnT3k8UeLArJh3FOW0oSQ5vpnEWV5DP3gqjRlKMDmtk X-Received: by 2002:a17:902:f7cb:b0:19c:ba57:a869 with SMTP id h11-20020a170902f7cb00b0019cba57a869mr16495818plw.13.1678289963118; Wed, 08 Mar 2023 07:39:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678289963; cv=none; d=google.com; s=arc-20160816; b=XzP5GJ06IMH6FtBfsG3sCJvZ2HGPt3IHATHAH6YRohYo50AryGiRUwDycwTjNtEIF5 WQqHP9sMAe7PhHRgviMB/7xqm9jUo1mu9QvlX+rCLKqROUGAtB5XazoP3Rb7/TBH7g6m 3LoLpCi54IXNfra+H3iMLGvvPkOMy2COu3dNkl5d/2Y1osKYr4YEb/XF9vvR7YZsEcQp hfsk5agJyVJCQM+9hsqgaLjt9v9mUW03nluKgWaqXrIkq9EYgxmkDXBjcIWPCnIH3JoT sxBn3CGPpgY53qQy8KHpyTcxiAQhAva3M32ueZlZ6URkB9P43Qx/3lIjbGlNadJDIp18 Mwfw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=kPt8JXf9NOQ0MTpLZEyB4ihbzR5v6xSqNymS3y+vPl0=; b=oEdvByDLrbkv3+UpJnq6hEQ900IuBX+xhkuXKf1F2cO88BD7fXc55thwe8w3PoT/6p 9tc3aLjRpXm0eBsF8gqo6RPz6jebAmJks2cJRmLbiUH1lMhFzz+zjgAIFWWVPuRFtRGa bV0PdVaJ1AD5K8PEo8919vqJZUYabVG5Es/cCOXVAHoTudeSeveEDtw+uialMHNDbuiv rBROdZj1dCbEE1joEoNkaLr6Ypn3oHlpcYwCzYFzZQSQF3XXW4qykUqLa4NtcsC8nade lTJPD6gKRytczeTGWhLm9z5cki5sxG+KYOz5VGJRy1Q9E3fHGQsO5LVISjL0Ryiv5vGs MZaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=CfKOeyVv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jh21-20020a170903329500b0019b7766afdfsi14719541plb.626.2023.03.08.07.39.10; Wed, 08 Mar 2023 07:39:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=CfKOeyVv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232255AbjCHPdc (ORCPT + 99 others); Wed, 8 Mar 2023 10:33:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232279AbjCHPcy (ORCPT ); Wed, 8 Mar 2023 10:32:54 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68360DB6E8; Wed, 8 Mar 2023 07:32:27 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 5C833FF812; Wed, 8 Mar 2023 15:32:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289545; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kPt8JXf9NOQ0MTpLZEyB4ihbzR5v6xSqNymS3y+vPl0=; b=CfKOeyVv7kx4wu/bRzKxXPq0xmAQGDmLNLLkbr5p0GGKW3ZIoIY/hljgB8sRYaLoR/fbnZ 8my+azHW9vZ6PVvrt8OAHO0+ds9JHludsMDnExbbP9QHk+LsR148/Jv9GB05vJziBJ68ek 8Yt+iuCEX+X/21JTp06E6xDf4dNfgTl+WDq0ZDqE3B0P3dJqfjvhcDw2eGuWJNreWiSWZ+ OVIOiWys3DdLz9yyV88dfD10lsyiMfUO7TpnLnJ3aBlyFk4ooUO8CyOiCdJWcJ1GcQkbBL jgW1Y9Lmlqbjj27jfNwUKuZKRYnMxXe65VdI94UyenqQZCG5lEeGeVgFhHeFZw== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v3 12/20] nvmem: core: add per-cell post processing Date: Wed, 8 Mar 2023 16:31:52 +0100 Message-Id: <20230308153200.682248-13-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814576380378427?= X-GMAIL-MSGID: =?utf-8?q?1759814576380378427?= From: Michael Walle Instead of relying on the name the consumer is using for the cell, like it is done for the nvmem .cell_post_process configuration parameter, provide a per-cell post processing hook. This can then be populated by the NVMEM provider (or the NVMEM layout) when adding the cell. Signed-off-by: Michael Walle Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 17 +++++++++++++++++ include/linux/nvmem-provider.h | 3 +++ 2 files changed, 20 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 49b4bbaf59e8..0708f9f27898 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -54,6 +54,7 @@ struct nvmem_cell_entry { int bytes; int bit_offset; int nbits; + nvmem_cell_post_process_t read_post_process; struct device_node *np; struct nvmem_device *nvmem; struct list_head node; @@ -470,6 +471,7 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem, cell->offset = info->offset; cell->bytes = info->bytes; cell->name = info->name; + cell->read_post_process = info->read_post_process; cell->bit_offset = info->bit_offset; cell->nbits = info->nbits; @@ -1563,6 +1565,13 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, if (cell->bit_offset || cell->nbits) nvmem_shift_read_buffer_in_place(cell, buf); + if (cell->read_post_process) { + rc = cell->read_post_process(nvmem->priv, id, index, + cell->offset, buf, cell->bytes); + if (rc) + return rc; + } + if (nvmem->cell_post_process) { rc = nvmem->cell_post_process(nvmem->priv, id, index, cell->offset, buf, cell->bytes); @@ -1671,6 +1680,14 @@ static int __nvmem_cell_entry_write(struct nvmem_cell_entry *cell, void *buf, si (cell->bit_offset == 0 && len != cell->bytes)) return -EINVAL; + /* + * Any cells which have a read_post_process hook are read-only because + * we cannot reverse the operation and it might affect other cells, + * too. + */ + if (cell->read_post_process) + return -EINVAL; + if (cell->bit_offset || cell->nbits) { buf = nvmem_cell_prepare_write_buffer(cell, buf, len); if (IS_ERR(buf)) diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 535c5f9f3309..3bfc23553a9e 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -54,6 +54,8 @@ struct nvmem_keepout { * @bit_offset: Bit offset if cell is smaller than a byte. * @nbits: Number of bits. * @np: Optional device_node pointer. + * @read_post_process: Callback for optional post processing of cell data + * on reads. */ struct nvmem_cell_info { const char *name; @@ -62,6 +64,7 @@ struct nvmem_cell_info { unsigned int bit_offset; unsigned int nbits; struct device_node *np; + nvmem_cell_post_process_t read_post_process; }; /** From patchwork Wed Mar 8 15:31:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66308 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp406026wrd; Wed, 8 Mar 2023 07:39:34 -0800 (PST) X-Google-Smtp-Source: AK7set+LxxAR6Qnfu4VroodaE8r49zH/Haxjq7H2VUu6garjiK5dKV57bMRM5X20zyWWJRkNrjT6 X-Received: by 2002:a05:6a20:7aa7:b0:c7:6232:c6e2 with SMTP id u39-20020a056a207aa700b000c76232c6e2mr14777444pzh.48.1678289973748; Wed, 08 Mar 2023 07:39:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678289973; cv=none; d=google.com; s=arc-20160816; b=VDqEcAdufKKfIIyWRgDloh0j42NlNSG6z/9i9UZGVatRf4dIne8xPAoSY97tTIxXF5 DrA9sW61zeOP8MPKDQR94pzMnh78A+gA40X8Ob01UnjQQS/ke0fvxdIboN6lVtt4ha0B 0Hrn/L5RGbrdKE4O5gcSp6saw3A/mJXLha7HeI1nkqk4YL2LT0RUHUFj+XTWm7D5dA4A asMXtac3nApMZ8GS1mcsg79AJB66eLm1SNmRdP8lvsX60wPORwiDc6J8s63uzITCnLiF V6+wMPTgleOQer5db4K0EB2dyFTtG2ztjf6C7J7Q+3lXA2d0K3m4cg83DVgPihhgfv7T 3wNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uNiNDyX4GaTfMI2x7EDRmsWPXsDEC+d6+Vzjx+rSfbg=; b=CLvmZqAUEhGamHCGUs7r89101rFwOa0objNDTN/iuFWbKG34NK+s36W0U6wvxm0PyH Df+eZsMP0ROQehFODQMVmxn67UB0m4l3RmkJ+i/lnYnqPH0DnhnfEAxzwFilqfUg9jnp HIpkLXgtJHgS9f8t96bN3pr2G4lQhaIyxSsmaI/BFUdDJRH3DwDAvJnLFU4BQhJBsKCg F8FkSAdHjL+f1OvJG2ohdMkbMO5XJURMCNLRLXKtSa3jTwAm11AIfuwTEUyeB4rooMEZ nSkb2TWV8IprEjlkGC5K6AwINOLydPMKMXxWKUbqqHAK45gbnIrGdTOzGiidBGQh8GM2 C+CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=fiU+R4qS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 3-20020a631143000000b004fbcff506c5si13892911pgr.346.2023.03.08.07.39.20; Wed, 08 Mar 2023 07:39:33 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=fiU+R4qS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232280AbjCHPdg (ORCPT + 99 others); Wed, 8 Mar 2023 10:33:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232212AbjCHPcz (ORCPT ); Wed, 8 Mar 2023 10:32:55 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 778565D244; Wed, 8 Mar 2023 07:32:28 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id C6BC8FF803; Wed, 8 Mar 2023 15:32:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289546; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uNiNDyX4GaTfMI2x7EDRmsWPXsDEC+d6+Vzjx+rSfbg=; b=fiU+R4qSe+SYgKPHztNLUiJNcwUUQ5sdflk1BjJ7XPE29xJaYqT1YMFMFE2cw1z6rItJb1 GY1vdXQFqunKASh5EUWj65djg7+XT4YOTkmaIEwWGuyhG55j7wmkRT3C+tHvR2domAOWxj rlCe27eemstW4iQclClYvJ0EfhDItfo3Q04vOZU38SkEN1TcUB5d/tsC7HSGC/NOu+ufwi /bQL3niecPNsgKbJBBX2XssKgWi951Vo5a+uf3XnnBtfck222Gk8W6NQY5ZBJxpQ8KNq4C XApxhwtgk6RDwgjbautO2ckDlowPP5Ap9o6vLDadxVbNNNrKy9DCpxcvzBvh2w== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v3 13/20] nvmem: core: allow to modify a cell before adding it Date: Wed, 8 Mar 2023 16:31:53 +0100 Message-Id: <20230308153200.682248-14-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814587290200882?= X-GMAIL-MSGID: =?utf-8?q?1759814587290200882?= From: Michael Walle Provide a way to modify a cell before it will get added. This is useful to attach a custom post processing hook via a layout. Signed-off-by: Michael Walle Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 4 ++++ include/linux/nvmem-provider.h | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index 0708f9f27898..f43025ad315b 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -695,6 +695,7 @@ static int nvmem_validate_keepouts(struct nvmem_device *nvmem) static int nvmem_add_cells_from_of(struct nvmem_device *nvmem) { + struct nvmem_layout *layout = nvmem->layout; struct device *dev = &nvmem->dev; struct device_node *child; const __be32 *addr; @@ -724,6 +725,9 @@ static int nvmem_add_cells_from_of(struct nvmem_device *nvmem) info.np = of_node_get(child); + if (layout && layout->fixup_cell_info) + layout->fixup_cell_info(nvmem, layout, &info); + ret = nvmem_add_one_cell(nvmem, &info); kfree(info.name); if (ret) { diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index 3bfc23553a9e..be81cc88eabc 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -155,6 +155,8 @@ struct nvmem_cell_table { * @add_cells: Will be called if a nvmem device is found which * has this layout. The function will add layout * specific cells with nvmem_add_one_cell(). + * @fixup_cell_info: Will be called before a cell is added. Can be + * used to modify the nvmem_cell_info. * @owner: Pointer to struct module. * @node: List node. * @@ -168,6 +170,9 @@ struct nvmem_layout { const struct of_device_id *of_match_table; int (*add_cells)(struct device *dev, struct nvmem_device *nvmem, struct nvmem_layout *layout); + void (*fixup_cell_info)(struct nvmem_device *nvmem, + struct nvmem_layout *layout, + struct nvmem_cell_info *cell); /* private */ struct module *owner; From patchwork Wed Mar 8 15:31:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66299 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp404007wrd; Wed, 8 Mar 2023 07:35:32 -0800 (PST) X-Google-Smtp-Source: AK7set+Y1YkcO6+1SHqvtWImvBFkt17oXHMhU/SlJr0JbhrBFYbVSPZM4bGJ7eYVAsuQU26opnoQ X-Received: by 2002:a17:902:c407:b0:19e:7490:c93e with SMTP id k7-20020a170902c40700b0019e7490c93emr26058766plk.63.1678289731943; Wed, 08 Mar 2023 07:35:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678289731; cv=none; d=google.com; s=arc-20160816; b=ML6Il94ES6MQXidfIZ6u3EC+wy/iZNHHBbQCMWLVCSDPiCRUcyIekh91mN3bB7mksf 0hd2986rF4TF8+xITBLsDuOkKUCOqGx7POfGOQZ7SW59jHKMe0HSasY9W6+RcPyUoa5V EjGd9H/ayITu8rt+/DTs8G76rekpuuIl43mNTCPVyYiMk95aP3gEBJoOWTw+4vLQd7Hx gtOiQEHouN2HJySp17w1AzJRANjJIpWZ8eEebQSgYJXoNnKbapGG0CuC7bUiz3h2wm2d 2m9RAXtfZkYecB6qcsL2U4YhA54/NNJ9OaDnu4gA1a29D6v71wO5EVuA7JsK0il1Kmd7 Ggaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=+8KBJRUvcteGrcXB2dPcvKQXMIPPTo96B4W8ORMytWg=; b=nG6vQgRR/gmol0kxbPZIEUsI9U7FwZQTwLIYizn6r+wRgxrPYgeJim3IJu4HThx6VP 9o2l0TkXAPCk187YpujTEReQGshk7TcY1mQ8t9gmoem0Xzz3CJbhCDd9+g21pRhX0qBr RBMzU3N7YEL/5/zyJGpaPfHncKphy5+Ew5SBiURCfMdG0oxmGX9ebybpOT7BiHmYnrC9 suWUADasWnJqeG9e+cKsW5Ub2vSFAV4+nu6GQ2mahSMe7d3r37wi6xTGuoPJ85o5WL8p YoyB47jqs4y7PlloDijUdDVQ7X4wTKZjBqt1f9zaGL4srYcChdKrtv+G/G3aTMTDwsfS xuKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=UXr4mxc1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id km11-20020a17090327cb00b0019e68e4e472si14358691plb.378.2023.03.08.07.35.14; Wed, 08 Mar 2023 07:35:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=UXr4mxc1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231951AbjCHPdj (ORCPT + 99 others); Wed, 8 Mar 2023 10:33:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232215AbjCHPc4 (ORCPT ); Wed, 8 Mar 2023 10:32:56 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CD61D5D24B; Wed, 8 Mar 2023 07:32:29 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 19777FF80C; Wed, 8 Mar 2023 15:32:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289548; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+8KBJRUvcteGrcXB2dPcvKQXMIPPTo96B4W8ORMytWg=; b=UXr4mxc1WU2zTuHUxkiT/b+F/1Sm4X8kCt2rAXYFwnBjQ/Hyf6T0CnzLDuuFBgIHE4sw/M 0t9tX4L/SGZE10HfBJlbeLiqAcpp0lwC8qvYknzOOKLUql0Yl1xohknLVaIuGI09j0S31E zwOREGgvVF1ULdl4t2bnOQki5Ltd3sAJq6r1QOghNUzjEmizj9FSwLDnjWC4OuKlzbo4v3 QwinXMOPkj80IWcb0eNPwHuAP29M7UpE7OAt4FIKqhW0TZxHy17DJdfxfuF5SwhR4JTUmE zaTsAjZRW/QUPzuj0ftfSGz8o8rH05A//HMPNkjUmUmFs5cziMbmEs3L3PE9Pg== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v3 14/20] nvmem: imx-ocotp: replace global post processing with layouts Date: Wed, 8 Mar 2023 16:31:54 +0100 Message-Id: <20230308153200.682248-15-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814333850109623?= X-GMAIL-MSGID: =?utf-8?q?1759814333850109623?= From: Michael Walle In preparation of retiring the global post processing hook change this driver to use layouts. The layout will be supplied during registration and will be used to add the post processing hook to all added cells. Signed-off-by: Michael Walle Tested-by: Michael Walle # on kontron-pitx-imx8m Signed-off-by: Miquel Raynal --- drivers/nvmem/imx-ocotp.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/drivers/nvmem/imx-ocotp.c b/drivers/nvmem/imx-ocotp.c index e9b52ecb3f72..ac0edb6398f1 100644 --- a/drivers/nvmem/imx-ocotp.c +++ b/drivers/nvmem/imx-ocotp.c @@ -225,18 +225,13 @@ static int imx_ocotp_read(void *context, unsigned int offset, static int imx_ocotp_cell_pp(void *context, const char *id, int index, unsigned int offset, void *data, size_t bytes) { - struct ocotp_priv *priv = context; + u8 *buf = data; + int i; /* Deal with some post processing of nvmem cell data */ - if (id && !strcmp(id, "mac-address")) { - if (priv->params->reverse_mac_address) { - u8 *buf = data; - int i; - - for (i = 0; i < bytes/2; i++) - swap(buf[i], buf[bytes - i - 1]); - } - } + if (id && !strcmp(id, "mac-address")) + for (i = 0; i < bytes / 2; i++) + swap(buf[i], buf[bytes - i - 1]); return 0; } @@ -488,7 +483,6 @@ static struct nvmem_config imx_ocotp_nvmem_config = { .stride = 1, .reg_read = imx_ocotp_read, .reg_write = imx_ocotp_write, - .cell_post_process = imx_ocotp_cell_pp, }; static const struct ocotp_params imx6q_params = { @@ -595,6 +589,17 @@ static const struct of_device_id imx_ocotp_dt_ids[] = { }; MODULE_DEVICE_TABLE(of, imx_ocotp_dt_ids); +static void imx_ocotp_fixup_cell_info(struct nvmem_device *nvmem, + struct nvmem_layout *layout, + struct nvmem_cell_info *cell) +{ + cell->read_post_process = imx_ocotp_cell_pp; +} + +struct nvmem_layout imx_ocotp_layout = { + .fixup_cell_info = imx_ocotp_fixup_cell_info, +}; + static int imx_ocotp_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; @@ -619,6 +624,9 @@ static int imx_ocotp_probe(struct platform_device *pdev) imx_ocotp_nvmem_config.size = 4 * priv->params->nregs; imx_ocotp_nvmem_config.dev = dev; imx_ocotp_nvmem_config.priv = priv; + if (priv->params->reverse_mac_address) + imx_ocotp_nvmem_config.layout = &imx_ocotp_layout; + priv->config = &imx_ocotp_nvmem_config; clk_prepare_enable(priv->clk); From patchwork Wed Mar 8 15:31:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66302 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp404717wrd; Wed, 8 Mar 2023 07:36:59 -0800 (PST) X-Google-Smtp-Source: AK7set92XLSUF5cZJOtHgCEoW5LVj5N6AXaOar5CgDDybY/m7jQ6q9RWvdl3Zro7Jd+hf2nppqs3 X-Received: by 2002:aa7:9489:0:b0:5a9:d619:e5e4 with SMTP id z9-20020aa79489000000b005a9d619e5e4mr15940993pfk.0.1678289819388; Wed, 08 Mar 2023 07:36:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678289819; cv=none; d=google.com; s=arc-20160816; b=JMoIpg4cRwiRnr1/nGJVA8EPgj2DX/T5v5+x9FJXXFgVV5sPS0SzgCqt0TFtxU6Mn+ kUVIHHsrhX5eIDjuFXpRCT0AGesQ4r6HI0s0QUqbxaSqGoQS99uIGqAOB0sr8Dj8nBJ6 X6Lhij1PIT20HYhLqzjBUfp8CkHh9Z2TYrwq6bZwEIdKU/FEkYO0l4rZs8sp1ZMxacWi WxuBQbtaPlZfoladv4QxxMZm6sZTBh9nxMgYO7f9LV/89mLskYOtqxTEnNbWcmXllh9V L2eTy/OAxYhPJSGVyHYsVR/66x4aMiOf/yEmAyP2ahFF96Bg+bTEmyJfmxUCoJ74Maqa sWJA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=A/ImksdSBrmaV0urK8R+sWRAcEcl9MKuKFJL/MM1X44=; b=tZdtHCrltnmmWwcXC6OiLezn9lZcS+M2JoB/eu987d/BlqgpARsgSqEsozs9uk6nMc yUemkZ7NMXtnQVcSjJUzUakarj6e9J53vseLGy0k0X/tBzxc8M2nhKCdxnU/scy6ObH3 1eUKnaZRA/Pb+CWOXuzbztWgRVNAniX/6/8Yh6Vx0vSEJUDmRumJd5oooc3af4CJMiIZ JQPgNBDTMZu/UUEvnfN2X2Utq4RszmGtx9OdHMIqA8vUYy3yUPDAj9AbpR+RlNl7Z0W8 sgybP65Zj6k5MRRs1Vy4PSG98/jkrRkvjUayd15Mu/KJhbVHGXwVkw66z70UV3sAkC/u dvrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=UdT+678g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a24-20020aa79718000000b005a8c0f03340si15023368pfg.375.2023.03.08.07.36.43; Wed, 08 Mar 2023 07:36:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=UdT+678g; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232290AbjCHPdn (ORCPT + 99 others); Wed, 8 Mar 2023 10:33:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231836AbjCHPc6 (ORCPT ); Wed, 8 Mar 2023 10:32:58 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 216725D259; Wed, 8 Mar 2023 07:32:30 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 71657FF817; Wed, 8 Mar 2023 15:32:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289549; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=A/ImksdSBrmaV0urK8R+sWRAcEcl9MKuKFJL/MM1X44=; b=UdT+678g6P+qOlbMDH0Z1fjEu1gOEcMJgU8+4g1tZ8k33FtN0HFlb9D/L3WV3domz6fOV+ VN3ujGIXt9jepInYoazwxUCsYww837N663VJajS8aVaF2RriflzrzIvgGW/ZmEIhKfGv+x WqdWco6FuZ9Hhb1u8eEzlVKjkCnbNSQBL7i8ANSnE750zjeuNwyLInPX1QzAoM2p5/YWH+ VcnjNc78M0CMyFJKJ0ScxyJ9gn1fe+UJ2fqCesxZ7sdc6O2TczLamDg/NIzsb5fQq74M5x EORFsmezHZ7kREEENV6hyYbRsiG0m8We37exUA994hHtATr/Mn/6alwAaSEAmQ== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v3 15/20] nvmem: cell: drop global cell_post_process Date: Wed, 8 Mar 2023 16:31:55 +0100 Message-Id: <20230308153200.682248-16-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814425607845989?= X-GMAIL-MSGID: =?utf-8?q?1759814425607845989?= From: Michael Walle There are no users anymore for the global cell_post_process callback anymore. New users should use proper nvmem layouts. Signed-off-by: Michael Walle Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 9 --------- include/linux/nvmem-provider.h | 2 -- 2 files changed, 11 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index f43025ad315b..fccb2728193a 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -39,7 +39,6 @@ struct nvmem_device { unsigned int nkeepout; nvmem_reg_read_t reg_read; nvmem_reg_write_t reg_write; - nvmem_cell_post_process_t cell_post_process; struct gpio_desc *wp_gpio; struct nvmem_layout *layout; void *priv; @@ -903,7 +902,6 @@ struct nvmem_device *nvmem_register(const struct nvmem_config *config) nvmem->type = config->type; nvmem->reg_read = config->reg_read; nvmem->reg_write = config->reg_write; - nvmem->cell_post_process = config->cell_post_process; nvmem->keepout = config->keepout; nvmem->nkeepout = config->nkeepout; if (config->of_node) @@ -1576,13 +1574,6 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, return rc; } - if (nvmem->cell_post_process) { - rc = nvmem->cell_post_process(nvmem->priv, id, index, - cell->offset, buf, cell->bytes); - if (rc) - return rc; - } - if (len) *len = cell->bytes; diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index be81cc88eabc..d3d7af86a283 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -85,7 +85,6 @@ struct nvmem_cell_info { * @no_of_node: Device should not use the parent's of_node even if it's !NULL. * @reg_read: Callback to read data. * @reg_write: Callback to write data. - * @cell_post_process: Callback for vendor specific post processing of cell data * @size: Device size. * @word_size: Minimum read/write access granularity. * @stride: Minimum read/write access stride. @@ -118,7 +117,6 @@ struct nvmem_config { bool no_of_node; nvmem_reg_read_t reg_read; nvmem_reg_write_t reg_write; - nvmem_cell_post_process_t cell_post_process; int size; int word_size; int stride; From patchwork Wed Mar 8 15:31:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66298 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp403999wrd; Wed, 8 Mar 2023 07:35:31 -0800 (PST) X-Google-Smtp-Source: AK7set9jdj6bax+mVAOviGWhw0K3FlA1mcUbgGtVDghmkgMcm8SVK/RKetiPqexI1h9sE8y8q7YK X-Received: by 2002:a05:6a20:c126:b0:cd:74aa:df55 with SMTP id bh38-20020a056a20c12600b000cd74aadf55mr15112603pzb.25.1678289730898; Wed, 08 Mar 2023 07:35:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678289730; cv=none; d=google.com; s=arc-20160816; b=0en/4IItW0BGIMCwIUXDnHtPg8ploDRqPpktKQpsvbDbUdELSCvmN1PfMjX2654khn WIQGh5h8lFR4/mCbot9KR+h383peUl7/7wrqZL2+LgOy8f6oWBalAD3aJJE1HmommvvM /WzJcuYpPD3E6Wk5aUcgZFGTcvsoqXLB0jHfd5gN//HryZWLGittUqwU1W6XtKUlCNH5 /sHR7SY47Ayl+nFsVFEWphra6DoJCeryI3bXKUGeBwmH4uYRJPQtpXKnAPBkILZgRvQF Cp2+3dE8nanJ8mJunWzkNxmLd9x1rlornma0rU4CUnv2sy+R6a0Sd2tasDi6nh+0iPM3 qZrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=EhEP0p7cTgU2NYHkJBTt1zaHHLH70q1d3GVrDXZ/qrs=; b=jTBwaA6i67YAvs3+ReTvvR4ysDCq8ytWkZ+cGJ2m7H19PbLDeGzHI5HCqnEgtkgfqK C27cnzv7ndO2h338rvzX4BnI7/ewRjfB/P/kzBNOpS2tffzdLTgsrMxWrmqhvAh+1Yz3 06xIuZ0wgLm877Dr2hCp9Tm37rH/XjejNAqpB9ooP0dcdLJMZZ0rt8Xm7wLat6m9Yt0w MtVPfxfJYBowErRtP3kefdQHenIS4f7kHL+KE2/v376ZpaK1v3JH9FA5tBTfuWCoakwR vij0xYn071U5syojt6Yf5vQO88q77P6jQ6cxp3Osk8m5iZR4Sb06DVnfxGD23GqvwzpW AMpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=X6gOZgA+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s18-20020a656452000000b005023dfa3c69si5639810pgv.405.2023.03.08.07.35.15; Wed, 08 Mar 2023 07:35:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=X6gOZgA+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231910AbjCHPd7 (ORCPT + 99 others); Wed, 8 Mar 2023 10:33:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232235AbjCHPdG (ORCPT ); Wed, 8 Mar 2023 10:33:06 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D93D5D253; Wed, 8 Mar 2023 07:32:32 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id CB060FF807; Wed, 8 Mar 2023 15:32:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289551; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EhEP0p7cTgU2NYHkJBTt1zaHHLH70q1d3GVrDXZ/qrs=; b=X6gOZgA+OwTX9CO3gJJjRDk3sGu9vCOMiuNbeDIwq+JnxYcAt+lBDTU2PuJS8/p82NMspL 9fdLtlz4m+6EUFEiQUYDEDlq/3M1uVmmfPS218moRA7TL5gMHWl77IWrYp9dh9lQY4ey/4 2+bIFRMHaa0sisfiDEUmxepkvil2WxXVghn1LsSXf3SXyC4WSR4RMppXYlUtq4ZtXkFF/5 lUoDWncTLyZIw2SfTicQKYt6oDsKxXGSpvb3eS9d2U+de7pE5bcBD10moP5PIv9O4TzlmL 9m2i4uo7YEHw+NoWzMJAiDPnUilYAwU3e5gb2wNL9JvMvW9l/bAB+fVtJDlZ0w== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v3 16/20] nvmem: core: provide own priv pointer in post process callback Date: Wed, 8 Mar 2023 16:31:56 +0100 Message-Id: <20230308153200.682248-17-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814332535256145?= X-GMAIL-MSGID: =?utf-8?q?1759814332535256145?= From: Michael Walle It doesn't make any more sense to have a opaque pointer set up by the nvmem device. Usually, the layout isn't associated with a particular nvmem device. Instead, let the caller who set the post process callback provide the priv pointer. Signed-off-by: Michael Walle Signed-off-by: Miquel Raynal --- drivers/nvmem/core.c | 4 +++- include/linux/nvmem-provider.h | 5 ++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/drivers/nvmem/core.c b/drivers/nvmem/core.c index fccb2728193a..212c5ba5789f 100644 --- a/drivers/nvmem/core.c +++ b/drivers/nvmem/core.c @@ -54,6 +54,7 @@ struct nvmem_cell_entry { int bit_offset; int nbits; nvmem_cell_post_process_t read_post_process; + void *priv; struct device_node *np; struct nvmem_device *nvmem; struct list_head node; @@ -471,6 +472,7 @@ static int nvmem_cell_info_to_nvmem_cell_entry_nodup(struct nvmem_device *nvmem, cell->bytes = info->bytes; cell->name = info->name; cell->read_post_process = info->read_post_process; + cell->priv = info->priv; cell->bit_offset = info->bit_offset; cell->nbits = info->nbits; @@ -1568,7 +1570,7 @@ static int __nvmem_cell_read(struct nvmem_device *nvmem, nvmem_shift_read_buffer_in_place(cell, buf); if (cell->read_post_process) { - rc = cell->read_post_process(nvmem->priv, id, index, + rc = cell->read_post_process(cell->priv, id, index, cell->offset, buf, cell->bytes); if (rc) return rc; diff --git a/include/linux/nvmem-provider.h b/include/linux/nvmem-provider.h index d3d7af86a283..0cf9f9490514 100644 --- a/include/linux/nvmem-provider.h +++ b/include/linux/nvmem-provider.h @@ -20,7 +20,8 @@ typedef int (*nvmem_reg_write_t)(void *priv, unsigned int offset, void *val, size_t bytes); /* used for vendor specific post processing of cell data */ typedef int (*nvmem_cell_post_process_t)(void *priv, const char *id, int index, - unsigned int offset, void *buf, size_t bytes); + unsigned int offset, void *buf, + size_t bytes); enum nvmem_type { NVMEM_TYPE_UNKNOWN = 0, @@ -56,6 +57,7 @@ struct nvmem_keepout { * @np: Optional device_node pointer. * @read_post_process: Callback for optional post processing of cell data * on reads. + * @priv: Opaque data passed to the read_post_process hook. */ struct nvmem_cell_info { const char *name; @@ -65,6 +67,7 @@ struct nvmem_cell_info { unsigned int nbits; struct device_node *np; nvmem_cell_post_process_t read_post_process; + void *priv; }; /** From patchwork Wed Mar 8 15:31:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66309 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp406862wrd; Wed, 8 Mar 2023 07:41:11 -0800 (PST) X-Google-Smtp-Source: AK7set+jCirbnduf/Sy5778vwQpJxbSlLVHvWEzb4n7fsriysvf0OxENaplNp3gA9N/NEZd17n1i X-Received: by 2002:a62:8406:0:b0:60e:950c:7a4f with SMTP id k6-20020a628406000000b0060e950c7a4fmr6325055pfd.8.1678290071190; Wed, 08 Mar 2023 07:41:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678290071; cv=none; d=google.com; s=arc-20160816; b=Kj28fQvjKLC/Rf8lJmcw83bdYonTyiYmjBScHFpRFL4y80L+yRFVhNFtKqoFItvC9f Mhp5xO7d2CsJXEoLdx8uh22dkfKqd7RlfHrwNv3JoHasyjOBXroFQVjiJrqa6jBjqkBv lAAuGweuy0uR1uMJ9d/IcTquFcE8KMUJGUO2XBQZ2HwC091qoLVR9ot9qRf/ySm8Ny0M z2XOUKDWgzVidvuNzCoTS6qlonxBZ1rvhUTdXD6I79MKM01dX/kr9wqzD+wQ6+UdtYUi 7nBdnztiA9+KVpkwIS367WquRWMy89uPp/Uuv3S6mUZaHF+lPf6VzVaN+ERRF/cxhz7k a9uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uFRM4PTDCSOdcU0u0521ZO4/N4DtV8C7SzDo9oGW8ew=; b=xxETSFd7fFyfUPBbz2B1MdhRfNGLFxzPMZ/5i2CEuKNj0+kfgXZucGdaZjEkqgzf/5 r0h9Xs14ZGIVwmHJW0wVqTMAKpGWz49E4g3ZrCXBfZ13xCV7MX4JtzVjjsNn5DZiaRau 21Ux1OvLrDbUyQnircu3o3VOF0nmVdZMr+DMLhJvN5A6a1dGUYW9iQyyQ4AitpobM+r6 a3kMt0OiN8JQGxzf29QXD4Y53ybg0aubso9oKUvwxKEtZ0/ToSWUH72W03y1hFcGQ/7I M06VvhH0ObnkzOFV91okW1jWIRrEyVli6E7ev5nWToLet/1HmKrE5KDGD/VKH3BlY9T2 8zCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=HDTqu1aO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id k12-20020aa7972c000000b005a48ecab9a1si16265311pfg.167.2023.03.08.07.40.53; Wed, 08 Mar 2023 07:41:11 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=HDTqu1aO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232233AbjCHPeH (ORCPT + 99 others); Wed, 8 Mar 2023 10:34:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230373AbjCHPdQ (ORCPT ); Wed, 8 Mar 2023 10:33:16 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1B615D27D; Wed, 8 Mar 2023 07:32:34 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id D4EE5FF80B; Wed, 8 Mar 2023 15:32:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289553; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uFRM4PTDCSOdcU0u0521ZO4/N4DtV8C7SzDo9oGW8ew=; b=HDTqu1aO76W96QPeSlXC+xNulblaWqYJGKz2A1FQJ/yAMOkbNggJv3qP45UZC1HJbFj10o Sxnno0CmOs0gZDGoNSbolBuCg1rrKw5YPFjb2reiyRqRcVQaeLxzh1D9nWqvMkuaKKXi7L Q3otWR0Ifn1ithhEwko0vXObmNNs5gPAwF/5/mC4MADfcIcBBF+unRpgrp2TJIaqJy49ZZ ykU6RP8MB8uoBuJqqAdTvG12BKSL4/Ny9hLKe5H5HdKYuhNBDzlPg9s1y4rw5XM0sDJxaB WYAm+EFd4JpuSh8b895PDWBe29m+d4YbAXUUW2qLV/PP0xhGOkwx0U3sBGJ/ng== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v3 17/20] nvmem: layouts: sl28vpd: Add new layout driver Date: Wed, 8 Mar 2023 16:31:57 +0100 Message-Id: <20230308153200.682248-18-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814690013538522?= X-GMAIL-MSGID: =?utf-8?q?1759814690013538522?= From: Michael Walle This layout applies to the VPD of the Kontron sl28 boards. The VPD only contains a base MAC address. Therefore, we have to add an individual offset to it. This is done by taking the second argument of the nvmem phandle into account. Also this let us checking the VPD version and the checksum. Signed-off-by: Michael Walle Signed-off-by: Miquel Raynal --- drivers/nvmem/layouts/Kconfig | 9 ++ drivers/nvmem/layouts/Makefile | 2 + drivers/nvmem/layouts/sl28vpd.c | 165 ++++++++++++++++++++++++++++++++ 3 files changed, 176 insertions(+) create mode 100644 drivers/nvmem/layouts/sl28vpd.c diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig index 9ad3911d1605..fd161347c129 100644 --- a/drivers/nvmem/layouts/Kconfig +++ b/drivers/nvmem/layouts/Kconfig @@ -2,4 +2,13 @@ menu "Layout Types" +config NVMEM_LAYOUT_SL28_VPD + tristate "Kontron sl28 VPD layout support" + select CRC8 + help + Say Y here if you want to support the VPD layout of the Kontron + SMARC-sAL28 boards. + + If unsure, say N. + endmenu diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile index 6fdb3c60a4fa..fc617b9e87d0 100644 --- a/drivers/nvmem/layouts/Makefile +++ b/drivers/nvmem/layouts/Makefile @@ -2,3 +2,5 @@ # # Makefile for nvmem layouts. # + +obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o diff --git a/drivers/nvmem/layouts/sl28vpd.c b/drivers/nvmem/layouts/sl28vpd.c new file mode 100644 index 000000000000..9370e41bad73 --- /dev/null +++ b/drivers/nvmem/layouts/sl28vpd.c @@ -0,0 +1,165 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include +#include +#include +#include +#include +#include + +#define SL28VPD_MAGIC 'V' + +struct sl28vpd_header { + u8 magic; + u8 version; +} __packed; + +struct sl28vpd_v1 { + struct sl28vpd_header header; + char serial_number[15]; + u8 base_mac_address[ETH_ALEN]; + u8 crc8; +} __packed; + +static int sl28vpd_mac_address_pp(void *priv, const char *id, int index, + unsigned int offset, void *buf, + size_t bytes) +{ + if (bytes != ETH_ALEN) + return -EINVAL; + + if (index < 0) + return -EINVAL; + + if (!is_valid_ether_addr(buf)) + return -EINVAL; + + eth_addr_add(buf, index); + + return 0; +} + +static const struct nvmem_cell_info sl28vpd_v1_entries[] = { + { + .name = "serial-number", + .offset = offsetof(struct sl28vpd_v1, serial_number), + .bytes = sizeof_field(struct sl28vpd_v1, serial_number), + }, + { + .name = "base-mac-address", + .offset = offsetof(struct sl28vpd_v1, base_mac_address), + .bytes = sizeof_field(struct sl28vpd_v1, base_mac_address), + .read_post_process = sl28vpd_mac_address_pp, + }, +}; + +static int sl28vpd_v1_check_crc(struct device *dev, struct nvmem_device *nvmem) +{ + struct sl28vpd_v1 data_v1; + u8 table[CRC8_TABLE_SIZE]; + int ret; + u8 crc; + + crc8_populate_msb(table, 0x07); + + ret = nvmem_device_read(nvmem, 0, sizeof(data_v1), &data_v1); + if (ret < 0) + return ret; + else if (ret != sizeof(data_v1)) + return -EIO; + + crc = crc8(table, (void *)&data_v1, sizeof(data_v1) - 1, 0); + + if (crc != data_v1.crc8) { + dev_err(dev, + "Checksum is invalid (got %02x, expected %02x).\n", + crc, data_v1.crc8); + return -EINVAL; + } + + return 0; +} + +static int sl28vpd_add_cells(struct device *dev, struct nvmem_device *nvmem, + struct nvmem_layout *layout) +{ + const struct nvmem_cell_info *pinfo; + struct nvmem_cell_info info = {0}; + struct device_node *layout_np; + struct sl28vpd_header hdr; + int ret, i; + + /* check header */ + ret = nvmem_device_read(nvmem, 0, sizeof(hdr), &hdr); + if (ret < 0) + return ret; + else if (ret != sizeof(hdr)) + return -EIO; + + if (hdr.magic != SL28VPD_MAGIC) { + dev_err(dev, "Invalid magic value (%02x)\n", hdr.magic); + return -EINVAL; + } + + if (hdr.version != 1) { + dev_err(dev, "Version %d is unsupported.\n", hdr.version); + return -EINVAL; + } + + ret = sl28vpd_v1_check_crc(dev, nvmem); + if (ret) + return ret; + + layout_np = of_nvmem_layout_get_container(nvmem); + if (!layout_np) + return -ENOENT; + + for (i = 0; i < ARRAY_SIZE(sl28vpd_v1_entries); i++) { + pinfo = &sl28vpd_v1_entries[i]; + + info.name = pinfo->name; + info.offset = pinfo->offset; + info.bytes = pinfo->bytes; + info.read_post_process = pinfo->read_post_process; + info.np = of_get_child_by_name(layout_np, pinfo->name); + + ret = nvmem_add_one_cell(nvmem, &info); + if (ret) { + of_node_put(layout_np); + return ret; + } + } + + of_node_put(layout_np); + + return 0; +} + +static const struct of_device_id sl28vpd_of_match_table[] = { + { .compatible = "kontron,sl28-vpd" }, + {}, +}; +MODULE_DEVICE_TABLE(of, sl28vpd_of_match_table); + +struct nvmem_layout sl28vpd_layout = { + .name = "sl28-vpd", + .of_match_table = sl28vpd_of_match_table, + .add_cells = sl28vpd_add_cells, +}; + +static int __init sl28vpd_init(void) +{ + return nvmem_layout_register(&sl28vpd_layout); +} + +static void __exit sl28vpd_exit(void) +{ + nvmem_layout_unregister(&sl28vpd_layout); +} + +module_init(sl28vpd_init); +module_exit(sl28vpd_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Michael Walle "); +MODULE_DESCRIPTION("NVMEM layout driver for the VPD of Kontron sl28 boards"); From patchwork Wed Mar 8 15:31:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66300 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp404272wrd; Wed, 8 Mar 2023 07:36:07 -0800 (PST) X-Google-Smtp-Source: AK7set8U+cEJToR23FJW2cSguCwOmB1grj+WZLOjmLh2f8FAjRFMzZ4RUSjROTWAiIktp1nhlCpU X-Received: by 2002:a17:90b:1d90:b0:233:cd29:f168 with SMTP id pf16-20020a17090b1d9000b00233cd29f168mr19376173pjb.24.1678289766876; Wed, 08 Mar 2023 07:36:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678289766; cv=none; d=google.com; s=arc-20160816; b=zXtnanaPmDSjXEMGApgodcKqgk68j7gCn2ZNe9lXlXHouLqH4nn1HjxUFvM+pA8Qs4 jDMZkzTblbHpOgssYwNzRh5H5VqdJOIV5dshNlR0I331IvRsBWYpuC6I0zR/LuOcGoX1 YJsVbpvHJlB7WTjIKVnOzOKw8AjoVXkim6gTFZQXs7orJGMCty7grkjK3vgOaopngaSx cNaJiOCfJ1r69cHyE6LGa8x1o2/qGjMY4r1ZnDo/yzAvMIVegxAR/BQyfVHttsXsdpnv 7Mbw0YHpE2K3hSrL0Ay+6u/4KW2f5NpKvFb2UF/zdU0ZPMVYSbtmzGOcaji5Tr2ab0wE L8fw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=BNQ3sTpjQyMvjHFTjnQEONu0j45V03HRSLfLQ6vGys0=; b=fqxFrMjuQrhslkvySe3zA9m1t8B1GKQIBIOaTwtCqhFgEPl4C4dhg2hTZ5Bo/n2FbW FJxw9InkURJejrK2s5J/wC0uX/CkC4PJBr5o3O1kqwmy7ndiA2gqInzHUzKkvp/SeD/+ SXEFG4+47nAjOIyQtBY05yjbd8w09X6TQ/rhhX6WxN8JTDrGOdvqOj0jkkPRkUZxRKBp r3TYSJispft4Nj+JfrPi2TvLy020dQxEUwK8Jwh+yDSjvsKm85iEy74Tur+0STvu7XMb ElHDcg0A9hhSn8mAbK2EAsQWh9ILAn5Fe5KJNUTTFeKFlcKZncUsx8q6+eEnFz1M680z y/Qg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=SVuA4pTk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id c22-20020a17090a8d1600b002340b11f1e8si14901415pjo.44.2023.03.08.07.35.49; Wed, 08 Mar 2023 07:36:06 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=SVuA4pTk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232193AbjCHPeE (ORCPT + 99 others); Wed, 8 Mar 2023 10:34:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232088AbjCHPdL (ORCPT ); Wed, 8 Mar 2023 10:33:11 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1F9D85D268; Wed, 8 Mar 2023 07:32:35 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 9992DFF805; Wed, 8 Mar 2023 15:32:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289554; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BNQ3sTpjQyMvjHFTjnQEONu0j45V03HRSLfLQ6vGys0=; b=SVuA4pTkUs2qlK1ugOOMOi2u7xla/tp5W0FRCKFj09IicxtsSqRyH6yj/ZXMOvDGbFznWl 7SCqvHAeiQFm7z+sQYqswmWUP9pytj1ZeI32qfVwrxf9s91QF6kwdzwsW2MJlZzn9Naadj uZ1sbhyQQXaGVQy1C0tgD/C3j7TBjTcQyuu614Uk9mLQPZnpNRiwJc+gKDKKNA6WIbf0ne vRJeo2OaWcxOKbYG2CGD3ttJATvLzOTZXpmE2P4AfgFY1sPZqzF5nLbOufOpzzeR2cTFqG wdPRXGat17PDZxkc3UH9JYT2Bwrk3iAUew7uPrSMQPecuEZbTW5oZvKd6ioSNw== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v3 18/20] MAINTAINERS: add myself as sl28vpd nvmem layout driver Date: Wed, 8 Mar 2023 16:31:58 +0100 Message-Id: <20230308153200.682248-19-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814370097833968?= X-GMAIL-MSGID: =?utf-8?q?1759814370097833968?= From: Michael Walle Add myself as a maintainer for the new sl28vpd nvmem layout driver. Signed-off-by: Michael Walle Signed-off-by: Miquel Raynal --- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 8d5bc223f305..60ed770b0212 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19184,6 +19184,12 @@ F: drivers/irqchip/irq-sl28cpld.c F: drivers/pwm/pwm-sl28cpld.c F: drivers/watchdog/sl28cpld_wdt.c +SL28 VPD NVMEM LAYOUT DRIVER +M: Michael Walle +S: Maintained +F: Documentation/devicetree/bindings/nvmem/layouts/kontron,sl28-vpd.yaml +F: drivers/nvmem/layouts/sl28vpd.c + SLAB ALLOCATOR M: Christoph Lameter M: Pekka Enberg From patchwork Wed Mar 8 15:31:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66301 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp404422wrd; Wed, 8 Mar 2023 07:36:23 -0800 (PST) X-Google-Smtp-Source: AK7set/wbIt1SO/t4TAoXlZyqrfXhMf+dBvqXAU+IQdtwNlNGXVnXRTHAzkiXcsTISGyt3OfdL4a X-Received: by 2002:a17:902:da87:b0:199:3a4a:d702 with SMTP id j7-20020a170902da8700b001993a4ad702mr22401670plx.0.1678289783580; Wed, 08 Mar 2023 07:36:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678289783; cv=none; d=google.com; s=arc-20160816; b=v6kSFozR33/aceR78Bo0TloMeoBtvLzZMnav5q9JZ0V7a1/Huq2w6QR61dOwQtbKnU mJf/9UXEFOtASMhZDJDI2N+zyGIBrDcm8k33en/aLdvcCHA95BsG7+elc2t+SnYhYm+7 aXcTAXaDok7435svVC/5XxSG0ubcNtpzGXZVYgJw2D7nyc7xvFZLebCzabCpOhHYzK67 St3HzDbF7IVff/EzfUXW1knDtVYFqmtgtQtBllOxPW/96BZgS6p2PvReOSQ5LieFy9zx j7Mnl4PgJCtq/6GSa2dMJgpfAJRC7XRxP+k9q3I55jx+a1PN5QP6MME8zuLJ80EZZWnv cinw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=5r6F0YpgjdYq8KoLnNlw94ikIMFZ53LzHkMcfFlQ/Ds=; b=QuBAldhE8UiMeaNClHSjgTFy2tVQvKonpjK62EqHnR5aG1k4Gfd0zB+2R1IcjNzyT6 vZFIgmD3yyrHwhjAAscxIGxUCBho65wpObOu2fn8Cyn/tU+v+AJ/jWQPwultN+jsiVS4 OWgJu+P+FlG0u1mUOrMbSKnt8GEX1q+JGya9COu1wdfJs3SWkhsRQ1/qKB0ibi5PBsaM 908Qx1DXEHBEYlvBip4Un7zaQiCAsgDrA1BsJbXzJk/TwdNWJLpBdI/NkIBTr2S65DpE QRmM6U6JT5yj56BQu21XmfQ4dsUalvPBI2r15orGhJaNXc/cZm2DN9k9ddS0QtulZN9l 8kaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Ztv117Nc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bj10-20020a170902850a00b001842f465c10si13954366plb.438.2023.03.08.07.36.07; Wed, 08 Mar 2023 07:36:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Ztv117Nc; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232295AbjCHPeK (ORCPT + 99 others); Wed, 8 Mar 2023 10:34:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232221AbjCHPdX (ORCPT ); Wed, 8 Mar 2023 10:33:23 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 185BAC8595; Wed, 8 Mar 2023 07:32:37 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 03FA7FF815; Wed, 8 Mar 2023 15:32:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289556; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5r6F0YpgjdYq8KoLnNlw94ikIMFZ53LzHkMcfFlQ/Ds=; b=Ztv117NcOQBgIOiKMHslcvn+FV0kg8rE/DGB3dUMMdMSyU5Hj7yDOBakM/2rQTfTzJsvZc Dh2jbLXYQg+odtHc3t689nMZwe4A74CON2JAL2kyIp5bZuXPQ/yt9tnZiW4ghttiqBnp5L nXx4en46M9pZ6aYh4xolZYlpjvHq7vJC6R6RXxiKPKAfZLrdWQb7pJKLfpfDUoX2ue8hx+ weNtPpxcP46GwDFZUrv94xpuo4uyxy/LxJdTIEKG4p64MuD+BGR/WZVlfUwHfLnbPyd8wh onYZudRDmAlX+aGNpyYcIsq7g6mTBGJrFouLCLUjgej0Z1N9FB6IiLFOaJQcHw== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v3 19/20] nvmem: layouts: onie-tlv: Add new layout driver Date: Wed, 8 Mar 2023 16:31:59 +0100 Message-Id: <20230308153200.682248-20-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814387974029107?= X-GMAIL-MSGID: =?utf-8?q?1759814387974029107?= This layout applies on top of any non volatile storage device containing an ONIE table factory flashed. This table follows the tlv (type-length-value) organization described in the link below. We cannot afford using regular parsers because the content of these tables is manufacturer specific and must be dynamically discovered. Link: https://opencomputeproject.github.io/onie/design-spec/hw_requirements.html Signed-off-by: Miquel Raynal --- drivers/nvmem/layouts/Kconfig | 9 ++ drivers/nvmem/layouts/Makefile | 1 + drivers/nvmem/layouts/onie-tlv.c | 257 +++++++++++++++++++++++++++++++ 3 files changed, 267 insertions(+) create mode 100644 drivers/nvmem/layouts/onie-tlv.c diff --git a/drivers/nvmem/layouts/Kconfig b/drivers/nvmem/layouts/Kconfig index fd161347c129..7ff1ee1c1f05 100644 --- a/drivers/nvmem/layouts/Kconfig +++ b/drivers/nvmem/layouts/Kconfig @@ -11,4 +11,13 @@ config NVMEM_LAYOUT_SL28_VPD If unsure, say N. +config NVMEM_LAYOUT_ONIE_TLV + tristate "ONIE tlv support" + select CRC32 + help + Say Y here if you want to support the Open Compute Project ONIE + Type-Length-Value standard table. + + If unsure, say N. + endmenu diff --git a/drivers/nvmem/layouts/Makefile b/drivers/nvmem/layouts/Makefile index fc617b9e87d0..2974bd7d33ed 100644 --- a/drivers/nvmem/layouts/Makefile +++ b/drivers/nvmem/layouts/Makefile @@ -4,3 +4,4 @@ # obj-$(CONFIG_NVMEM_LAYOUT_SL28_VPD) += sl28vpd.o +obj-$(CONFIG_NVMEM_LAYOUT_ONIE_TLV) += onie-tlv.o diff --git a/drivers/nvmem/layouts/onie-tlv.c b/drivers/nvmem/layouts/onie-tlv.c new file mode 100644 index 000000000000..d45b7301a69d --- /dev/null +++ b/drivers/nvmem/layouts/onie-tlv.c @@ -0,0 +1,257 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * ONIE tlv NVMEM cells provider + * + * Copyright (C) 2022 Open Compute Group ONIE + * Author: Miquel Raynal + * Based on the nvmem driver written by: Vadym Kochan + * Inspired by the first layout written by: Rafał Miłecki + */ + +#include +#include +#include +#include +#include + +#define ONIE_TLV_MAX_LEN 2048 +#define ONIE_TLV_CRC_FIELD_SZ 6 +#define ONIE_TLV_CRC_SZ 4 +#define ONIE_TLV_HDR_ID "TlvInfo" + +struct onie_tlv_hdr { + u8 id[8]; + u8 version; + __be16 data_len; +} __packed; + +struct onie_tlv { + u8 type; + u8 len; +} __packed; + +static const char *onie_tlv_cell_name(u8 type) +{ + switch (type) { + case 0x21: + return "product-name"; + case 0x22: + return "part-number"; + case 0x23: + return "serial-number"; + case 0x24: + return "mac-address"; + case 0x25: + return "manufacture-date"; + case 0x26: + return "device-version"; + case 0x27: + return "label-revision"; + case 0x28: + return "platform-name"; + case 0x29: + return "onie-version"; + case 0x2A: + return "num-macs"; + case 0x2B: + return "manufacturer"; + case 0x2C: + return "country-code"; + case 0x2D: + return "vendor"; + case 0x2E: + return "diag-version"; + case 0x2F: + return "service-tag"; + case 0xFD: + return "vendor-extension"; + case 0xFE: + return "crc32"; + default: + break; + } + + return NULL; +} + +static int onie_tlv_mac_read_cb(void *priv, const char *id, int index, + unsigned int offset, void *buf, + size_t bytes) +{ + eth_addr_add(buf, index); + + return 0; +} + +static nvmem_cell_post_process_t onie_tlv_read_cb(u8 type, u8 *buf) +{ + switch (type) { + case 0x24: + return &onie_tlv_mac_read_cb; + default: + break; + } + + return NULL; +} + +static int onie_tlv_add_cells(struct device *dev, struct nvmem_device *nvmem, + size_t data_len, u8 *data) +{ + struct nvmem_cell_info cell = {}; + struct device_node *layout; + struct onie_tlv tlv; + unsigned int hdr_len = sizeof(struct onie_tlv_hdr); + unsigned int offset = 0; + int ret; + + layout = of_nvmem_layout_get_container(nvmem); + if (!layout) + return -ENOENT; + + while (offset < data_len) { + memcpy(&tlv, data + offset, sizeof(tlv)); + if (offset + tlv.len >= data_len) { + dev_err(dev, "Out of bounds field (0x%x bytes at 0x%x)\n", + tlv.len, hdr_len + offset); + break; + } + + cell.name = onie_tlv_cell_name(tlv.type); + if (!cell.name) + continue; + + cell.offset = hdr_len + offset + sizeof(tlv.type) + sizeof(tlv.len); + cell.bytes = tlv.len; + cell.np = of_get_child_by_name(layout, cell.name); + cell.read_post_process = onie_tlv_read_cb(tlv.type, data + offset + sizeof(tlv)); + + ret = nvmem_add_one_cell(nvmem, &cell); + if (ret) { + of_node_put(layout); + return ret; + } + + offset += sizeof(tlv) + tlv.len; + } + + of_node_put(layout); + + return 0; +} + +static bool onie_tlv_hdr_is_valid(struct device *dev, struct onie_tlv_hdr *hdr) +{ + if (memcmp(hdr->id, ONIE_TLV_HDR_ID, sizeof(hdr->id))) { + dev_err(dev, "Invalid header\n"); + return false; + } + + if (hdr->version != 0x1) { + dev_err(dev, "Invalid version number\n"); + return false; + } + + return true; +} + +static bool onie_tlv_crc_is_valid(struct device *dev, size_t table_len, u8 *table) +{ + struct onie_tlv crc_hdr; + u32 read_crc, calc_crc; + __be32 crc_be; + + memcpy(&crc_hdr, table + table_len - ONIE_TLV_CRC_FIELD_SZ, sizeof(crc_hdr)); + if (crc_hdr.type != 0xfe || crc_hdr.len != ONIE_TLV_CRC_SZ) { + dev_err(dev, "Invalid CRC field\n"); + return false; + } + + /* The table contains a JAMCRC, which is XOR'ed compared to the original + * CRC32 implementation as known in the Ethernet world. + */ + memcpy(&crc_be, table + table_len - ONIE_TLV_CRC_SZ, ONIE_TLV_CRC_SZ); + read_crc = be32_to_cpu(crc_be); + calc_crc = crc32(~0, table, table_len - ONIE_TLV_CRC_SZ) ^ 0xFFFFFFFF; + if (read_crc != calc_crc) { + dev_err(dev, "Invalid CRC read: 0x%08x, expected: 0x%08x\n", + read_crc, calc_crc); + return false; + } + + return true; +} + +static int onie_tlv_parse_table(struct device *dev, struct nvmem_device *nvmem, + struct nvmem_layout *layout) +{ + struct onie_tlv_hdr hdr; + size_t table_len, data_len, hdr_len; + u8 *table, *data; + int ret; + + ret = nvmem_device_read(nvmem, 0, sizeof(hdr), &hdr); + if (ret < 0) + return ret; + + if (!onie_tlv_hdr_is_valid(dev, &hdr)) { + dev_err(dev, "Invalid ONIE TLV header\n"); + return -EINVAL; + } + + hdr_len = sizeof(hdr.id) + sizeof(hdr.version) + sizeof(hdr.data_len); + data_len = be16_to_cpu(hdr.data_len); + table_len = hdr_len + data_len; + if (table_len > ONIE_TLV_MAX_LEN) { + dev_err(dev, "Invalid ONIE TLV data length\n"); + return -EINVAL; + } + + table = devm_kmalloc(dev, table_len, GFP_KERNEL); + if (!table) + return -ENOMEM; + + ret = nvmem_device_read(nvmem, 0, table_len, table); + if (ret != table_len) + return ret; + + if (!onie_tlv_crc_is_valid(dev, table_len, table)) + return -EINVAL; + + data = table + hdr_len; + ret = onie_tlv_add_cells(dev, nvmem, data_len, data); + if (ret) + return ret; + + return 0; +} + +static const struct of_device_id onie_tlv_of_match_table[] = { + { .compatible = "onie,tlv-layout", }, + {}, +}; +MODULE_DEVICE_TABLE(of, onie_tlv_of_match_table); + +static struct nvmem_layout onie_tlv_layout = { + .name = "ONIE tlv layout", + .of_match_table = onie_tlv_of_match_table, + .add_cells = onie_tlv_parse_table, +}; + +static int __init onie_tlv_init(void) +{ + return nvmem_layout_register(&onie_tlv_layout); +} + +static void __exit onie_tlv_exit(void) +{ + nvmem_layout_unregister(&onie_tlv_layout); +} + +module_init(onie_tlv_init); +module_exit(onie_tlv_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Miquel Raynal "); +MODULE_DESCRIPTION("NVMEM layout driver for Onie TLV table parsing"); +MODULE_ALIAS("NVMEM layout driver for Onie TLV table parsing"); From patchwork Wed Mar 8 15:32:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 66314 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp407440wrd; Wed, 8 Mar 2023 07:42:17 -0800 (PST) X-Google-Smtp-Source: AK7set/A+H+bmlwlUHTKpWxd2sBwWmdXD942EneWPfPFclmwjSxItgUdLYJetSbNyVA0iAuTx0cu X-Received: by 2002:a17:903:32d2:b0:19b:441c:3913 with SMTP id i18-20020a17090332d200b0019b441c3913mr21840854plr.44.1678290137654; Wed, 08 Mar 2023 07:42:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678290137; cv=none; d=google.com; s=arc-20160816; b=Es9uBU09RzSPTE+1EAfF2z2zyjyYE8E+m1sRMxYoOjNQIgUvHNHyp3Ytrn9yO0gvof ltH/nLWeG43CcaeZ6Ch7D+mc9Hd4+ssTKUSOjeGm0QYhyBMRVMYyE4Lgp+ZIgvQr3mal McpiG4cggtiPgfziD/6pDdDYwGm3cxs8Y6K4uAOaVfreCiCTVH99DnsMGewZ7uHOqdeJ S5FBOoz6qNweJVYvXS3Gmtd6KKllsur+dkVNrW3SzFYAltSkjbB51S8qFw0b7LW4MMkF WgTFctcIf7QWEs64cvaFTxi4T4iIvfULH3WFj1t8aouxO4ADGgmThd1N8DU9mLhckTyG PEvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=XyICmylP7PDUApTv+q/07vUt9nI5bdRkLXudAMFgC28=; b=VL+12xjgNeNXnEDTk/+FcI+mQj+2bCqZk/1ViNZW42TEMmvYxnJamRilrUjko/3TjO mRZCzLkCYBFU3cnljbM4v7KpHZlWnXJX6OECpBMPBu6GIEtMIje7nhdLpcxHHN8mjEPK 7jsT6upWKj9ZK9zzVCltLoDjkWk//f2+446YN++7PBqVSs97yC6d6yKMz2mevGwDq56J cWUpzreugnf/ft+SoNQ+bIOBOYeIAZcFbE2prvYEewQiz224cjx2DK+c7rIQ5mNkUXH5 PsWQEWCdCfL6ON5nZfoe64mH7yJ4JSMXSLxsGlWkV0zqp6/XQ/OEIutXKEILANf360aJ 0ezw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=bKlS9q19; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x69-20020a638648000000b00502d650cfa2si14580888pgd.811.2023.03.08.07.42.04; Wed, 08 Mar 2023 07:42:17 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=bKlS9q19; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231651AbjCHPeR (ORCPT + 99 others); Wed, 8 Mar 2023 10:34:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231528AbjCHPd2 (ORCPT ); Wed, 8 Mar 2023 10:33:28 -0500 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5EA135D27C; Wed, 8 Mar 2023 07:32:39 -0800 (PST) Received: (Authenticated sender: miquel.raynal@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id BDA28FF81D; Wed, 8 Mar 2023 15:32:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1678289557; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=XyICmylP7PDUApTv+q/07vUt9nI5bdRkLXudAMFgC28=; b=bKlS9q1921Sq3Bj8UY1Rb7cKzUzLjNl/vjj+XTmKeZuoHEU4q5nE18hZL7vr548/nGiUiP Eh3f7mvX9jwh5ABpvmNKOOXvbMPI+EnGHyJlyIj8gPDLiMs3H8PJl2kHAC6qaKexJP+33R EkVNXVH/3hw3F6Q/BIb6fKA0EtkBTM9RH87YuOGWuCV0i4/v5HKTSY9K7ItDp4FQ7d6KV7 k5IdUHXFSPcpDmHvAUiIVaJjHW2tBJoWNr0Id/7B/aV9ksNrx/OvQIf/rLEYt4RnfXv6qT eTyFteqvTpjH0xna1C9eegKiwPNfnTX2nfQ2pCta8+OhiBgLCU4poJaod4avWw== From: Miquel Raynal To: Srinivas Kandagatla , Cc: Greg Kroah-Hartman , Michael Walle , =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Robert Marko , Luka Perkov , Thomas Petazzoni , Rob Herring , Frank Rowand , devicetree@vger.kernel.org, Miquel Raynal Subject: [PATCH v3 20/20] MAINTAINERS: Add myself as ONIE tlv NVMEM layout maintainer Date: Wed, 8 Mar 2023 16:32:00 +0100 Message-Id: <20230308153200.682248-21-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230308153200.682248-1-miquel.raynal@bootlin.com> References: <20230308153200.682248-1-miquel.raynal@bootlin.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759814759705768788?= X-GMAIL-MSGID: =?utf-8?q?1759814759705768788?= Following the introduction of the bindings for this NVMEM parser and the layout driver, add myself as maintainer. Signed-off-by: Miquel Raynal --- MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index 60ed770b0212..3a53f9d5ac56 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -15550,6 +15550,12 @@ L: linux-hwmon@vger.kernel.org S: Maintained F: drivers/hwmon/oxp-sensors.c +ONIE TLV NVMEM LAYOUT DRIVER +M: Miquel Raynal +S: Maintained +F: Documentation/devicetree/bindings/nvmem/layouts/onie,tlv-layout.yaml +F: drivers/nvmem/layouts/onie-tlv.c + ONION OMEGA2+ BOARD M: Harvey Hunt L: linux-mips@vger.kernel.org