Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp1507681yba; Thu, 16 May 2019 23:50:42 -0700 (PDT) X-Google-Smtp-Source: APXvYqymt1RiUPc+6zLtSviZSIo3PhB+YQkFOa8m1xoY17mCMrTFXbycW+Z5+PZbbeJgHtjgWLht X-Received: by 2002:a17:902:1cb:: with SMTP id b69mr28907365plb.158.1558075842553; Thu, 16 May 2019 23:50:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558075842; cv=none; d=google.com; s=arc-20160816; b=XGyub4sT1YVQRNU6f8NsF7khxQaK0UydNAaUz8zDHdcfQnnjfAjgbQp6VZByw9W1Ww cu4WUPX9bktIIo5QYOGk6F7O/cQkMSpRYjHXn8e4x76GYYbwfZ964GnARL1LN3feewDE fzmhqNqG6amj8gxYnsrEleJFqeikHy45hJeiIJdSSD9lmj2TcgdVrUmUf4H41oRMYSTG 3OhD4Vaga8+kxaNbpWkkKfvHfAU3T0yF+2va6vUpELt5NQTBuPXqD4wR0S4Y+z2KCBHU 2n70E+rEYHGxApRXI9D0T1A+rAg8ayM58KzSqQ4BzeQuu/rQvoJSt/P3VicHtupOmDVD JWXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=biaz+cOv+YJugcMdD0WDqIaiYUxSs7Ai+mV33tidFf0=; b=uVoX4VVIoo+Thg0EIrx4NDKO0oNq+MxzfEuEVtnZ3SicUD4wXAdgSw+ccrAbicgre1 AwZjnpwHBnWO06KQRw+4axsFOnls2ZF1nXdmJHocITK2gvfPOEip2l6gG4u/0MPsuNj2 XvEeq+pha/7NGuAkXLYlI9vFvSVF3b7vpmMDFy//pl+lYFKB/K0gvj76uqcUl47msDKg BFnGGc63q6yRVtb0y8unwdIilFAWIBLh5kPIQi4jVM428heYSwEPJ5ryGATbP3rTthbz sx/VCXR7ei+Ibf5SvR3DxztQV/t3YQSMf5YUFjDcx8qpg5mujDCk+OYfZYww0wVhje3k J0AQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uwk4G9eb; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i186si7214194pfb.0.2019.05.16.23.50.11; Thu, 16 May 2019 23:50:42 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=uwk4G9eb; spf=pass (google.com: best guess record for domain of linux-wireless-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-wireless-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727581AbfEQG0P (ORCPT + 99 others); Fri, 17 May 2019 02:26:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:58528 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727184AbfEQG0P (ORCPT ); Fri, 17 May 2019 02:26:15 -0400 Received: from lore-desk-wlan.lan (unknown [151.66.17.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3152F20833; Fri, 17 May 2019 06:26:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1558074374; bh=GdNj1kVcG98Mh6w82ct3kOQTIhlA8j7gO0BlJ8ugMj0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=uwk4G9ebyRl8DwRaQURcxQRs/yG/Okw/udEu3xItCEhZKomFLLtHuuGgsmHmQ/p6U p78CjlvQpXNhGIw9ytP3lmORySjpcHOUTy43+pxjSVpgj4+ECfwoDDejNHzPznaJno nszlyjhdYCpxOnXrLhEWhTYUwXe8Gmo60/PJNPBo= From: Lorenzo Bianconi To: nbd@nbd.name Cc: lorenzo.bianconi@redhat.com, linux-wireless@vger.kernel.org, ryder.lee@mediatek.com, royluo@google.com Subject: [PATCH v2] mt76: mt7615: add support for mtd eeprom parsing Date: Fri, 17 May 2019 08:26:05 +0200 Message-Id: <12c5ae00296007af2da0021cc0872dac9b6960dc.1558074163.git.lorenzo@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Calibration data are often available on a specific mtd partition on embedded devices. Take into account eeprom calibration data if available. Signed-off-by: Lorenzo Bianconi --- Changes since v1: - remove TODO comment - take into account mtd partition even if otp one is empty --- .../wireless/mediatek/mt76/mt7615/eeprom.c | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt7615/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt7615/eeprom.c index dd5ab46a4f66..1712f66520a8 100644 --- a/drivers/net/wireless/mediatek/mt76/mt7615/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt7615/eeprom.c @@ -42,13 +42,13 @@ static int mt7615_efuse_read(struct mt7615_dev *dev, u32 base, static int mt7615_efuse_init(struct mt7615_dev *dev) { - u32 base = mt7615_reg_map(dev, MT_EFUSE_BASE); - int len = MT7615_EEPROM_SIZE; - int ret, i; + u32 val, base = mt7615_reg_map(dev, MT_EFUSE_BASE); + int i, len = MT7615_EEPROM_SIZE; void *buf; - if (mt76_rr(dev, base + MT_EFUSE_BASE_CTRL) & MT_EFUSE_BASE_CTRL_EMPTY) - return -EINVAL; + val = mt76_rr(dev, base + MT_EFUSE_BASE_CTRL); + if (val & MT_EFUSE_BASE_CTRL_EMPTY) + return 0; dev->mt76.otp.data = devm_kzalloc(dev->mt76.dev, len, GFP_KERNEL); dev->mt76.otp.size = len; @@ -57,6 +57,8 @@ static int mt7615_efuse_init(struct mt7615_dev *dev) buf = dev->mt76.otp.data; for (i = 0; i + 16 <= len; i += 16) { + int ret; + ret = mt7615_efuse_read(dev, base, i, buf + i); if (ret) return ret; @@ -76,6 +78,18 @@ static int mt7615_eeprom_load(struct mt7615_dev *dev) return mt7615_efuse_init(dev); } +static int mt7615_check_eeprom(struct mt76_dev *dev) +{ + u16 val = get_unaligned_le16(dev->eeprom.data); + + switch (val) { + case 0x7615: + return 0; + default: + return -EINVAL; + } +} + int mt7615_eeprom_init(struct mt7615_dev *dev) { int ret; @@ -84,7 +98,10 @@ int mt7615_eeprom_init(struct mt7615_dev *dev) if (ret < 0) return ret; - memcpy(dev->mt76.eeprom.data, dev->mt76.otp.data, MT7615_EEPROM_SIZE); + ret = mt7615_check_eeprom(&dev->mt76); + if (ret && dev->mt76.otp.data) + memcpy(dev->mt76.eeprom.data, dev->mt76.otp.data, + MT7615_EEPROM_SIZE); dev->mt76.cap.has_2ghz = true; dev->mt76.cap.has_5ghz = true; -- 2.20.1