From patchwork Fri Sep 28 11:39:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10619823 X-Patchwork-Delegate: kvalo@adurom.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 672FC417B for ; Fri, 28 Sep 2018 11:39:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5A1F22B2BD for ; Fri, 28 Sep 2018 11:39:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4ED4A2B2C2; Fri, 28 Sep 2018 11:39:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F22C32B2DF for ; Fri, 28 Sep 2018 11:39:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729614AbeI1SDC (ORCPT ); Fri, 28 Sep 2018 14:03:02 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:51154 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729431AbeI1SDC (ORCPT ); Fri, 28 Sep 2018 14:03:02 -0400 Received: by mail-wm1-f65.google.com with SMTP id s12-v6so1901899wmc.0 for ; Fri, 28 Sep 2018 04:39:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+ToiF4WkQHED/FMECTwZbdU8SdDLDBG/7LYVnue0eLM=; b=rSXxC0dZSoEfuo3EoeHFMK1u/05PbzGSJM8QpV/ubRLlaQGt/JAOwDcwjkLXFPLoi0 vGPafJzlRugDBKotnkcEO6KS5qEDyw4dfuiZpRG34ebMIJoYhMIr8aQhFEVa1ajWdep9 R1G7dXzipIuP3I5gc+oCeW1BFykKCfMgKRkMxeoQInzy/m5bhHyl1YvPU1lqb8fG2rgF Ih9b+NfEOXZk6oil0u/fu/Lxdg3EyVJOuo6p6doVjnd5iQHntCTE75eNpdPMY3Ok1AA5 FWz9+fq3FngD/bxYoK7xhW5pWVPbajiogiG8TQ1q1FxDRWx2pQS7CVmu8O8m8ChPDfTX Bx7w== X-Gm-Message-State: ABuFfohSc/oJz8gy/bhMoJi9vOAuY7M9v+vbx6Mn6bK5pR9bn/HcC45G ynB0cIm0l+A1mbaZka0j4lO9zg== X-Google-Smtp-Source: ACcGV63njAt0i6UyjxaymM8AJkvuoq5Vr8DdKucBS+vYNTD3pWQwxYoWPFcFuFVnvMASNJzm0jYGLw== X-Received: by 2002:a1c:90e:: with SMTP id 14-v6mr1457570wmj.130.1538134779274; Fri, 28 Sep 2018 04:39:39 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id s10-v6sm2395655wmd.22.2018.09.28.04.39.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Sep 2018 04:39:38 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: sgruszka@redhat.com, linux-wireless@vger.kernel.org Subject: [PATCH v3 23/24] mt76x0: eeprom: load eeprom data from mtd by default Date: Fri, 28 Sep 2018 13:39:06 +0200 Message-Id: X-Mailer: git-send-email 2.17.1 In-Reply-To: References: Sender: linux-wireless-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Read eeprom data from mtd memory by default and fall-back to efuse if it fails Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/eeprom.c | 56 ++++++++++++++----- 1 file changed, 43 insertions(+), 13 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index ef9c3df6a169..166a1fd8644e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -277,24 +277,54 @@ void mt76x0_get_power_info(struct mt76x0_dev *dev, u8 *info) info[1] = 5; } +static int mt76x0_check_eeprom(struct mt76x0_dev *dev) +{ + u16 val; + + val = get_unaligned_le16(dev->mt76.eeprom.data); + if (!val) + val = get_unaligned_le16(dev->mt76.eeprom.data + + MT_EE_PCI_ID); + + switch (val) { + case 0x7650: + case 0x7610: + return 0; + default: + dev_err(dev->mt76.dev, "EEPROM data check failed: %04x\n", + val); + return -EINVAL; + } +} + +static int mt76x0_load_eeprom(struct mt76x0_dev *dev) +{ + int found; + + found = mt76_eeprom_init(&dev->mt76, MT76X0_EEPROM_SIZE); + if (found < 0) + return found; + + if (found && !mt76x0_check_eeprom(dev)) + return 0; + + found = mt76x0_efuse_physical_size_check(dev); + if (found < 0) + return found; + + return mt76x02_get_efuse_data(&dev->mt76, 0, dev->mt76.eeprom.data, + MT76X0_EEPROM_SIZE, MT_EE_READ); +} + int mt76x0_eeprom_init(struct mt76x0_dev *dev) { u8 version, fae; u16 data; - int ret; + int err; - ret = mt76x0_efuse_physical_size_check(dev); - if (ret) - return ret; - - ret = mt76_eeprom_init(&dev->mt76, MT76X0_EEPROM_SIZE); - if (ret < 0) - return ret; - - ret = mt76x02_get_efuse_data(&dev->mt76, 0, dev->mt76.eeprom.data, - MT76X0_EEPROM_SIZE, MT_EE_READ); - if (ret) - return ret; + err = mt76x0_load_eeprom(dev); + if (err < 0) + return err; data = mt76x02_eeprom_get(&dev->mt76, MT_EE_VERSION); version = data >> 8;