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: 10607265 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 2EEFA6CB for ; Thu, 20 Sep 2018 09:34:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1C96A2CDCB for ; Thu, 20 Sep 2018 09:34:47 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 10A352CECD; Thu, 20 Sep 2018 09:34:47 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7E2282CDCB for ; Thu, 20 Sep 2018 09:34:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=7qWQFuLTRFeQoXwZbq+SgbXJ3qIPQ3joxAnDFcnNIEI=; b=Ujn0f2hFVN11dvT2AkLYFEZLPR T94zMav1W9zoRGCsIebp+m3iypMbNZWCtHKI0skf5UhwGiWAbjUghXlG94D+JzpI0a9f7WnQy6YmY 8a9Clv9Ehwy6Axphyc5qFLWl+Edut603XziQdX3LVQ1Fanju7s5tB4ZJPzA+MkJyb7nGr9SAu4UGM 1G1nv0lUidYuhLh06/Ms3dOaWdmCfQ+hKxOQrkptwsOGLbcxPyXsfHgfyfh/GI7Xdb1nDL0qseIcP k5enZSP49sOQ5Vj95lrWx/AeP4qjpur0IiUHnJwSYAKQEjCYJrzfajUGha9x0WTXgg6+tj6D05bTm 5jRtjjaw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2vM9-0004FE-Qz; Thu, 20 Sep 2018 09:34:41 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2vED-0007yC-Nf for linux-mediatek@bombadil.infradead.org; Thu, 20 Sep 2018 09:26:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=MSmurVW3MjFDe9dh1Bpf9O+qpwsMIWJeKHloxroZLKQ=; b=HJZXByDxtVBrZUcH2aurVEUkE ywPxOzYvXryG49w66Rd7qBzrpx5q65p24Y2dDFVinKMRntBSict0EU3URQf/yAqT4cUhbj0AEM6+u FTGQQKvPlxlgSswR0BdYum7huv+gYfjEWgQda5C6Rd3o5RDKFWhSG4A4BdSEskfBlPu0Z5UUYBA9j P9ndv7K0l6qdD+uQPjr4LuI7K5ePaE9bXxkO06WjgXI0BhiqeNhTc7QfFZX7iThegvXdS4UGE9Pc5 Enc1jfiKXAWibiepVmUrqQOU7YwBOTQLZ1ytQqJl/GGPPh/ASBgTFBD+8UlvayhesNZKNx3Z20Wu3 v3T1JrISw==; Received: from mail-wm1-f68.google.com ([209.85.128.68]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2v0q-0000Vi-6X for linux-mediatek@lists.infradead.org; Thu, 20 Sep 2018 09:12:41 +0000 Received: by mail-wm1-f68.google.com with SMTP id 207-v6so9998601wme.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=mynUBwH3vNw4fdUCEWDO3eqkSGjDxCJwoRKZ6y1OWU2ofGXA/nDAGqMscXkn1BBOPl 70QiapfsRIaDLuYjEBV7ktjrWKUkKPV1pDBLA6lOp+W21gKiSlg+QM5tnlNRVD5zNucW 6hitPRx5CA6dQ48RbzQcCi5hy1ULdDChH3n4PD6/SoGbg62ViQV6ggs/AYyMjzkZni54 q1zTvRm8MG+BMhqoOu7KDAigwOuOr7cbsy8aXU28++2kg6aLG5mbHmclxiFYk+rTd1ar L2q5yNXQlu+a2v5Nsbm2+Bw849PcERDWJjqNspRhoFUMEohZBklDNIHrNR133vMtuTNF /mPQ== X-Gm-Message-State: ABuFfogT5wChb0p4VqtpQ3ndpB5rJ4SlaUIdHySoIVav6bM7HcnVnycw W0T6dqsCII3ZHU2Ozcs4anRq9g== 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 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: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180920_051240_235932_0603C7B9 X-CRM114-Status: GOOD ( 17.21 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: sgruszka@redhat.com, linux-mediatek@lists.infradead.org, linux-wireless@vger.kernel.org MIME-Version: 1.0 Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.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);