From patchwork Mon Feb 6 10:05:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QXLEsW7DpyDDnE5BTA==?= X-Patchwork-Id: 13129586 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8C504C61DA4 for ; Mon, 6 Feb 2023 10:06:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229838AbjBFKG0 (ORCPT ); Mon, 6 Feb 2023 05:06:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230212AbjBFKF6 (ORCPT ); Mon, 6 Feb 2023 05:05:58 -0500 Received: from mail-ej1-x62e.google.com (mail-ej1-x62e.google.com [IPv6:2a00:1450:4864:20::62e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D2D193F4; Mon, 6 Feb 2023 02:05:16 -0800 (PST) Received: by mail-ej1-x62e.google.com with SMTP id m2so32588378ejb.8; Mon, 06 Feb 2023 02:05:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Gqf1vCXAbzOf8WDTZTA0pRXwIBMxs7RLBp7o8lAX0PU=; b=T/BkKnXItAdLlJcLNUMa+VCEdmv6AMdP0dWS0Of5OxiLbWBVgnVYIECIo6c4MYN47H g07qpZLpDfvrFdME3IiSyDfrdO+nKnoc2wP2GNGGzi2Gpt/1C+MdoYydbc+AHnDq6llK Ibt5bSqGyn75c/DvpwlAAAaR7/ueJdl12v4G2HAaQXD4iAP+tpNVWsiFvCYl3czcy7zm C/mheRhfSuXWdl9r8yyMu6sjpeyMZuOq4lYtzBUkZ+TkHnwZcLbn22kgDOWDo2rwqwMD 2ChYMIagNBEEAjPE/6C/karJX0/R8mWFcAXkRp+zxig32eruF3TvopdD/AYuYmvZGAyb Vc1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Gqf1vCXAbzOf8WDTZTA0pRXwIBMxs7RLBp7o8lAX0PU=; b=7VPThdA8GwGXYwBrzGZzyY7O8FKsJm4Y9QYNZtp7Z2H+8hJIuONNz4PPiAwi9NDU6T jCIv5nwwLyCWBNEnPwUb2IBkQcHf9fuy7+PKX2Ou2F5ItRpn1A7ixVAl++u8/9aNUZHc tJb9i1KqEh7Bw/pU/wXsSQzmafTAyKTjfqVDmcAcWxtMJkSiSKe20c88wLuI8nqVmNse oq8+3t9r/CwPi3zG9qO+O93t35oZg38a/UGnTPJCvbsx/vHiL+IKQUmf4a+4/v1KWEUh 9hBWBcLSksmpQ/wIA32Cb99gPcyNOK3wOUk4wfwAsdtHtz31Gna2Kpnlpk/bYpPIiUNq Euaw== X-Gm-Message-State: AO0yUKXt/cvFC5IguPnpwePe/Qd7hZQYswRhYRB1UvvwFc128iuHkb3d +DjhMLFF5Yo1Bl3M08Qm0nc= X-Google-Smtp-Source: AK7set+dLPcd5QuiLWBH7phQh03dPTamLJPxtAgvDwcz5xmNJIQ3hFiqOl4bmWdL30CfeqcEyDuZLA== X-Received: by 2002:a17:907:94c2:b0:88d:ba89:1851 with SMTP id dn2-20020a17090794c200b0088dba891851mr16848475ejc.34.1675677914683; Mon, 06 Feb 2023 02:05:14 -0800 (PST) Received: from arinc9-PC.lan ([37.120.152.236]) by smtp.gmail.com with ESMTPSA id s19-20020a1709067b9300b008878909859bsm5240746ejo.152.2023.02.06.02.05.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 02:05:14 -0800 (PST) From: Willem-Jan de Hoog X-Google-Original-From: Willem-Jan de Hoog To: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Srinivas Kandagatla , Linus Walleij , Willem-Jan de Hoog , Florian Fainelli Cc: =?utf-8?b?QXLEsW7DpyDDnE5BTA==?= , =?utf-8?b?UmFm?= =?utf-8?b?YcWCIE1pxYJlY2tp?= , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, erkin.bozoglu@xeront.com Subject: [PATCH 1/2] firmware: bcm47xx_nvram: allow to read from buffered nvram data Date: Mon, 6 Feb 2023 13:05:01 +0300 Message-Id: <20230206100502.20243-2-wdehoog@exalondelft.nl> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230206100502.20243-1-wdehoog@exalondelft.nl> References: <20230206100502.20243-1-wdehoog@exalondelft.nl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org The bcm47xx code makes a copy of the NVRAM data in ram. Allow access to this data so property values can be read using nvmem cell api. [ arinc.unal: Improved patch subject and log ] Signed-off-by: Willem-Jan de Hoog Signed-off-by: Arınç ÜNAL --- drivers/firmware/broadcom/bcm47xx_nvram.c | 14 ++++++++++++++ include/linux/bcm47xx_nvram.h | 6 ++++++ 2 files changed, 20 insertions(+) diff --git a/drivers/firmware/broadcom/bcm47xx_nvram.c b/drivers/firmware/broadcom/bcm47xx_nvram.c index 5f47dbf4889a..7e5c62dc702f 100644 --- a/drivers/firmware/broadcom/bcm47xx_nvram.c +++ b/drivers/firmware/broadcom/bcm47xx_nvram.c @@ -182,6 +182,20 @@ static int nvram_init(void) return -ENXIO; } +int bcm47xx_nvram_read(unsigned int offset, char *val, size_t val_len) +{ + if (!nvram_len) + return -ENXIO; + + if ((offset+val_len) > nvram_len) + return -EINVAL; + + while (val_len--) + *val++ = nvram_buf[offset++]; + + return 0; +} + int bcm47xx_nvram_getenv(const char *name, char *val, size_t val_len) { char *var, *value, *end, *eq; diff --git a/include/linux/bcm47xx_nvram.h b/include/linux/bcm47xx_nvram.h index 7615f8d7b1ed..b265b8ce6434 100644 --- a/include/linux/bcm47xx_nvram.h +++ b/include/linux/bcm47xx_nvram.h @@ -20,6 +20,7 @@ static inline void bcm47xx_nvram_release_contents(char *nvram) { vfree(nvram); }; +int bcm47xx_nvram_read(unsigned int offset, char *val, size_t val_len); #else static inline int bcm47xx_nvram_init_from_iomem(void __iomem *nvram_start, size_t res_size) @@ -48,6 +49,11 @@ static inline char *bcm47xx_nvram_get_contents(size_t *val_len) static inline void bcm47xx_nvram_release_contents(char *nvram) { }; + +static inline int bcm47xx_nvram_read(unsigned int offset, char *val, size_t val_len) +{ + return -ENOTSUPP; +}: #endif #endif /* __BCM47XX_NVRAM_H */ From patchwork Mon Feb 6 10:05:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?QXLEsW7DpyDDnE5BTA==?= X-Patchwork-Id: 13129585 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1A579C636D6 for ; Mon, 6 Feb 2023 10:06:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229698AbjBFKGU (ORCPT ); Mon, 6 Feb 2023 05:06:20 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229756AbjBFKF7 (ORCPT ); Mon, 6 Feb 2023 05:05:59 -0500 Received: from mail-ej1-x635.google.com (mail-ej1-x635.google.com [IPv6:2a00:1450:4864:20::635]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 770E4EF9E; Mon, 6 Feb 2023 02:05:17 -0800 (PST) Received: by mail-ej1-x635.google.com with SMTP id m2so32588531ejb.8; Mon, 06 Feb 2023 02:05:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=rdavTuFd5AwgKTjsKFAoVHcxbRzSLlR1vkVVIhc1i+o=; b=Z2XpNek6T0AAlQCiIBmQrR6dbMJKGGwZ3HtzOvrrOy7uFUA13MgzAoatrw0Tp0CoHP zA4nStYfmBprLOAlobHxFwprnulsOa5fI0wh08DHe1aQJpaaV7nzn6dYxO0icbUp3RPL r7sQw3FhPPxV+V3aFMQCSqetzVV/svcA/S1wmTPD4w2DHpPMO8TclLaPDEXPYWfqvH51 +nkCWRhGzEGrMs12xqK3yabGNOxmWygJJiEm40754N+tY+0NdLv8m9ThyWmEzK2DL2Ws QVmeCK/xfTpIRXrHPrOaesfMEzzWHb0KpEn/Io6SLbEnBWjhZkPVierQDqvtolwpHbYP 1JsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=rdavTuFd5AwgKTjsKFAoVHcxbRzSLlR1vkVVIhc1i+o=; b=p5skGuMEfgGtVoSydHhPYhFkrUBIhOrHZyQT7uV/PkWd3VBoD7sIntL1rjnWQnN08F ICh6G23S9OktlDqm9wsFVHG82vK4GOgBT33UORiU3H91SY5KavUx47WRxWk2niEfiw0w 67yGOZ/5O1HD1mA+MfiuSa9ATiNsoMerW1CZMsjkECdJx2Rd6XGXHq4VQLsIUtQ1PquZ gPlgA5fWRqOmqNF1idSLcWkU1sr87g2aQQzc/9AdpK+6vR6H3a47/FN2FxEYXjOsTyCA 9DA2T+AAztWX1eTXtJQa3zrq2EyJSN302A360eScpphYw4Om0AJ8U5jYbf1IT8ooGGNo Xu8Q== X-Gm-Message-State: AO0yUKWjPDPLDymcjDsDnq4g5LJWJVu9eqrFoqkwDSjZmLV7SCIws6+x kZbvHAhLycmqdHW6weijbNo= X-Google-Smtp-Source: AK7set97+m7/pbYVZc5ri1mu7vQ583KJV+OuDLG/4UCVkd1WhW9CT5U9r6aa7wgq9qyiV8sl0+533g== X-Received: by 2002:a17:906:3192:b0:889:58bd:88a3 with SMTP id 18-20020a170906319200b0088958bd88a3mr20136037ejy.68.1675677915928; Mon, 06 Feb 2023 02:05:15 -0800 (PST) Received: from arinc9-PC.lan ([37.120.152.236]) by smtp.gmail.com with ESMTPSA id s19-20020a1709067b9300b008878909859bsm5240746ejo.152.2023.02.06.02.05.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Feb 2023 02:05:15 -0800 (PST) From: Willem-Jan de Hoog X-Google-Original-From: Willem-Jan de Hoog To: =?utf-8?b?UmFmYcWCIE1pxYJlY2tp?= , Srinivas Kandagatla , Linus Walleij , Willem-Jan de Hoog , Florian Fainelli Cc: =?utf-8?b?QXLEsW7DpyDDnE5BTA==?= , =?utf-8?b?UmFm?= =?utf-8?b?YcWCIE1pxYJlY2tp?= , linux-mips@vger.kernel.org, linux-kernel@vger.kernel.org, erkin.bozoglu@xeront.com Subject: [PATCH 2/2] nvmem: brcm_nvram: use bcm47xx buffered data Date: Mon, 6 Feb 2023 13:05:02 +0300 Message-Id: <20230206100502.20243-3-wdehoog@exalondelft.nl> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230206100502.20243-1-wdehoog@exalondelft.nl> References: <20230206100502.20243-1-wdehoog@exalondelft.nl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mips@vger.kernel.org The bcm47xx module has a copy of the NVRAM data in ram. When available, use this one instead of reading from io memory since it causes mtd/ubi to fail. [ arinc.unal: Improved patch subject and log ] Signed-off-by: Willem-Jan de Hoog Signed-off-by: Arınç ÜNAL --- drivers/nvmem/brcm_nvram.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/nvmem/brcm_nvram.c b/drivers/nvmem/brcm_nvram.c index 34130449f2d2..f74bcb1c948e 100644 --- a/drivers/nvmem/brcm_nvram.c +++ b/drivers/nvmem/brcm_nvram.c @@ -33,6 +33,12 @@ struct brcm_nvram_header { static int brcm_nvram_read(void *context, unsigned int offset, void *val, size_t bytes) { +#ifdef CONFIG_BCM47XX_NVRAM + + return bcm47xx_nvram_read(offset, val, bytes); + +#else + struct brcm_nvram *priv = context; u8 *dst = val; @@ -40,6 +46,8 @@ static int brcm_nvram_read(void *context, unsigned int offset, void *val, *dst++ = readb(priv->base + offset++); return 0; + +#endif } static int brcm_nvram_add_cells(struct brcm_nvram *priv, uint8_t *data,