From patchwork Thu Sep 20 09:12: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: 10607213 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 2FFCA6CB for ; Thu, 20 Sep 2018 09:13:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1E82B28BE6 for ; Thu, 20 Sep 2018 09:13:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1285528C00; Thu, 20 Sep 2018 09:13:28 +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 5768B28BE6 for ; Thu, 20 Sep 2018 09:13:27 +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=AFPun78h4EOraGMWYjx9fGTM4o35V6BXtltDToghzt8=; b=EiFYu7vGfAl+6y3aP4MmAQT1gp OSC+cF0NgXABPJejlCmvgJoQr/k1xH8XrBX/+Z88IgtHgfqY9T/hinokmHLNiwUdQS8iPrpbYvrnF Kh6QowrA7+vLi3iALOkdVcYB58Nq9EpR6naW/ABtLRLXy1M6CUACYfVY+0fwd+7CL7ympkWgWBlXU nhJ82qkHWfD12Fe+KM1Bxc3832Fg3jQMCxOqXIDs8kc6z1vSHflSb04kuSQTEjvao0NRSbAtXdgVQ L3+gDcwe6BFFlGKg3BDna2yem3lA3oRvxYWiDXyfa7H3jMozY3MYSllh6pRc01+NRelbnrigEe+ER TMNx2M2Q==; 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 1g2v1X-00029O-VZ; Thu, 20 Sep 2018 09:13:24 +0000 Received: from mail-wm1-f68.google.com ([209.85.128.68]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g2v15-00020y-Vb for linux-mediatek@lists.infradead.org; Thu, 20 Sep 2018 09:13:15 +0000 Received: by mail-wm1-f68.google.com with SMTP id y139-v6so9069230wmc.2 for ; Thu, 20 Sep 2018 02:12:45 -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=ZKjfPSutdl1HUQz8MRZwxCrzbj7Yh7aWLRviT6C6q5g=; b=m1hOiqupEGcNDtzbdREDAhCDE+TzWDmhRNz7Mf4qc3JRHkXd5/HzTG7IeVfs7hrOKy 6sBM4aX5gNFhjWR2nC925553rge3rxEXv9XfTZsRYv9pH7T1Y2qkCjGKUvaQEHz4XA4O 8BQJpibbr65VYBArv1n8X4DX0u5UGkySbOuNLjgbL9TQG6k12rYP3IvvTI+zbDVad7OZ DU0MQELaihVqZwvhZ35rgAHoV0wukiQ+2WdtNGqjBF4LLMIm5xrg094N6XRkzCuFocr3 9yJ7Y9M2+jsuswzAmtpKdYniLO/ExwMLXUK1v2Bt1MwwymA73jFC7LIx+vbUtpUkUFRh 1FIg== X-Gm-Message-State: APzg51Cle+E/OP6ATgrwLuwGIuGWcW/jqHfOabhMq9sGRy7bJUL8VSO4 EVHpmsL531Qz/n4gHm/IcDDJ2Q== X-Google-Smtp-Source: ANB0VdYnlPGGg/xWZc5z5DKhvw9oKOYSP1O47Oyh9BNfdHomxpJEMz4xSTgX3NF1Uv1dLZ4E41Wxdw== X-Received: by 2002:a1c:8587:: with SMTP id h129-v6mr1594380wmd.105.1537434764470; Thu, 20 Sep 2018 02:12:44 -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.43 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:43 -0700 (PDT) From: Lorenzo Bianconi To: nbd@nbd.name Subject: [PATCH 19/20] mt76x0: remove eeprom dependency from mt76x0_set_tx_power_per_chan Date: Thu, 20 Sep 2018 11:12:06 +0200 Message-Id: <818313ec8e94d1ebcefdcd5b778b6634909e7719.1537433365.git.lorenzo.bianconi@redhat.com> 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_021256_066029_F5A495CD X-CRM114-Status: GOOD ( 15.35 ) 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 In order to unify eeprom parsing between mt76x0 and mt76x2 drivers, remove eeprom pointer dependency from mt76x0_set_tx_power_per_chan routine. Remove mt76x0_eeprom_params since it is now an empty structure Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/debugfs.c | 4 +- .../wireless/mediatek/mt76/mt76x0/eeprom.c | 92 +++++++++++-------- .../wireless/mediatek/mt76/mt76x0/eeprom.h | 7 +- .../wireless/mediatek/mt76/mt76x0/mt76x0.h | 1 - .../net/wireless/mediatek/mt76/mt76x0/phy.c | 2 +- 5 files changed, 58 insertions(+), 48 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c index 46327cc90797..a34feead2cc4 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c @@ -115,9 +115,9 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data) val & MT_EE_NIC_CONF_0_PA_TYPE); seq_puts(file, "Per channel power:\n"); - for (i = 0; i < 58; i++) + for (i = 0; i < MT76X0_NUM_CHANS; i++) seq_printf(file, "\t%d chan:%d pwr:%d\n", i, i, - dev->ee->tx_pwr_per_chan[i]); + dev->caldata.tx_pwr_per_chan[i]); return 0; } diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index 1406e88141de..6db4610f5839 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -224,38 +224,57 @@ void mt76x0_set_tx_power_per_rate(struct mt76x0_dev *dev, t->vht[8] = mt76x0_get_power_rate(val >> 8, delta); } -static void -mt76x0_set_tx_power_per_chan(struct mt76x0_dev *dev, u8 *eeprom) +static void mt76x0_set_tx_power_per_chan(struct mt76x0_dev *dev) { + struct mt76x0_caldata *caldata = &dev->caldata; + u8 val, addr; + u16 data; int i; - u8 tx_pwr; - for (i = 0; i < 14; i++) { - tx_pwr = eeprom[MT_EE_TX_POWER_DELTA_BW80 + i]; - if (tx_pwr <= 0x3f && tx_pwr > 0) - dev->ee->tx_pwr_per_chan[i] = tx_pwr; + for (i = 0; i < 14; i += 2) { + addr = MT_EE_TX_POWER_DELTA_BW80 + i; + data = mt76x02_eeprom_get(&dev->mt76, addr); + + val = data; + if (val <= 0x3f && val > 0) + caldata->tx_pwr_per_chan[i] = val; + else + caldata->tx_pwr_per_chan[i] = 5; + + val = data >> 8; + if (val <= 0x3f && val > 0) + caldata->tx_pwr_per_chan[i + 1] = val; else - dev->ee->tx_pwr_per_chan[i] = 5; + caldata->tx_pwr_per_chan[i + 1] = 5; } - for (i = 0; i < 40; i++) { - tx_pwr = eeprom[MT_EE_TX_POWER_0_GRP4_TSSI_SLOPE + 2 + i]; - if (tx_pwr <= 0x3f && tx_pwr > 0) - dev->ee->tx_pwr_per_chan[14 + i] = tx_pwr; + for (i = 0; i < 40; i += 2) { + addr = MT_EE_TX_POWER_0_GRP4_TSSI_SLOPE + 2 + i; + data = mt76x02_eeprom_get(&dev->mt76, addr); + + val = data; + if (val <= 0x3f && val > 0) + caldata->tx_pwr_per_chan[14 + i] = val; + else + caldata->tx_pwr_per_chan[14 + i] = 5; + + val = data >> 8; + if (val <= 0x3f && val > 0) + caldata->tx_pwr_per_chan[15 + i] = val; else - dev->ee->tx_pwr_per_chan[14 + i] = 5; + caldata->tx_pwr_per_chan[15 + i] = 5; } - dev->ee->tx_pwr_per_chan[54] = dev->ee->tx_pwr_per_chan[22]; - dev->ee->tx_pwr_per_chan[55] = dev->ee->tx_pwr_per_chan[28]; - dev->ee->tx_pwr_per_chan[56] = dev->ee->tx_pwr_per_chan[34]; - dev->ee->tx_pwr_per_chan[57] = dev->ee->tx_pwr_per_chan[44]; + caldata->tx_pwr_per_chan[54] = caldata->tx_pwr_per_chan[22]; + caldata->tx_pwr_per_chan[55] = caldata->tx_pwr_per_chan[28]; + caldata->tx_pwr_per_chan[56] = caldata->tx_pwr_per_chan[34]; + caldata->tx_pwr_per_chan[57] = caldata->tx_pwr_per_chan[44]; } -int -mt76x0_eeprom_init(struct mt76x0_dev *dev) +int mt76x0_eeprom_init(struct mt76x0_dev *dev) { - u8 *eeprom; + u8 version, fae; + u16 data; int ret; ret = mt76x0_efuse_physical_size_check(dev); @@ -266,37 +285,32 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev) if (ret < 0) return ret; - dev->ee = devm_kzalloc(dev->mt76.dev, sizeof(*dev->ee), GFP_KERNEL); - if (!dev->ee) - return -ENOMEM; - - eeprom = kmalloc(MT76X0_EEPROM_SIZE, GFP_KERNEL); - if (!eeprom) - return -ENOMEM; - - ret = mt76x02_get_efuse_data(&dev->mt76, 0, eeprom, + ret = mt76x02_get_efuse_data(&dev->mt76, 0, dev->mt76.eeprom.data, MT76X0_EEPROM_SIZE, MT_EE_READ); if (ret) - goto out; + return ret; + + data = mt76x02_eeprom_get(&dev->mt76, MT_EE_VERSION); + version = data >> 8; + fae = data; - if (eeprom[MT_EE_VERSION + 1] > MT76X0U_EE_MAX_VER) + if (version > MT76X0U_EE_MAX_VER) dev_warn(dev->mt76.dev, "Warning: unsupported EEPROM version %02hhx\n", - eeprom[MT_EE_VERSION + 1]); + version); dev_info(dev->mt76.dev, "EEPROM ver:%02hhx fae:%02hhx\n", - eeprom[MT_EE_VERSION + 1], eeprom[MT_EE_VERSION]); + version, fae); - mt76x02_mac_setaddr(&dev->mt76, eeprom + MT_EE_MAC_ADDR); + mt76x02_mac_setaddr(&dev->mt76, + dev->mt76.eeprom.data + MT_EE_MAC_ADDR); mt76x0_set_chip_cap(dev); mt76x0_set_freq_offset(dev); mt76x0_set_temp_offset(dev); - dev->chainmask = 0x0101; + mt76x0_set_tx_power_per_chan(dev); - mt76x0_set_tx_power_per_chan(dev, eeprom); + dev->chainmask = 0x0101; -out: - kfree(eeprom); - return ret; + return 0; } MODULE_LICENSE("Dual BSD/GPL"); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h index 88e31186c317..23b83a5ca098 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h @@ -28,6 +28,7 @@ struct reg_channel_bounds { u8 num; }; +#define MT76X0_NUM_CHANS 58 struct mt76x0_caldata { s8 rssi_offset[2]; s8 lna_gain; @@ -35,14 +36,10 @@ struct mt76x0_caldata { s16 temp_offset; u8 freq_offset; + u8 tx_pwr_per_chan[MT76X0_NUM_CHANS]; struct mt76_rate_power rate_power; }; -struct mt76x0_eeprom_params { - - u8 tx_pwr_per_chan[58]; -}; - int mt76x0_eeprom_init(struct mt76x0_dev *dev); void mt76x0_read_rx_gain(struct mt76x0_dev *dev); void mt76x0_set_tx_power_per_rate(struct mt76x0_dev *dev, diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h index 99d48fa96fd9..101332a35f40 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h @@ -89,7 +89,6 @@ struct mt76x0_dev { const u16 *beacon_offsets; - struct mt76x0_eeprom_params *ee; struct mt76x0_caldata caldata; struct mutex reg_atomic_mutex; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index 52cd39fbfd49..8f428f6c5333 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -633,7 +633,7 @@ mt76x0_phy_set_chan_pwr(struct mt76x0_dev *dev, u8 channel) val = mt76_rr(dev, MT_TX_ALC_CFG_0); val &= ~0x3f3f; - val |= dev->ee->tx_pwr_per_chan[i]; + val |= dev->caldata.tx_pwr_per_chan[i]; val |= 0x2f2f << 16; mt76_wr(dev, MT_TX_ALC_CFG_0, val); }