Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp1644642pxb; Sat, 23 Jan 2021 00:37:57 -0800 (PST) X-Google-Smtp-Source: ABdhPJzvoE40btHPIT73DhrnNtRoxoFYsIgHqMV20bO6lsZe6gw3FIXvLLqlAw7XlSvoghP2PPpE X-Received: by 2002:a17:906:ae51:: with SMTP id lf17mr978942ejb.330.1611391077575; Sat, 23 Jan 2021 00:37:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1611391077; cv=none; d=google.com; s=arc-20160816; b=Abxu+Q3uw9pDQAt/d2SqRV567SqR7r80au4zSjMhCTFCcD+QPmyvJTxyo7yRimcsAA +/EpyEI/renHaobpmKiIUpPeBWp/vmAVi/ReNjLP3HDFDowyNt5pEofxGGQ0m5wCldvr aQttQgfoeug3QqJ3Y1MtwKguH7hhbqEDHcqB6EGIZ7/VZ5JJXSJvkJoMzBNCeAMkYyAV K2Od4iTAA1Ex9puT/mCFTNGFOHccNqmYrdk0aP5bIUQhaYf31AnTpyfM4h14SJrplVLV xR6rgy+9pvMI/Ib6tvfy8dd7xMSbzYZo329wHuFV4blTOrghxxU3ONg+Gput+YQIHadS mk9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=thzqUUwBJgrhRyomboTugiO/FteucSguuGJigTx/0n0=; b=b+GEwACTY0jgLqNsq7696788ZmZuNcvYwfIvZaW4rIlU8vviIGD3h4kQII/CvKBcAv qYT0FdOZS9Qtl2N4M35pY9S/FczYIP+6o71V6JELuui1xLYNi857GJkIcJghG7acIEAQ /mbQZwJWO80brJfvK2CetVuUdFFiFDBUTSSG5QfCtuj+bCKD5/QtjifLGQL7vyWOLE7k KQOj5ObGgobkm+eE13dBo7obdPFBWr0QaRtGKRGQm6jZwAeKGmQkxPIcG9d2P0R8sizb BV/uG0JVtAzvovsSZUSn99kyFJCx6ZzF/8dHrd8uMC7PInUU2ESY1fzPb1aJ1+SNdk7b B32A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d30si4992378edd.488.2021.01.23.00.37.35; Sat, 23 Jan 2021 00:37:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-wireless-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726720AbhAWIgI (ORCPT + 99 others); Sat, 23 Jan 2021 03:36:08 -0500 Received: from mailgw01.mediatek.com ([210.61.82.183]:54858 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726673AbhAWIgC (ORCPT ); Sat, 23 Jan 2021 03:36:02 -0500 X-UUID: 8bf480e598324b929db43828bf3516b3-20210123 X-UUID: 8bf480e598324b929db43828bf3516b3-20210123 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw01.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.14 Build 0819 with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 233865453; Sat, 23 Jan 2021 16:35:16 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs06n1.mediatek.inc (172.21.101.129) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Sat, 23 Jan 2021 16:35:15 +0800 Received: from mtkswgap22.mediatek.inc (172.21.77.33) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Sat, 23 Jan 2021 16:35:15 +0800 From: To: , CC: , , , , , , , , , , Lorenzo Bianconi Subject: [PATCH -next v7 04/22] mt76: mt7921: add EEPROM support Date: Sat, 23 Jan 2021 16:34:55 +0800 Message-ID: <05d2dee7cdd7c0f71724866f5d19fee176fdc5a0.1611389300.git.objelf@gmail.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org From: Sean Wang Add EEPROM support to MT7921 to determine the capability the card has such as indentificaiton, MAC address, the band and antenna number the card able to support. Co-developed-by: Lorenzo Bianconi Signed-off-by: Lorenzo Bianconi Co-developed-by: Soul Huang Signed-off-by: Soul Huang Signed-off-by: Sean Wang --- .../wireless/mediatek/mt76/mt7921/eeprom.c | 100 ++++++++++++++++++ .../wireless/mediatek/mt76/mt7921/eeprom.h | 27 +++++ 2 files changed, 127 insertions(+) create mode 100644 drivers/net/wireless/mediatek/mt76/mt7921/eeprom.c create mode 100644 drivers/net/wireless/mediatek/mt76/mt7921/eeprom.h diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt7921/eeprom.c new file mode 100644 index 000000000000..691d14a1a7bf --- /dev/null +++ b/drivers/net/wireless/mediatek/mt76/mt7921/eeprom.c @@ -0,0 +1,100 @@ +// SPDX-License-Identifier: ISC +/* Copyright (C) 2020 MediaTek Inc. */ + +#include "mt7921.h" +#include "eeprom.h" + +static u32 mt7921_eeprom_read(struct mt7921_dev *dev, u32 offset) +{ + u8 *data = dev->mt76.eeprom.data; + + if (data[offset] == 0xff) + mt7921_mcu_get_eeprom(dev, offset); + + return data[offset]; +} + +static int mt7921_eeprom_load(struct mt7921_dev *dev) +{ + int ret; + + ret = mt76_eeprom_init(&dev->mt76, MT7921_EEPROM_SIZE); + if (ret < 0) + return ret; + + memset(dev->mt76.eeprom.data, -1, MT7921_EEPROM_SIZE); + + return 0; +} + +static int mt7921_check_eeprom(struct mt7921_dev *dev) +{ + u8 *eeprom = dev->mt76.eeprom.data; + u16 val; + + mt7921_eeprom_read(dev, MT_EE_CHIP_ID); + val = get_unaligned_le16(eeprom); + + switch (val) { + case 0x7961: + return 0; + default: + return -EINVAL; + } +} + +void mt7921_eeprom_parse_band_config(struct mt7921_phy *phy) +{ + struct mt7921_dev *dev = phy->dev; + u32 val; + + val = mt7921_eeprom_read(dev, MT_EE_WIFI_CONF); + val = FIELD_GET(MT_EE_WIFI_CONF_BAND_SEL, val); + + switch (val) { + case MT_EE_5GHZ: + phy->mt76->cap.has_5ghz = true; + break; + case MT_EE_2GHZ: + phy->mt76->cap.has_2ghz = true; + break; + default: + phy->mt76->cap.has_2ghz = true; + phy->mt76->cap.has_5ghz = true; + break; + } +} + +static void mt7921_eeprom_parse_hw_cap(struct mt7921_dev *dev) +{ + u8 tx_mask; + + mt7921_eeprom_parse_band_config(&dev->phy); + + /* TODO: read NSS with MCU_CMD_NIC_CAPV2 */ + tx_mask = 2; + dev->chainmask = BIT(tx_mask) - 1; + dev->mphy.antenna_mask = dev->chainmask; + dev->mphy.chainmask = dev->mphy.antenna_mask; +} + +int mt7921_eeprom_init(struct mt7921_dev *dev) +{ + int ret; + + ret = mt7921_eeprom_load(dev); + if (ret < 0) + return ret; + + ret = mt7921_check_eeprom(dev); + if (ret) + return ret; + + mt7921_eeprom_parse_hw_cap(dev); + memcpy(dev->mphy.macaddr, dev->mt76.eeprom.data + MT_EE_MAC_ADDR, + ETH_ALEN); + + mt76_eeprom_override(&dev->mphy); + + return 0; +} diff --git a/drivers/net/wireless/mediatek/mt76/mt7921/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt7921/eeprom.h new file mode 100644 index 000000000000..54f30401343c --- /dev/null +++ b/drivers/net/wireless/mediatek/mt76/mt7921/eeprom.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: ISC */ +/* Copyright (C) 2020 MediaTek Inc. */ + +#ifndef __MT7921_EEPROM_H +#define __MT7921_EEPROM_H + +#include "mt7921.h" + +enum mt7921_eeprom_field { + MT_EE_CHIP_ID = 0x000, + MT_EE_VERSION = 0x002, + MT_EE_MAC_ADDR = 0x004, + MT_EE_WIFI_CONF = 0x07c, + __MT_EE_MAX = 0x3bf +}; + +#define MT_EE_WIFI_CONF_TX_MASK BIT(0) +#define MT_EE_WIFI_CONF_BAND_SEL GENMASK(3, 2) + +enum mt7921_eeprom_band { + MT_EE_NA, + MT_EE_5GHZ, + MT_EE_2GHZ, + MT_EE_DUAL_BAND, +}; + +#endif -- 2.25.1