From patchwork Sat Jul 8 18:29:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13305696 X-Patchwork-Delegate: nbd@nbd.name 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 8E359EB64DA for ; Sat, 8 Jul 2023 18:29:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229942AbjGHS3q (ORCPT ); Sat, 8 Jul 2023 14:29:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjGHS3p (ORCPT ); Sat, 8 Jul 2023 14:29:45 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 98BE9D2; Sat, 8 Jul 2023 11:29:44 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id ffacd0b85a97d-31297125334so2465983f8f.0; Sat, 08 Jul 2023 11:29:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688840983; x=1691432983; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=2nWPM4jwPafYGbRkd318KIxOMWqBhLm3R65ukPzT5Hw=; b=Eo+Ve0tiHadMyHDD4YevTQOQH7jWzOxi9XRPXgvke/Z4nauF7ijUaEBi86hGQl1XeI v/DReW2ssHDGOaL78gYoJwUkr+JrfAyCGMEIyZ9iV2OOaGFTxcsiHR2/n2LUpIyVU70h oEm2qI6A+t1pfxzOJBQx0x0JBQjis34S6KFKialnq17k8ZAoX4/xCIPJfd/V6uNtcUr2 SwqD9LqMph/nDcn1lYu7Ksw46/xs55Sz+KcUILIIh4SawmW/BxIVfxfpTpR5z2gI4bPL 6W3Fxz8xe3RtAXl/X/rW3fmFFswhtmiYF2GRediYYo3FA98sh/GGx5oB0CGJmayEPwte Pvkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688840983; x=1691432983; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2nWPM4jwPafYGbRkd318KIxOMWqBhLm3R65ukPzT5Hw=; b=BgUME7KrvC4WbXxpjgMmSVpDLxW+S9FKwZ9aFDT0ltR44W6G67HoHMstpeZeySoNuv kn02Bipdg4oXZgBhj+8duHI9BLfc8PUhH121J4zDYuxhFK+MgOzp9W8Zavd6kWyDKx27 Csp0VfLiowEu08zZVBz961pJ9oN6nMjWNMeZDlgo4wSMWNCM1EsuxnsbnhW0x2pvUQEq zc8F7QCUZKsNLrX/Lm70bbNHxRn9W/FN2AKdv/YwIGmrR5A+7UBRH5QMF4v3zsmThKP7 zX/OFBtiVgArj29rX8iveQIFyOvTnH+slqH+WOL2eXtl2ys+aR1pIa0ztRFs2alA+moC Fw8A== X-Gm-Message-State: ABy/qLbHNYj2tKZsyWZX/D2MW+2h8PC4G8Fkb8cpM5yQyZvVpoqxmV0W eCJ5yYqcu8GEdeGOs8aVHa8ly7p/atE= X-Google-Smtp-Source: APBJJlHEs+Abh2p4LsTa9DS8Xo9WLU3gZZVMEj49tQExaGWJKA40ooL/IXqMn0LcwfERBDMYoUmscw== X-Received: by 2002:a5d:420d:0:b0:314:3f1:cebf with SMTP id n13-20020a5d420d000000b0031403f1cebfmr11449963wrq.28.1688840982706; Sat, 08 Jul 2023 11:29:42 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id h9-20020adfe989000000b0030647449730sm7492067wrm.74.2023.07.08.11.29.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Jul 2023 11:29:42 -0700 (PDT) From: Christian Marangi To: Felix Fietkau , Lorenzo Bianconi , Ryder Lee , Shayne Chen , Sean Wang , Kalle Valo , Matthias Brugger , AngeloGioacchino Del Regno , linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Cc: Christian Marangi Subject: [PATCH 1/2] wifi: mt76: split get_of_eeprom in subfunction Date: Sat, 8 Jul 2023 20:29:35 +0200 Message-Id: <20230708182936.24469-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org In preparation for NVMEM support, split get_of_eeprom() in subfunction to tidy the code and facilitate the addition of alternative method to get eeprom data. No behaviour change intended. While at it also drop OF ifdef checks as OF have stubs and calling of_get_property would result in the same error returned. Signed-off-by: Christian Marangi Reviewed-by: Daniel Golle Tested-by: Daniel Golle Reviewed-by: Rafał Miłecki --- drivers/net/wireless/mediatek/mt76/eeprom.c | 51 ++++++++++++++------- 1 file changed, 35 insertions(+), 16 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/eeprom.c b/drivers/net/wireless/mediatek/mt76/eeprom.c index dce851d42e08..c3a762074be8 100644 --- a/drivers/net/wireless/mediatek/mt76/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/eeprom.c @@ -9,31 +9,35 @@ #include #include "mt76.h" -int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len) +static int mt76_get_of_eeprom_data(struct mt76_dev *dev, void *eep, int len) { -#if defined(CONFIG_OF) && defined(CONFIG_MTD) struct device_node *np = dev->dev->of_node; - struct mtd_info *mtd; - const __be32 *list; const void *data; - const char *part; - phandle phandle; int size; - size_t retlen; - int ret; - if (!np) + data = of_get_property(np, "mediatek,eeprom-data", &size); + if (!data) return -ENOENT; - data = of_get_property(np, "mediatek,eeprom-data", &size); - if (data) { - if (size > len) - return -EINVAL; + if (size > len) + return -EINVAL; - memcpy(eep, data, size); + memcpy(eep, data, size); - return 0; - } + return 0; +} + +static int mt76_get_of_epprom_from_mtd(struct mt76_dev *dev, void *eep, int offset, int len) +{ +#ifdef CONFIG_MTD + struct device_node *np = dev->dev->of_node; + struct mtd_info *mtd; + const __be32 *list; + const char *part; + phandle phandle; + size_t retlen; + int size; + int ret; list = of_get_property(np, "mediatek,mtd-eeprom", &size); if (!list) @@ -100,6 +104,21 @@ int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len) return -ENOENT; #endif } + +int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len) +{ + struct device_node *np = dev->dev->of_node; + int ret; + + if (!np) + return -ENOENT; + + ret = mt76_get_of_eeprom_data(dev, eep, len); + if (!ret) + return 0; + + return mt76_get_of_epprom_from_mtd(dev, eep, offset, len); +} EXPORT_SYMBOL_GPL(mt76_get_of_eeprom); void From patchwork Sat Jul 8 18:29:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 13305697 X-Patchwork-Delegate: nbd@nbd.name 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 CB27BC001B0 for ; Sat, 8 Jul 2023 18:29:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229986AbjGHS3r (ORCPT ); Sat, 8 Jul 2023 14:29:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229458AbjGHS3q (ORCPT ); Sat, 8 Jul 2023 14:29:46 -0400 Received: from mail-wm1-x334.google.com (mail-wm1-x334.google.com [IPv6:2a00:1450:4864:20::334]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D4A7130; Sat, 8 Jul 2023 11:29:45 -0700 (PDT) Received: by mail-wm1-x334.google.com with SMTP id 5b1f17b1804b1-3fbf1b82de7so24520085e9.1; Sat, 08 Jul 2023 11:29:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688840984; x=1691432984; 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=aRlinllzuoLno5ix8NJN30aYnS4fPlc7sOxq/5PjHIk=; b=qu+RlsIaWJd8WTxko1JbxVTi2ZRF7I15gRBdEyTNLfm4+1YU0LEOFxXJKCmCZx4YPc Ki0bBjXQwBl8NaKHddnzIJI2Mij6+V+yE6uvl6l1XmSAVrYvC5sG2VjQhUsxakdvkBK1 39b+6bIJw2iuskMXwiLzm3PLKfI3LYPiUsDt6HAPSpYnSJFCkclV3zcMU3s9mg/IG6GL +VOY8OuxYuucrplErZc5fXwHGZfhcmqkV2B0eq3xGJdAzmYeMET5T7QEAWtN9BX7oCFu M7ddlT44sT/CngI3SzNKFmrKkYG4nwEP1EQmoszDP3zkW5xtBfsGc0PlKdfD39LKBaFF Twdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688840984; x=1691432984; 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=aRlinllzuoLno5ix8NJN30aYnS4fPlc7sOxq/5PjHIk=; b=UasoNzYV1rodkMyaYsjG5AKfh2Piw2CiiCItl1WJHuLhyywIolWaXX7EfY56rLafOB Yr6MpXyODldynA6U1FA0vjL+0wFVcOcbI1Uz4E0UF2GYUBYgWZa6rkNvTO1Xrc3l66I3 SHGak6HRyBKgO2l5U3MdhtGV9gxjnfdgH/KA+zlrkYWjy4POE51wJ/TqdVMXJGTollm2 VFfnf/JMQKb2NRQgl4qEfqUHY9Z86V8QN/4aaL7m/43rvnhBXLtG/daO6ruBL6H7P1QB dKsXhA37M/377R0tssNcgmVRcszt85yYUC91wFO3uEKe00pEwWe4L8PcgqFoH6xAxhLr LbzA== X-Gm-Message-State: ABy/qLYAYWO31Ty0sa7emuy4lcOfyvRRbYTB/8KWICwDix+4iPWNddY/ olDQIYEAdN2y+9/9X3dpTRE= X-Google-Smtp-Source: APBJJlHQCf5NSpNxS5BwssHQcf8A1hFtRUGQ9JeBaBFBFtD02S1IhjHLWTq+vacSUBIVP3j3aXcnkw== X-Received: by 2002:a05:600c:2207:b0:3f7:e660:cdc5 with SMTP id z7-20020a05600c220700b003f7e660cdc5mr7583435wml.9.1688840983788; Sat, 08 Jul 2023 11:29:43 -0700 (PDT) Received: from localhost.localdomain (93-34-93-173.ip49.fastwebnet.it. [93.34.93.173]) by smtp.googlemail.com with ESMTPSA id h9-20020adfe989000000b0030647449730sm7492067wrm.74.2023.07.08.11.29.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Jul 2023 11:29:43 -0700 (PDT) From: Christian Marangi To: Felix Fietkau , Lorenzo Bianconi , Ryder Lee , Shayne Chen , Sean Wang , Kalle Valo , Matthias Brugger , AngeloGioacchino Del Regno , linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org Cc: Christian Marangi Subject: [PATCH 2/2] wifi: mt76: add support for providing eeprom in nvmem cells Date: Sat, 8 Jul 2023 20:29:36 +0200 Message-Id: <20230708182936.24469-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230708182936.24469-1-ansuelsmth@gmail.com> References: <20230708182936.24469-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Add support for providing eeprom in nvmem cells by adding nvmem cell as an alternative source for mt76_get_of_eeprom(). Nvmem cells will follow standard nvmem cell definition and needs to be called 'eeprom' to be correctly identified. Signed-off-by: Christian Marangi Reviewed-by: Daniel Golle Tested-by: Daniel Golle Reviewed-by: Rafał Miłecki --- drivers/net/wireless/mediatek/mt76/eeprom.c | 38 ++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/mediatek/mt76/eeprom.c b/drivers/net/wireless/mediatek/mt76/eeprom.c index c3a762074be8..36564930aef1 100644 --- a/drivers/net/wireless/mediatek/mt76/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/eeprom.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "mt76.h" @@ -105,6 +106,37 @@ static int mt76_get_of_epprom_from_mtd(struct mt76_dev *dev, void *eep, int offs #endif } +static int mt76_get_of_epprom_from_nvmem(struct mt76_dev *dev, void *eep, int len) +{ + struct device_node *np = dev->dev->of_node; + struct nvmem_cell *cell; + const void *data; + size_t retlen; + int ret = 0; + + cell = of_nvmem_cell_get(np, "eeprom"); + if (IS_ERR(cell)) + return PTR_ERR(cell); + + data = nvmem_cell_read(cell, &retlen); + nvmem_cell_put(cell); + + if (IS_ERR(data)) + return PTR_ERR(data); + + if (retlen < len) { + ret = -EINVAL; + goto exit; + } + + memcpy(eep, data, len); + +exit: + kfree(data); + + return ret; +} + int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len) { struct device_node *np = dev->dev->of_node; @@ -117,7 +149,11 @@ int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len) if (!ret) return 0; - return mt76_get_of_epprom_from_mtd(dev, eep, offset, len); + ret = mt76_get_of_epprom_from_mtd(dev, eep, offset, len); + if (!ret) + return 0; + + return mt76_get_of_epprom_from_nvmem(dev, eep, len); } EXPORT_SYMBOL_GPL(mt76_get_of_eeprom);