From patchwork Thu Sep 20 09:11:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607171 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 246C81390 for ; Thu, 20 Sep 2018 09:12:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 148492CC13 for ; Thu, 20 Sep 2018 09:12:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 091602CC7A; Thu, 20 Sep 2018 09:12:37 +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 7D80E2CC13 for ; Thu, 20 Sep 2018 09:12:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387440AbeITOy6 (ORCPT ); Thu, 20 Sep 2018 10:54:58 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:55618 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387433AbeITOy6 (ORCPT ); Thu, 20 Sep 2018 10:54:58 -0400 Received: by mail-wm1-f66.google.com with SMTP id f21-v6so9109286wmc.5 for ; Thu, 20 Sep 2018 02:12:29 -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=MSmurVW3MjFDe9dh1Bpf9O+qpwsMIWJeKHloxroZLKQ=; b=aNVjs+P+zMgoreCv2egQWLbfUPiKg2GtraXm3MAaRUwVFScbIlC72HYGeU34n+sZzU 0Ax2g4v+72GbGFNUrGV8Y6KFRE/ZNOdD9C+o+yB0L5Z/HJOfojq0nQ9PnAMupZVkOLvO GERuaMGj66lkPENfZR2mKD7nbIQ8Azg2tvYISKKtBjrHwugR8nOfMsyQhQMgWzyKYZ/K 56cpX3xKsFAwUZZqy5KtoP1DLtbiO6klWNQf9pPuK/LyvEnOBOMs29567FrckVma72Jq R8Zh7bzVe6/OwUMlnGFBXtgf4FPV68hJgQNlXQxStHJQ21pVhTkjq4O0OtKHXCMmmhkt XImg== X-Gm-Message-State: ABuFfojKlVZ4nKVh28+dd5bqLBiBx0xJd8+Y1oG+3t1FK/VlF+s5SQdU Tdt93DE6srz1Uys7DYc/9+4vIg== X-Google-Smtp-Source: ANB0VdZcgcsptrHagIk0yvD9WCYwR/pxMOAKaQimcdQ9mYIbuKlI4FEmTyg1wUCbsW9t/XcpBpOgfg== X-Received: by 2002:a1c:b686:: with SMTP id g128-v6mr1462321wmf.83.1537434748108; Thu, 20 Sep 2018 02:12:28 -0700 (PDT) Received: from localhost.localdomain.com (nat-pool-mxp-t.redhat.com. [149.6.153.186]) by smtp.gmail.com with ESMTPSA id 34-v6sm35501691wra.20.2018.09.20.02.12.27 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:27 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Cc: linux-wireless@vger.kernel.org, sgruszka@redhat.com, linux-mediatek@lists.infradead.org Subject: [PATCH 04/20] mt76: move eeprom utility routines in mt76x02_eeprom.h Date: Thu, 20 Sep 2018 11:11:51 +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 Move shared eeprom utility routines in mt76x02_eeprom.h and remove duplicated code Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/eeprom.c | 44 +++++-------------- .../wireless/mediatek/mt76/mt76x02_eeprom.h | 15 +++++++ .../wireless/mediatek/mt76/mt76x2_eeprom.c | 37 +++++----------- 3 files changed, 38 insertions(+), 58 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index 8a8244c1cdaa..c935d98f5710 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -21,31 +21,6 @@ #include "mt76x0.h" #include "eeprom.h" -static bool -field_valid(u8 val) -{ - return val != 0xff; -} - -static s8 -field_validate(u8 val) -{ - if (!field_valid(val)) - return 0; - - return val; -} - -static inline int -sign_extend(u32 val, unsigned int size) -{ - bool sign = val & BIT(size - 1); - - val &= BIT(size - 1) - 1; - - return sign ? val : -val; -} - static int mt76x0_efuse_read(struct mt76x0_dev *dev, u16 addr, u8 *data, enum mt76x0_eeprom_access_modes mode) @@ -137,14 +112,14 @@ mt76x0_set_chip_cap(struct mt76x0_dev *dev, u8 *eeprom) dev_dbg(dev->mt76.dev, "Has 2GHZ %d 5GHZ %d\n", dev->mt76.cap.has_2ghz, dev->mt76.cap.has_5ghz); - if (!field_valid(nic_conf1 & 0xff)) + if (!mt76x02_field_valid(nic_conf1 & 0xff)) nic_conf1 &= 0xff00; if (nic_conf1 & MT_EE_NIC_CONF_1_HW_RF_CTRL) dev_err(dev->mt76.dev, "Error: this driver does not support HW RF ctrl\n"); - if (!field_valid(nic_conf0 >> 8)) + if (!mt76x02_field_valid(nic_conf0 >> 8)) return; if (FIELD_GET(MT_EE_NIC_CONF_0_RX_PATH, nic_conf0) > 1 || @@ -183,8 +158,8 @@ mt76x0_set_temp_offset(struct mt76x0_dev *dev, u8 *eeprom) { u8 temp = eeprom[MT_EE_TEMP_OFFSET]; - if (field_valid(temp)) - dev->ee->temp_off = sign_extend(temp, 8); + if (mt76x02_field_valid(temp)) + dev->ee->temp_off = mt76x02_sign_extend(temp, 8); else dev->ee->temp_off = -10; } @@ -231,8 +206,13 @@ mt76x0_set_rf_freq_off(struct mt76x0_dev *dev, u8 *eeprom) { u8 comp; - dev->ee->rf_freq_off = field_validate(eeprom[MT_EE_FREQ_OFFSET]); - comp = field_validate(eeprom[MT_EE_FREQ_OFFSET_COMPENSATION]); + comp = eeprom[MT_EE_FREQ_OFFSET_COMPENSATION]; + if (!mt76x02_field_valid(comp)) + comp = 0; + + dev->ee->rf_freq_off = eeprom[MT_EE_FREQ_OFFSET]; + if (!mt76x02_field_valid(dev->ee->rf_freq_off)) + dev->ee->rf_freq_off = 0; if (comp & BIT(7)) dev->ee->rf_freq_off -= comp & 0x7f; @@ -311,7 +291,7 @@ get_delta(u8 val) { s8 ret; - if (!field_valid(val) || !(val & BIT(7))) + if (!mt76x02_field_valid(val) || !(val & BIT(7))) return 0; ret = val & 0x1f; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h index d50387f2ef46..1575c2352d9b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h @@ -121,4 +121,19 @@ enum mt76x02_eeprom_field { #define MT_EFUSE_USAGE_MAP_SIZE (MT_EE_USAGE_MAP_END - \ MT_EE_USAGE_MAP_START + 1) +static inline bool mt76x02_field_valid(u8 val) +{ + return val != 0 && val != 0xff; +} + +static inline int +mt76x02_sign_extend(u32 val, unsigned int size) +{ + bool sign = val & BIT(size - 1); + + val &= BIT(size - 1) - 1; + + return sign ? val : -val; +} + #endif /* __MT76x02_EEPROM_H */ diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c index 7c3d65f9d18d..2db495d9f99f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c @@ -259,28 +259,12 @@ mt76x2_eeprom_load(struct mt76x2_dev *dev) return 0; } -static inline int -mt76x2_sign_extend(u32 val, unsigned int size) -{ - bool sign = val & BIT(size - 1); - - val &= BIT(size - 1) - 1; - - return sign ? val : -val; -} - static inline int mt76x2_sign_extend_optional(u32 val, unsigned int size) { bool enable = val & BIT(size); - return enable ? mt76x2_sign_extend(val, size) : 0; -} - -static bool -field_valid(u8 val) -{ - return val != 0 && val != 0xff; + return enable ? mt76x02_sign_extend(val, size) : 0; } static void @@ -288,14 +272,14 @@ mt76x2_set_rx_gain_group(struct mt76x2_dev *dev, u8 val) { s8 *dest = dev->cal.rx.high_gain; - if (!field_valid(val)) { + if (!mt76x02_field_valid(val)) { dest[0] = 0; dest[1] = 0; return; } - dest[0] = mt76x2_sign_extend(val, 4); - dest[1] = mt76x2_sign_extend(val >> 4, 4); + dest[0] = mt76x02_sign_extend(val, 4); + dest[1] = mt76x02_sign_extend(val >> 4, 4); } static void @@ -303,7 +287,7 @@ mt76x2_set_rssi_offset(struct mt76x2_dev *dev, int chain, u8 val) { s8 *dest = dev->cal.rx.rssi_offset; - if (!field_valid(val)) { + if (!mt76x02_field_valid(val)) { dest[chain] = 0; return; } @@ -384,10 +368,10 @@ void mt76x2_read_rx_gain(struct mt76x2_dev *dev) val = mt76x2_eeprom_get(dev, MT_EE_RSSI_OFFSET_5G_1); lna_5g[2] = val >> 8; - if (!field_valid(lna_5g[1])) + if (!mt76x02_field_valid(lna_5g[1])) lna_5g[1] = lna_5g[0]; - if (!field_valid(lna_5g[2])) + if (!mt76x02_field_valid(lna_5g[2])) lna_5g[2] = lna_5g[0]; dev->cal.rx.mcu_gain = (lna_2g & 0xff); @@ -413,14 +397,14 @@ void mt76x2_read_rx_gain(struct mt76x2_dev *dev) if (lna == 0xff) lna = 0; - dev->cal.rx.lna_gain = mt76x2_sign_extend(lna, 8); + dev->cal.rx.lna_gain = mt76x02_sign_extend(lna, 8); } EXPORT_SYMBOL_GPL(mt76x2_read_rx_gain); static s8 mt76x2_rate_power_val(u8 val) { - if (!field_valid(val)) + if (!mt76x02_field_valid(val)) return 0; return mt76x2_sign_extend_optional(val, 7); @@ -598,7 +582,8 @@ void mt76x2_get_power_info(struct mt76x2_dev *dev, MT_EE_TX_POWER_1_START_2G); } - if (mt76x2_tssi_enabled(dev) || !field_valid(t->target_power)) + if (mt76x2_tssi_enabled(dev) || + !mt76x02_field_valid(t->target_power)) t->target_power = t->chain[0].target_power; t->delta_bw40 = mt76x2_rate_power_val(bw40);