From patchwork Thu Sep 20 09:11:48 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607165 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 45ABD6CB for ; Thu, 20 Sep 2018 09:12:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 360EE2CC13 for ; Thu, 20 Sep 2018 09:12:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2A3F22CC26; Thu, 20 Sep 2018 09:12: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=-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 BD53A2CC13 for ; Thu, 20 Sep 2018 09:12:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731689AbeITOyz (ORCPT ); Thu, 20 Sep 2018 10:54:55 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:37278 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731665AbeITOyy (ORCPT ); Thu, 20 Sep 2018 10:54:54 -0400 Received: by mail-wr1-f67.google.com with SMTP id u12-v6so8580730wrr.4 for ; Thu, 20 Sep 2018 02:12:25 -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=CP8V5OkdU81ZZErBUxE2LyQjjz+NRtj0pdjdYtJzswM=; b=GvRzs+P5OO2y5XzAVfo1TudLwP/bFYEiF2NBO+xC1IqtgJQbKvVhZtYD+JhCgwumnl vJXha/zyX4GDCx7HrHAh1NF3035azRneJkREYR2Yu4nSCVaswXEsf64rdTxqSAUOPMXP fkR0z5UkvLARNjiII9gfutLYzHkC/xUuokm3EU9ap+eA1DnPGIAYGIKItNQ+fy/vj43I 5vihdbRoXNhkDmazXhofvT7aFDljH3pO4cMetJNG0RtawhkB71lhGSa52V+kXC63xQ2i UEmQYxgYYETd2tdpvNY9HVZdfEuzYg5De4UllqJVQnyFmFfUkU0+FPRAnw7Ha5tUkFXO w6yg== X-Gm-Message-State: APzg51AnwmoByQi2UR7wv9NA78r61ze0xVo5noOuT99CyxRLFMadrQRN us1ri1b2uTeZEl6xp+yYE+T41aB1oDA= X-Google-Smtp-Source: ANB0VdbD2q756Jt5L32W4ixBudZI1BkQws4C8+K+ilCRrODHhuZk0b+pQ0dBsXz6m6GV/udaS3Tidw== X-Received: by 2002:adf:f984:: with SMTP id f4-v6mr32801750wrr.105.1537434744899; Thu, 20 Sep 2018 02:12:24 -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.23 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:24 -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 01/20] mt76: move seq_put_array in mt76-core module Date: Thu, 20 Sep 2018 11:11:48 +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 seq_put_array utility routine in mt76-core module in order to be reused in mt76x0 driver Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/debugfs.c | 12 +++++++ drivers/net/wireless/mediatek/mt76/mt76.h | 2 ++ .../wireless/mediatek/mt76/mt76x2_debugfs.c | 31 ++++++------------- 3 files changed, 24 insertions(+), 21 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/debugfs.c b/drivers/net/wireless/mediatek/mt76/debugfs.c index a38d05dea599..03ce635334fa 100644 --- a/drivers/net/wireless/mediatek/mt76/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/debugfs.c @@ -56,6 +56,18 @@ mt76_queues_read(struct seq_file *s, void *data) return 0; } +void mt76_seq_puts_array(struct seq_file *file, const char *str, + s8 *val, int len) +{ + int i; + + seq_printf(file, "%10s:", str); + for (i = 0; i < len; i++) + seq_printf(file, " %2d", val[i]); + seq_puts(file, "\n"); +} +EXPORT_SYMBOL_GPL(mt76_seq_puts_array); + struct dentry *mt76_register_debugfs(struct mt76_dev *dev) { struct dentry *dir; diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index dbda49243a10..b4980959efa7 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -539,6 +539,8 @@ int mt76_register_device(struct mt76_dev *dev, bool vht, void mt76_unregister_device(struct mt76_dev *dev); struct dentry *mt76_register_debugfs(struct mt76_dev *dev); +void mt76_seq_puts_array(struct seq_file *file, const char *str, + s8 *val, int len); int mt76_eeprom_init(struct mt76_dev *dev, int len); void mt76_eeprom_override(struct mt76_dev *dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x2_debugfs.c index 77b5ff1be05f..2cd0d8200a57 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_debugfs.c @@ -47,33 +47,22 @@ mt76x2_ampdu_stat_open(struct inode *inode, struct file *f) return single_open(f, mt76x2_ampdu_stat_read, inode->i_private); } -static void -seq_puts_array(struct seq_file *file, const char *str, s8 *val, int len) -{ - int i; - - seq_printf(file, "%10s:", str); - for (i = 0; i < len; i++) - seq_printf(file, " %2d", val[i]); - seq_puts(file, "\n"); -} - static int read_txpower(struct seq_file *file, void *data) { struct mt76x2_dev *dev = dev_get_drvdata(file->private); seq_printf(file, "Target power: %d\n", dev->target_power); - seq_puts_array(file, "Delta", dev->target_power_delta, - ARRAY_SIZE(dev->target_power_delta)); - seq_puts_array(file, "CCK", dev->rate_power.cck, - ARRAY_SIZE(dev->rate_power.cck)); - seq_puts_array(file, "OFDM", dev->rate_power.ofdm, - ARRAY_SIZE(dev->rate_power.ofdm)); - seq_puts_array(file, "HT", dev->rate_power.ht, - ARRAY_SIZE(dev->rate_power.ht)); - seq_puts_array(file, "VHT", dev->rate_power.vht, - ARRAY_SIZE(dev->rate_power.vht)); + mt76_seq_puts_array(file, "Delta", dev->target_power_delta, + ARRAY_SIZE(dev->target_power_delta)); + mt76_seq_puts_array(file, "CCK", dev->rate_power.cck, + ARRAY_SIZE(dev->rate_power.cck)); + mt76_seq_puts_array(file, "OFDM", dev->rate_power.ofdm, + ARRAY_SIZE(dev->rate_power.ofdm)); + mt76_seq_puts_array(file, "HT", dev->rate_power.ht, + ARRAY_SIZE(dev->rate_power.ht)); + mt76_seq_puts_array(file, "VHT", dev->rate_power.vht, + ARRAY_SIZE(dev->rate_power.vht)); return 0; } From patchwork Thu Sep 20 09:11:49 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607167 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 A82CF1390 for ; Thu, 20 Sep 2018 09:12:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 981DC2CC13 for ; Thu, 20 Sep 2018 09:12:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8A5642CC26; Thu, 20 Sep 2018 09:12:29 +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 EEFB82CC21 for ; Thu, 20 Sep 2018 09:12:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387428AbeITOy4 (ORCPT ); Thu, 20 Sep 2018 10:54:56 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:46105 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731678AbeITOyz (ORCPT ); Thu, 20 Sep 2018 10:54:55 -0400 Received: by mail-wr1-f68.google.com with SMTP id a108-v6so8565833wrc.13 for ; Thu, 20 Sep 2018 02:12:26 -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=Nx/oFJUqavrXoksHdEJWvyNDiQ0daeQdzoA/Hbd2oZo=; b=Cu+O7X5DR63Vhm3NYjeIA031XpCuMFqzPXPSbm1JscZIyShUo+UlIjOCxFBFxd4wKC iLtN77WOXmTZqvYzX+/KwoIwmRXWr+UKokoyG6+nCNOKYxoXYx3KUoD5Lq8RDQUTPYUv ojGy3K81RuuyUxbdzIO37Zn5JbrLMYgQTlvk9zmNyVOE/w2waqWqCO4n7DhvJ1lXvHKs Hw6BCGeSR+0AIEUxs47ERMn0qUloT87r0X6nHKkzWGZyypHVkMN/qrHeql4sUis0zWli r4BGoCkpptrHeGlbNFB6vuK0PSP+iwc3kumhb4pD6MJKv2qLMm8P80gdYIZjAw+M78Qy 5u7w== X-Gm-Message-State: APzg51D3xBl4grlux4ltcVtClFkXA0XeOgN9ZJs98p8mz7VEUZZCFQ9/ zZAUun0J8wwC7CwKxKhqwUkevw== X-Google-Smtp-Source: ANB0VdboOXKqdKuQcoiow54OZfeDcUZXA/WThVMYKhtjqaLWPWIBesfk7E4sP+3O3xqyjJMO9PEGtQ== X-Received: by 2002:a5d:4990:: with SMTP id r16-v6mr32669229wrq.116.1537434745938; Thu, 20 Sep 2018 02:12:25 -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.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:25 -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 02/20] mt76: add stbc entries to mt76_rate_power Date: Thu, 20 Sep 2018 11:11:49 +0200 Message-Id: <15d756db7fef57befcc2e2e28e640be10493df88.1537433365.git.lorenzo.bianconi@redhat.com> 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 From: Felix Fietkau Add stbc tx power eeprom parsing support for mt76x2 driver. Signed-off-by: Felix Fietkau Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt76.h | 3 ++- drivers/net/wireless/mediatek/mt76/mt76x2_debugfs.c | 2 ++ drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c | 1 + drivers/net/wireless/mediatek/mt76/mt76x2_phy_common.c | 4 ++-- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76.h b/drivers/net/wireless/mediatek/mt76/mt76.h index b4980959efa7..9febace6ef23 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76.h +++ b/drivers/net/wireless/mediatek/mt76/mt76.h @@ -423,10 +423,11 @@ struct mt76_rate_power { struct { s8 cck[4]; s8 ofdm[8]; + s8 stbc[8]; s8 ht[16]; s8 vht[10]; }; - s8 all[38]; + s8 all[46]; }; }; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x2_debugfs.c index 2cd0d8200a57..45f3439a6563 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_debugfs.c @@ -59,6 +59,8 @@ static int read_txpower(struct seq_file *file, void *data) ARRAY_SIZE(dev->rate_power.cck)); mt76_seq_puts_array(file, "OFDM", dev->rate_power.ofdm, ARRAY_SIZE(dev->rate_power.ofdm)); + mt76_seq_puts_array(file, "STBC", dev->rate_power.stbc, + ARRAY_SIZE(dev->rate_power.stbc)); mt76_seq_puts_array(file, "HT", dev->rate_power.ht, ARRAY_SIZE(dev->rate_power.ht)); mt76_seq_puts_array(file, "VHT", dev->rate_power.vht, diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c index 1753bcb36356..807bf46e0dd9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c @@ -461,6 +461,7 @@ void mt76x2_get_rate_power(struct mt76x2_dev *dev, struct mt76_rate_power *t, val = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_HT_MCS4); t->ht[4] = t->ht[5] = mt76x2_rate_power_val(val); t->ht[6] = t->ht[7] = mt76x2_rate_power_val(val >> 8); + memcpy(t->stbc, t->ht, sizeof(t->stbc)); val = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_HT_MCS8); t->ht[8] = t->ht[9] = mt76x2_rate_power_val(val); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_phy_common.c b/drivers/net/wireless/mediatek/mt76/mt76x2_phy_common.c index 3b704a70fad1..42ca855c7579 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_phy_common.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_phy_common.c @@ -227,9 +227,9 @@ void mt76x2_phy_set_txpower(struct mt76x2_dev *dev) mt76_wr(dev, MT_TX_PWR_CFG_2, mt76x2_tx_power_mask(t.ht[4], t.ht[6], t.ht[8], t.ht[10])); mt76_wr(dev, MT_TX_PWR_CFG_3, - mt76x2_tx_power_mask(t.ht[12], t.ht[14], t.ht[0], t.ht[2])); + mt76x2_tx_power_mask(t.ht[12], t.ht[14], t.stbc[0], t.stbc[2])); mt76_wr(dev, MT_TX_PWR_CFG_4, - mt76x2_tx_power_mask(t.ht[4], t.ht[6], 0, 0)); + mt76x2_tx_power_mask(t.stbc[4], t.stbc[6], 0, 0)); mt76_wr(dev, MT_TX_PWR_CFG_7, mt76x2_tx_power_mask(t.ofdm[6], t.vht[8], t.ht[6], t.vht[8])); mt76_wr(dev, MT_TX_PWR_CFG_8, From patchwork Thu Sep 20 09:11:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607169 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 79BF51390 for ; Thu, 20 Sep 2018 09:12:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 670682CC21 for ; Thu, 20 Sep 2018 09:12:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5939F2CC43; Thu, 20 Sep 2018 09:12:31 +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 661542CC21 for ; Thu, 20 Sep 2018 09:12:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387438AbeITOy5 (ORCPT ); Thu, 20 Sep 2018 10:54:57 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:34847 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387420AbeITOy5 (ORCPT ); Thu, 20 Sep 2018 10:54:57 -0400 Received: by mail-wm1-f66.google.com with SMTP id o18-v6so10079803wmc.0 for ; Thu, 20 Sep 2018 02:12:28 -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=3A/Vpdb4V4BsG+yXsOcvheEnv1f+Ua2CkLYbM+p9pyI=; b=elcD5m0ruRmtEQxkFKrBuUWwjqI7RfcZ+vX3PVKbn1gzmWT2Bg4lg7Y4V81d3EGpAZ 09U3E+HlAu3DuFglk2om+M5uwJvqsLMr3WhSJkEmzPnGHxfXaoGJclkpdNP5RY0oylpm zbFw2GXLC5VBOIdqzT7IIXCbYZTcXvqzihg2D5XN3aUX6JieQek+X2UiRpaG8ctrdAxI qQj+nT8DFfWgroUJ7Tr2lRDsvWw8HbVquIaG1297L7VOhd6lCHTQd4uufun9v33f+dCY T2NDogWYT2+GqbShBYREiPdQOFoSBCi2CaHuy+jG4JKoaPxdjTbGzd0eCdByZHmMVfgF r20w== X-Gm-Message-State: APzg51DZ82/5CXJMjqzQaYqrKl/6p5Ee71M/JbKJwe7QCOh3qJT6wMDu c16WpuJPUokF0J4KSxTdHHXKfw== X-Google-Smtp-Source: ANB0VdbTrk5EKaIHcJLY0riOJZDVLBeLLNPKupX4V6Bcf90Art3v/P03g9q2uSP+Tzsz3CwZ90Dsfg== X-Received: by 2002:a1c:a8d0:: with SMTP id r199-v6mr1560976wme.97.1537434747106; Thu, 20 Sep 2018 02:12:27 -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.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:26 -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 03/20] mt76: move common eeprom definitions in mt76x02-lib module Date: Thu, 20 Sep 2018 11:11:50 +0200 Message-Id: <14b5f6a780701abd9b88ed23857059afcd38e854.1537433365.git.lorenzo.bianconi@redhat.com> 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 mt76x2 and mt76x0 common definitions in mt76x02_eeprom.h and remove duplicated code Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/eeprom.c | 18 +-- .../wireless/mediatek/mt76/mt76x0/eeprom.h | 71 +--------- .../wireless/mediatek/mt76/mt76x02_eeprom.h | 124 ++++++++++++++++++ .../wireless/mediatek/mt76/mt76x2_eeprom.c | 2 +- .../wireless/mediatek/mt76/mt76x2_eeprom.h | 85 +----------- 5 files changed, 140 insertions(+), 160 deletions(-) create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index 79856bde1632..8a8244c1cdaa 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -245,8 +245,8 @@ mt76x0_set_lna_gain(struct mt76x0_dev *dev, u8 *eeprom) { u8 gain; - dev->ee->lna_gain_2ghz = eeprom[MT_EE_LNA_GAIN_2GHZ]; - dev->ee->lna_gain_5ghz[0] = eeprom[MT_EE_LNA_GAIN_5GHZ_0]; + dev->ee->lna_gain_2ghz = eeprom[MT_EE_LNA_GAIN]; + dev->ee->lna_gain_5ghz[0] = eeprom[MT_EE_LNA_GAIN + 1]; gain = eeprom[MT_EE_LNA_GAIN_5GHZ_1]; if (gain == 0xff || gain == 0) @@ -268,7 +268,7 @@ mt76x0_set_rssi_offset(struct mt76x0_dev *dev, u8 *eeprom) s8 *rssi_offset = dev->ee->rssi_offset_2ghz; for (i = 0; i < 2; i++) { - rssi_offset[i] = eeprom[MT_EE_RSSI_OFFSET + i]; + rssi_offset[i] = eeprom[MT_EE_RSSI_OFFSET_2G_0 + i]; if (rssi_offset[i] < -10 || rssi_offset[i] > 10) { dev_warn(dev->mt76.dev, @@ -281,7 +281,7 @@ mt76x0_set_rssi_offset(struct mt76x0_dev *dev, u8 *eeprom) rssi_offset = dev->ee->rssi_offset_5ghz; for (i = 0; i < 3; i++) { - rssi_offset[i] = eeprom[MT_EE_RSSI_OFFSET_5GHZ + i]; + rssi_offset[i] = eeprom[MT_EE_RSSI_OFFSET_5G_0 + i]; if (rssi_offset[i] < -10 || rssi_offset[i] > 10) { dev_warn(dev->mt76.dev, @@ -377,7 +377,7 @@ mt76x0_set_tx_power_per_chan(struct mt76x0_dev *dev, u8 *eeprom) u8 tx_pwr; for (i = 0; i < 14; i++) { - tx_pwr = eeprom[MT_EE_TX_POWER_OFFSET_2GHZ + 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; else @@ -385,7 +385,7 @@ mt76x0_set_tx_power_per_chan(struct mt76x0_dev *dev, u8 *eeprom) } for (i = 0; i < 40; i++) { - tx_pwr = eeprom[MT_EE_TX_POWER_OFFSET_5GHZ + 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; else @@ -422,12 +422,12 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev) goto out; } - if (eeprom[MT_EE_VERSION_EE] > MT76X0U_EE_MAX_VER) + if (eeprom[MT_EE_VERSION + 1] > MT76X0U_EE_MAX_VER) dev_warn(dev->mt76.dev, "Warning: unsupported EEPROM version %02hhx\n", - eeprom[MT_EE_VERSION_EE]); + eeprom[MT_EE_VERSION + 1]); dev_info(dev->mt76.dev, "EEPROM ver:%02hhx fae:%02hhx\n", - eeprom[MT_EE_VERSION_EE], eeprom[MT_EE_VERSION_FAE]); + eeprom[MT_EE_VERSION + 1], eeprom[MT_EE_VERSION]); mt76x0_set_macaddr(dev, eeprom); mt76x0_set_chip_cap(dev, eeprom); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h index cd0f14361405..1da90f056442 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h @@ -16,75 +16,12 @@ #ifndef __MT76X0U_EEPROM_H #define __MT76X0U_EEPROM_H -struct mt76x0_dev; - -#define MT76X0U_EE_MAX_VER 0x0c -#define MT76X0_EEPROM_SIZE 512 - -#define MT76X0U_DEFAULT_TX_POWER 6 - -enum mt76_eeprom_field { - MT_EE_CHIP_ID = 0x00, - MT_EE_VERSION_FAE = 0x02, - MT_EE_VERSION_EE = 0x03, - MT_EE_MAC_ADDR = 0x04, - MT_EE_NIC_CONF_0 = 0x34, - MT_EE_NIC_CONF_1 = 0x36, - MT_EE_COUNTRY_REGION_5GHZ = 0x38, - MT_EE_COUNTRY_REGION_2GHZ = 0x39, - MT_EE_FREQ_OFFSET = 0x3a, - MT_EE_NIC_CONF_2 = 0x42, - - MT_EE_LNA_GAIN_2GHZ = 0x44, - MT_EE_LNA_GAIN_5GHZ_0 = 0x45, - MT_EE_RSSI_OFFSET = 0x46, - MT_EE_RSSI_OFFSET_5GHZ = 0x4a, - MT_EE_LNA_GAIN_5GHZ_1 = 0x49, - MT_EE_LNA_GAIN_5GHZ_2 = 0x4d, - - MT_EE_TX_POWER_DELTA_BW40 = 0x50, - - MT_EE_TX_POWER_OFFSET_2GHZ = 0x52, +#include "../mt76x02_eeprom.h" - MT_EE_TX_TSSI_SLOPE = 0x6e, - MT_EE_TX_TSSI_OFFSET_GROUP = 0x6f, - MT_EE_TX_TSSI_OFFSET = 0x76, - - MT_EE_TX_POWER_OFFSET_5GHZ = 0x78, - - MT_EE_TEMP_OFFSET = 0xd1, - MT_EE_FREQ_OFFSET_COMPENSATION = 0xdb, - MT_EE_TX_POWER_BYRATE_BASE = 0xde, - - MT_EE_TX_POWER_BYRATE_BASE_5GHZ = 0x120, - - MT_EE_USAGE_MAP_START = 0x1e0, - MT_EE_USAGE_MAP_END = 0x1fc, -}; +struct mt76x0_dev; -#define MT_EE_NIC_CONF_0_RX_PATH GENMASK(3, 0) -#define MT_EE_NIC_CONF_0_TX_PATH GENMASK(7, 4) -#define MT_EE_NIC_CONF_0_PA_TYPE GENMASK(9, 8) -#define MT_EE_NIC_CONF_0_BOARD_TYPE GENMASK(13, 12) - -#define MT_EE_NIC_CONF_1_HW_RF_CTRL BIT(0) -#define MT_EE_NIC_CONF_1_TEMP_TX_ALC BIT(1) -#define MT_EE_NIC_CONF_1_LNA_EXT_2G BIT(2) -#define MT_EE_NIC_CONF_1_LNA_EXT_5G BIT(3) -#define MT_EE_NIC_CONF_1_TX_ALC_EN BIT(13) - -#define MT_EE_NIC_CONF_2_RX_STREAM GENMASK(3, 0) -#define MT_EE_NIC_CONF_2_TX_STREAM GENMASK(7, 4) -#define MT_EE_NIC_CONF_2_HW_ANTDIV BIT(8) -#define MT_EE_NIC_CONF_2_XTAL_OPTION GENMASK(10, 9) -#define MT_EE_NIC_CONF_2_TEMP_DISABLE BIT(11) -#define MT_EE_NIC_CONF_2_COEX_METHOD GENMASK(15, 13) - -#define MT_EE_TX_POWER_BYRATE(i) (MT_EE_TX_POWER_BYRATE_BASE + \ - (i) * 4) - -#define MT_EFUSE_USAGE_MAP_SIZE (MT_EE_USAGE_MAP_END - \ - MT_EE_USAGE_MAP_START + 1) +#define MT76X0U_EE_MAX_VER 0x0c +#define MT76X0_EEPROM_SIZE 512 enum mt76x0_eeprom_access_modes { MT_EE_READ = 0, diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h new file mode 100644 index 000000000000..d50387f2ef46 --- /dev/null +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h @@ -0,0 +1,124 @@ +/* + * Copyright (C) 2016 Felix Fietkau + * Copyright (C) 2018 Lorenzo Bianconi + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef __MT76x02_EEPROM_H +#define __MT76x02_EEPROM_H + +enum mt76x02_eeprom_field { + MT_EE_CHIP_ID = 0x000, + MT_EE_VERSION = 0x002, + MT_EE_MAC_ADDR = 0x004, + MT_EE_PCI_ID = 0x00A, + MT_EE_NIC_CONF_0 = 0x034, + MT_EE_NIC_CONF_1 = 0x036, + MT_EE_COUNTRY_REGION_5GHZ = 0x038, + MT_EE_COUNTRY_REGION_2GHZ = 0x039, + MT_EE_FREQ_OFFSET = 0x03a, + MT_EE_NIC_CONF_2 = 0x042, + + MT_EE_XTAL_TRIM_1 = 0x03a, + MT_EE_XTAL_TRIM_2 = 0x09e, + + MT_EE_LNA_GAIN = 0x044, + MT_EE_RSSI_OFFSET_2G_0 = 0x046, + MT_EE_RSSI_OFFSET_2G_1 = 0x048, + MT_EE_LNA_GAIN_5GHZ_1 = 0x049, + MT_EE_RSSI_OFFSET_5G_0 = 0x04a, + MT_EE_RSSI_OFFSET_5G_1 = 0x04c, + MT_EE_LNA_GAIN_5GHZ_2 = 0x04d, + + MT_EE_TX_POWER_DELTA_BW40 = 0x050, + MT_EE_TX_POWER_DELTA_BW80 = 0x052, + + MT_EE_TX_POWER_EXT_PA_5G = 0x054, + + MT_EE_TX_POWER_0_START_2G = 0x056, + MT_EE_TX_POWER_1_START_2G = 0x05c, + + /* used as byte arrays */ +#define MT_TX_POWER_GROUP_SIZE_5G 5 +#define MT_TX_POWER_GROUPS_5G 6 + MT_EE_TX_POWER_0_START_5G = 0x062, + + MT_EE_TX_POWER_0_GRP3_TX_POWER_DELTA = 0x074, + MT_EE_TX_POWER_0_GRP4_TSSI_SLOPE = 0x076, + + MT_EE_TX_POWER_1_START_5G = 0x080, + + MT_EE_TX_POWER_CCK = 0x0a0, + MT_EE_TX_POWER_OFDM_2G_6M = 0x0a2, + MT_EE_TX_POWER_OFDM_2G_24M = 0x0a4, + MT_EE_TX_POWER_OFDM_5G_6M = 0x0b2, + MT_EE_TX_POWER_OFDM_5G_24M = 0x0b4, + MT_EE_TX_POWER_HT_MCS0 = 0x0a6, + MT_EE_TX_POWER_HT_MCS4 = 0x0a8, + MT_EE_TX_POWER_HT_MCS8 = 0x0aa, + MT_EE_TX_POWER_HT_MCS12 = 0x0ac, + MT_EE_TX_POWER_VHT_MCS0 = 0x0ba, + MT_EE_TX_POWER_VHT_MCS4 = 0x0bc, + MT_EE_TX_POWER_VHT_MCS8 = 0x0be, + + MT_EE_TEMP_OFFSET = 0x0d1, + MT_EE_FREQ_OFFSET_COMPENSATION = 0x0db, + MT_EE_TX_POWER_BYRATE_BASE = 0x0de, + + MT_EE_RF_TEMP_COMP_SLOPE_5G = 0x0f2, + MT_EE_RF_TEMP_COMP_SLOPE_2G = 0x0f4, + + MT_EE_RF_2G_TSSI_OFF_TXPOWER = 0x0f6, + MT_EE_RF_2G_RX_HIGH_GAIN = 0x0f8, + MT_EE_RF_5G_GRP0_1_RX_HIGH_GAIN = 0x0fa, + MT_EE_RF_5G_GRP2_3_RX_HIGH_GAIN = 0x0fc, + MT_EE_RF_5G_GRP4_5_RX_HIGH_GAIN = 0x0fe, + + MT_EE_BT_RCAL_RESULT = 0x138, + MT_EE_BT_VCDL_CALIBRATION = 0x13c, + MT_EE_BT_PMUCFG = 0x13e, + + MT_EE_USAGE_MAP_START = 0x1e0, + MT_EE_USAGE_MAP_END = 0x1fc, + + __MT_EE_MAX +}; + +#define MT_EE_NIC_CONF_0_RX_PATH GENMASK(3, 0) +#define MT_EE_NIC_CONF_0_TX_PATH GENMASK(7, 4) +#define MT_EE_NIC_CONF_0_PA_TYPE GENMASK(9, 8) +#define MT_EE_NIC_CONF_0_PA_INT_2G BIT(8) +#define MT_EE_NIC_CONF_0_PA_INT_5G BIT(9) +#define MT_EE_NIC_CONF_0_BOARD_TYPE GENMASK(13, 12) + +#define MT_EE_NIC_CONF_1_HW_RF_CTRL BIT(0) +#define MT_EE_NIC_CONF_1_TEMP_TX_ALC BIT(1) +#define MT_EE_NIC_CONF_1_LNA_EXT_2G BIT(2) +#define MT_EE_NIC_CONF_1_LNA_EXT_5G BIT(3) +#define MT_EE_NIC_CONF_1_TX_ALC_EN BIT(13) + +#define MT_EE_NIC_CONF_2_RX_STREAM GENMASK(3, 0) +#define MT_EE_NIC_CONF_2_TX_STREAM GENMASK(7, 4) +#define MT_EE_NIC_CONF_2_HW_ANTDIV BIT(8) +#define MT_EE_NIC_CONF_2_XTAL_OPTION GENMASK(10, 9) +#define MT_EE_NIC_CONF_2_TEMP_DISABLE BIT(11) +#define MT_EE_NIC_CONF_2_COEX_METHOD GENMASK(15, 13) + +#define MT_EE_TX_POWER_BYRATE(x) (MT_EE_TX_POWER_BYRATE_BASE + \ + (x) * 4) + +#define MT_EFUSE_USAGE_MAP_SIZE (MT_EE_USAGE_MAP_END - \ + MT_EE_USAGE_MAP_START + 1) + +#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 807bf46e0dd9..7c3d65f9d18d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c @@ -21,7 +21,7 @@ #define EE_FIELD(_name, _value) [MT_EE_##_name] = (_value) | 1 static int -mt76x2_eeprom_copy(struct mt76x2_dev *dev, enum mt76x2_eeprom_field field, +mt76x2_eeprom_copy(struct mt76x2_dev *dev, enum mt76x02_eeprom_field field, void *dest, int len) { if (field + len > dev->mt76.eeprom.size) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h index 0f3e4d2f4fee..64b91fb57e3b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h @@ -17,88 +17,7 @@ #ifndef __MT76x2_EEPROM_H #define __MT76x2_EEPROM_H -#include "mt76x2.h" - -enum mt76x2_eeprom_field { - MT_EE_CHIP_ID = 0x000, - MT_EE_VERSION = 0x002, - MT_EE_MAC_ADDR = 0x004, - MT_EE_PCI_ID = 0x00A, - MT_EE_NIC_CONF_0 = 0x034, - MT_EE_NIC_CONF_1 = 0x036, - MT_EE_NIC_CONF_2 = 0x042, - - MT_EE_XTAL_TRIM_1 = 0x03a, - MT_EE_XTAL_TRIM_2 = 0x09e, - - MT_EE_LNA_GAIN = 0x044, - MT_EE_RSSI_OFFSET_2G_0 = 0x046, - MT_EE_RSSI_OFFSET_2G_1 = 0x048, - MT_EE_RSSI_OFFSET_5G_0 = 0x04a, - MT_EE_RSSI_OFFSET_5G_1 = 0x04c, - - MT_EE_TX_POWER_DELTA_BW40 = 0x050, - MT_EE_TX_POWER_DELTA_BW80 = 0x052, - - MT_EE_TX_POWER_EXT_PA_5G = 0x054, - - MT_EE_TX_POWER_0_START_2G = 0x056, - MT_EE_TX_POWER_1_START_2G = 0x05c, - - /* used as byte arrays */ -#define MT_TX_POWER_GROUP_SIZE_5G 5 -#define MT_TX_POWER_GROUPS_5G 6 - MT_EE_TX_POWER_0_START_5G = 0x062, - - MT_EE_TX_POWER_0_GRP3_TX_POWER_DELTA = 0x074, - MT_EE_TX_POWER_0_GRP4_TSSI_SLOPE = 0x076, - - MT_EE_TX_POWER_1_START_5G = 0x080, - - MT_EE_TX_POWER_CCK = 0x0a0, - MT_EE_TX_POWER_OFDM_2G_6M = 0x0a2, - MT_EE_TX_POWER_OFDM_2G_24M = 0x0a4, - MT_EE_TX_POWER_OFDM_5G_6M = 0x0b2, - MT_EE_TX_POWER_OFDM_5G_24M = 0x0b4, - MT_EE_TX_POWER_HT_MCS0 = 0x0a6, - MT_EE_TX_POWER_HT_MCS4 = 0x0a8, - MT_EE_TX_POWER_HT_MCS8 = 0x0aa, - MT_EE_TX_POWER_HT_MCS12 = 0x0ac, - MT_EE_TX_POWER_VHT_MCS0 = 0x0ba, - MT_EE_TX_POWER_VHT_MCS4 = 0x0bc, - MT_EE_TX_POWER_VHT_MCS8 = 0x0be, - - MT_EE_RF_TEMP_COMP_SLOPE_5G = 0x0f2, - MT_EE_RF_TEMP_COMP_SLOPE_2G = 0x0f4, - - MT_EE_RF_2G_TSSI_OFF_TXPOWER = 0x0f6, - MT_EE_RF_2G_RX_HIGH_GAIN = 0x0f8, - MT_EE_RF_5G_GRP0_1_RX_HIGH_GAIN = 0x0fa, - MT_EE_RF_5G_GRP2_3_RX_HIGH_GAIN = 0x0fc, - MT_EE_RF_5G_GRP4_5_RX_HIGH_GAIN = 0x0fe, - - MT_EE_BT_RCAL_RESULT = 0x138, - MT_EE_BT_VCDL_CALIBRATION = 0x13c, - MT_EE_BT_PMUCFG = 0x13e, - - __MT_EE_MAX -}; - -#define MT_EE_NIC_CONF_0_PA_INT_2G BIT(8) -#define MT_EE_NIC_CONF_0_PA_INT_5G BIT(9) -#define MT_EE_NIC_CONF_0_BOARD_TYPE GENMASK(13, 12) - -#define MT_EE_NIC_CONF_1_TEMP_TX_ALC BIT(1) -#define MT_EE_NIC_CONF_1_LNA_EXT_2G BIT(2) -#define MT_EE_NIC_CONF_1_LNA_EXT_5G BIT(3) -#define MT_EE_NIC_CONF_1_TX_ALC_EN BIT(13) - -#define MT_EE_NIC_CONF_2_RX_STREAM GENMASK(3, 0) -#define MT_EE_NIC_CONF_2_TX_STREAM GENMASK(7, 4) -#define MT_EE_NIC_CONF_2_HW_ANTDIV BIT(8) -#define MT_EE_NIC_CONF_2_XTAL_OPTION GENMASK(10, 9) -#define MT_EE_NIC_CONF_2_TEMP_DISABLE BIT(11) -#define MT_EE_NIC_CONF_2_COEX_METHOD GENMASK(15, 13) +#include "mt76x02_eeprom.h" enum mt76x2_board_type { BOARD_TYPE_2GHZ = 1, @@ -138,7 +57,7 @@ struct mt76x2_temp_comp { }; static inline int -mt76x2_eeprom_get(struct mt76x2_dev *dev, enum mt76x2_eeprom_field field) +mt76x2_eeprom_get(struct mt76x2_dev *dev, enum mt76x02_eeprom_field field) { if ((field & 1) || field >= __MT_EE_MAX) return -1; 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); From patchwork Thu Sep 20 09:11:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607179 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 F01D9161F 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 DE9D52CC13 for ; Thu, 20 Sep 2018 09:12:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D37132CC43; 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 BE8292CC70 for ; Thu, 20 Sep 2018 09:12:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387459AbeITOzC (ORCPT ); Thu, 20 Sep 2018 10:55:02 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:54688 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387433AbeITOzB (ORCPT ); Thu, 20 Sep 2018 10:55:01 -0400 Received: by mail-wm1-f68.google.com with SMTP id c14-v6so9123356wmb.4 for ; Thu, 20 Sep 2018 02:12:31 -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=11IHtODnFdTrf4yR6ESPEqelh8x6D7lbJdyCF6NPMG4=; b=ioh7spFcJ9oL+dQoS/puAFmjqs0E283sOoqvFUTrlq00kHW37LFW8cIcIx2g/BXa3K O97AAbKRRiMp4X+bb0j7AEFuL+Ezywe7pjLqi5WBDjvA9ZA6D8RfuTl7OCkJ/l56ndzI pnH5gpoK4r2ehyu/rNMAZPKkIGhgPRy7BzP5aJShUGX3DAPK2aBZ7q58E0e+0+nUOk2h 7EgYGRDvkON5JXV65Sb779tDrVPMme1n3nwiTWNV2YHn3EB+AMph62A9HODzwhki6pnK IkoBHzo+FQm8bwiDr/mcGojKOEnEX1YIR8+kPknqPFJIvNCDvAIdbmvF7S5AlBCFcnL8 q+8w== X-Gm-Message-State: APzg51BAtF8mAuT/uRQD+SQwGatuqkpDomjT8qcWev/CUdvFX0XPSgY7 Gp8MIu8TocY8zjA297pL7YLSeQ== X-Google-Smtp-Source: ANB0VdawNUfx5C5MdSKS3qhsT85zF1jGOZpqxL/aJONDjIRUFHhHZw7X0PYxxmQIkUV0dR4k2oFpxQ== X-Received: by 2002:a1c:2787:: with SMTP id n129-v6mr1488786wmn.101.1537434750025; Thu, 20 Sep 2018 02:12:30 -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.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:28 -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 05/20] mt76: move mt76x2_eeprom_get in mt76x02_eeprom.h Date: Thu, 20 Sep 2018 11:11:52 +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 mt76x2_eeprom_get utility routine in mt76x02_eeprom.h since it will be used to parse mt76x0 eeprom in order to unify eeprom support between mt76x2 and mt76x0 drivers Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x02_eeprom.h | 10 +++ .../wireless/mediatek/mt76/mt76x2_eeprom.c | 87 +++++++++++-------- .../wireless/mediatek/mt76/mt76x2_eeprom.h | 17 +--- .../net/wireless/mediatek/mt76/mt76x2_init.c | 6 +- .../net/wireless/mediatek/mt76/mt76x2_mcu.c | 2 +- .../mediatek/mt76/mt76x2_mcu_common.c | 5 +- .../net/wireless/mediatek/mt76/mt76x2_phy.c | 2 +- .../net/wireless/mediatek/mt76/mt76x2u_mac.c | 6 +- .../net/wireless/mediatek/mt76/mt76x2u_phy.c | 2 +- 9 files changed, 77 insertions(+), 60 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h index 1575c2352d9b..85dd4f9b97a5 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h @@ -136,4 +136,14 @@ mt76x02_sign_extend(u32 val, unsigned int size) return sign ? val : -val; } +static inline int +mt76x02_eeprom_get(struct mt76_dev *dev, + enum mt76x02_eeprom_field field) +{ + if ((field & 1) || field >= __MT_EE_MAX) + return -1; + + return get_unaligned_le16(dev->eeprom.data + field); +} + #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 2db495d9f99f..aea8033f13ce 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c @@ -42,7 +42,7 @@ mt76x2_eeprom_get_macaddr(struct mt76x2_dev *dev) void mt76x2_eeprom_parse_hw_cap(struct mt76x2_dev *dev) { - u16 val = mt76x2_eeprom_get(dev, MT_EE_NIC_CONF_0); + u16 val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_0); switch (FIELD_GET(MT_EE_NIC_CONF_0_BOARD_TYPE, val)) { case BOARD_TYPE_5GHZ: @@ -319,17 +319,23 @@ mt76x2_get_5g_rx_gain(struct mt76x2_dev *dev, u8 channel) group = mt76x2_get_cal_channel_group(channel); switch (group) { case MT_CH_5G_JAPAN: - return mt76x2_eeprom_get(dev, MT_EE_RF_5G_GRP0_1_RX_HIGH_GAIN); + return mt76x02_eeprom_get(&dev->mt76, + MT_EE_RF_5G_GRP0_1_RX_HIGH_GAIN); case MT_CH_5G_UNII_1: - return mt76x2_eeprom_get(dev, MT_EE_RF_5G_GRP0_1_RX_HIGH_GAIN) >> 8; + return mt76x02_eeprom_get(&dev->mt76, + MT_EE_RF_5G_GRP0_1_RX_HIGH_GAIN) >> 8; case MT_CH_5G_UNII_2: - return mt76x2_eeprom_get(dev, MT_EE_RF_5G_GRP2_3_RX_HIGH_GAIN); + return mt76x02_eeprom_get(&dev->mt76, + MT_EE_RF_5G_GRP2_3_RX_HIGH_GAIN); case MT_CH_5G_UNII_2E_1: - return mt76x2_eeprom_get(dev, MT_EE_RF_5G_GRP2_3_RX_HIGH_GAIN) >> 8; + return mt76x02_eeprom_get(&dev->mt76, + MT_EE_RF_5G_GRP2_3_RX_HIGH_GAIN) >> 8; case MT_CH_5G_UNII_2E_2: - return mt76x2_eeprom_get(dev, MT_EE_RF_5G_GRP4_5_RX_HIGH_GAIN); + return mt76x02_eeprom_get(&dev->mt76, + MT_EE_RF_5G_GRP4_5_RX_HIGH_GAIN); default: - return mt76x2_eeprom_get(dev, MT_EE_RF_5G_GRP4_5_RX_HIGH_GAIN) >> 8; + return mt76x02_eeprom_get(&dev->mt76, + MT_EE_RF_5G_GRP4_5_RX_HIGH_GAIN) >> 8; } } @@ -342,30 +348,31 @@ void mt76x2_read_rx_gain(struct mt76x2_dev *dev) u16 val; if (chan->band == NL80211_BAND_2GHZ) - val = mt76x2_eeprom_get(dev, MT_EE_RF_2G_RX_HIGH_GAIN) >> 8; + val = mt76x02_eeprom_get(&dev->mt76, + MT_EE_RF_2G_RX_HIGH_GAIN) >> 8; else val = mt76x2_get_5g_rx_gain(dev, channel); mt76x2_set_rx_gain_group(dev, val); if (chan->band == NL80211_BAND_2GHZ) { - val = mt76x2_eeprom_get(dev, MT_EE_RSSI_OFFSET_2G_0); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_RSSI_OFFSET_2G_0); mt76x2_set_rssi_offset(dev, 0, val); mt76x2_set_rssi_offset(dev, 1, val >> 8); } else { - val = mt76x2_eeprom_get(dev, MT_EE_RSSI_OFFSET_5G_0); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_RSSI_OFFSET_5G_0); mt76x2_set_rssi_offset(dev, 0, val); mt76x2_set_rssi_offset(dev, 1, val >> 8); } - val = mt76x2_eeprom_get(dev, MT_EE_LNA_GAIN); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_LNA_GAIN); lna_2g = val & 0xff; lna_5g[0] = val >> 8; - val = mt76x2_eeprom_get(dev, MT_EE_RSSI_OFFSET_2G_1); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_RSSI_OFFSET_2G_1); lna_5g[1] = val >> 8; - val = mt76x2_eeprom_get(dev, MT_EE_RSSI_OFFSET_5G_1); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_RSSI_OFFSET_5G_1); lna_5g[2] = val >> 8; if (!mt76x02_field_valid(lna_5g[1])) @@ -379,7 +386,7 @@ void mt76x2_read_rx_gain(struct mt76x2_dev *dev) dev->cal.rx.mcu_gain |= (lna_5g[1] & 0xff) << 16; dev->cal.rx.mcu_gain |= (lna_5g[2] & 0xff) << 24; - val = mt76x2_eeprom_get(dev, MT_EE_NIC_CONF_1); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_1); if (val & MT_EE_NIC_CONF_1_LNA_EXT_2G) lna_2g = 0; if (val & MT_EE_NIC_CONF_1_LNA_EXT_5G) @@ -420,50 +427,54 @@ void mt76x2_get_rate_power(struct mt76x2_dev *dev, struct mt76_rate_power *t, memset(t, 0, sizeof(*t)); - val = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_CCK); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_CCK); t->cck[0] = t->cck[1] = mt76x2_rate_power_val(val); t->cck[2] = t->cck[3] = mt76x2_rate_power_val(val >> 8); if (is_5ghz) - val = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_OFDM_5G_6M); + val = mt76x02_eeprom_get(&dev->mt76, + MT_EE_TX_POWER_OFDM_5G_6M); else - val = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_OFDM_2G_6M); + val = mt76x02_eeprom_get(&dev->mt76, + MT_EE_TX_POWER_OFDM_2G_6M); t->ofdm[0] = t->ofdm[1] = mt76x2_rate_power_val(val); t->ofdm[2] = t->ofdm[3] = mt76x2_rate_power_val(val >> 8); if (is_5ghz) - val = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_OFDM_5G_24M); + val = mt76x02_eeprom_get(&dev->mt76, + MT_EE_TX_POWER_OFDM_5G_24M); else - val = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_OFDM_2G_24M); + val = mt76x02_eeprom_get(&dev->mt76, + MT_EE_TX_POWER_OFDM_2G_24M); t->ofdm[4] = t->ofdm[5] = mt76x2_rate_power_val(val); t->ofdm[6] = t->ofdm[7] = mt76x2_rate_power_val(val >> 8); - val = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_HT_MCS0); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_HT_MCS0); t->ht[0] = t->ht[1] = mt76x2_rate_power_val(val); t->ht[2] = t->ht[3] = mt76x2_rate_power_val(val >> 8); - val = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_HT_MCS4); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_HT_MCS4); t->ht[4] = t->ht[5] = mt76x2_rate_power_val(val); t->ht[6] = t->ht[7] = mt76x2_rate_power_val(val >> 8); memcpy(t->stbc, t->ht, sizeof(t->stbc)); - val = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_HT_MCS8); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_HT_MCS8); t->ht[8] = t->ht[9] = mt76x2_rate_power_val(val); t->ht[10] = t->ht[11] = mt76x2_rate_power_val(val >> 8); - val = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_HT_MCS12); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_HT_MCS12); t->ht[12] = t->ht[13] = mt76x2_rate_power_val(val); t->ht[14] = t->ht[15] = mt76x2_rate_power_val(val >> 8); - val = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_VHT_MCS0); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_VHT_MCS0); t->vht[0] = t->vht[1] = mt76x2_rate_power_val(val); t->vht[2] = t->vht[3] = mt76x2_rate_power_val(val >> 8); - val = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_VHT_MCS4); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_VHT_MCS4); t->vht[4] = t->vht[5] = mt76x2_rate_power_val(val); t->vht[6] = t->vht[7] = mt76x2_rate_power_val(val >> 8); - val = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_VHT_MCS8); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_VHT_MCS8); if (!is_5ghz) val >>= 8; t->vht[8] = t->vht[9] = mt76x2_rate_power_val(val >> 8); @@ -505,7 +516,7 @@ mt76x2_get_power_info_2g(struct mt76x2_dev *dev, struct mt76x2_tx_power_info *t, t->chain[chain].target_power = data[2]; t->chain[chain].delta = mt76x2_sign_extend_optional(data[delta_idx], 7); - val = mt76x2_eeprom_get(dev, MT_EE_RF_2G_TSSI_OFF_TXPOWER); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_RF_2G_TSSI_OFF_TXPOWER); t->target_power = val >> 8; } @@ -554,7 +565,7 @@ mt76x2_get_power_info_5g(struct mt76x2_dev *dev, struct mt76x2_tx_power_info *t, t->chain[chain].target_power = data[2]; t->chain[chain].delta = mt76x2_sign_extend_optional(data[delta_idx], 7); - val = mt76x2_eeprom_get(dev, MT_EE_RF_2G_RX_HIGH_GAIN); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_RF_2G_RX_HIGH_GAIN); t->target_power = val & 0xff; } @@ -566,8 +577,8 @@ void mt76x2_get_power_info(struct mt76x2_dev *dev, memset(t, 0, sizeof(*t)); - bw40 = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_DELTA_BW40); - bw80 = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_DELTA_BW80); + bw40 = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_DELTA_BW40); + bw80 = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_DELTA_BW80); if (chan->band == NL80211_BAND_5GHZ) { bw40 >>= 8; @@ -605,14 +616,18 @@ int mt76x2_get_temp_comp(struct mt76x2_dev *dev, struct mt76x2_temp_comp *t) if (!mt76x2_ext_pa_enabled(dev, band)) return -EINVAL; - val = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_EXT_PA_5G) >> 8; + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_EXT_PA_5G) >> 8; t->temp_25_ref = val & 0x7f; if (band == NL80211_BAND_5GHZ) { - slope = mt76x2_eeprom_get(dev, MT_EE_RF_TEMP_COMP_SLOPE_5G); - bounds = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_EXT_PA_5G); + slope = mt76x02_eeprom_get(&dev->mt76, + MT_EE_RF_TEMP_COMP_SLOPE_5G); + bounds = mt76x02_eeprom_get(&dev->mt76, + MT_EE_TX_POWER_EXT_PA_5G); } else { - slope = mt76x2_eeprom_get(dev, MT_EE_RF_TEMP_COMP_SLOPE_2G); - bounds = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_DELTA_BW80) >> 8; + slope = mt76x02_eeprom_get(&dev->mt76, + MT_EE_RF_TEMP_COMP_SLOPE_2G); + bounds = mt76x02_eeprom_get(&dev->mt76, + MT_EE_TX_POWER_DELTA_BW80) >> 8; } t->high_slope = slope & 0xff; @@ -626,7 +641,7 @@ EXPORT_SYMBOL_GPL(mt76x2_get_temp_comp); bool mt76x2_ext_pa_enabled(struct mt76x2_dev *dev, enum nl80211_band band) { - u16 conf0 = mt76x2_eeprom_get(dev, MT_EE_NIC_CONF_0); + u16 conf0 = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_0); if (band == NL80211_BAND_5GHZ) return !(conf0 & MT_EE_NIC_CONF_0_PA_INT_5G); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h index 64b91fb57e3b..6064ef103d2c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h @@ -56,15 +56,6 @@ struct mt76x2_temp_comp { unsigned int low_slope; /* J / dB */ }; -static inline int -mt76x2_eeprom_get(struct mt76x2_dev *dev, enum mt76x02_eeprom_field field) -{ - if ((field & 1) || field >= __MT_EE_MAX) - return -1; - - return get_unaligned_le16(dev->mt76.eeprom.data + field); -} - void mt76x2_get_rate_power(struct mt76x2_dev *dev, struct mt76_rate_power *t, struct ieee80211_channel *chan); int mt76x2_get_max_rate_power(struct mt76_rate_power *r); @@ -81,11 +72,11 @@ mt76x2_temp_tx_alc_enabled(struct mt76x2_dev *dev) { u16 val; - val = mt76x2_eeprom_get(dev, MT_EE_TX_POWER_EXT_PA_5G); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_EXT_PA_5G); if (!(val & BIT(15))) return false; - return mt76x2_eeprom_get(dev, MT_EE_NIC_CONF_1) & + return mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_1) & MT_EE_NIC_CONF_1_TEMP_TX_ALC; } @@ -93,14 +84,14 @@ static inline bool mt76x2_tssi_enabled(struct mt76x2_dev *dev) { return !mt76x2_temp_tx_alc_enabled(dev) && - (mt76x2_eeprom_get(dev, MT_EE_NIC_CONF_1) & + (mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_1) & MT_EE_NIC_CONF_1_TX_ALC_EN); } static inline bool mt76x2_has_ext_lna(struct mt76x2_dev *dev) { - u32 val = mt76x2_eeprom_get(dev, MT_EE_NIC_CONF_1); + u32 val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_1); if (dev->mt76.chandef.chan->band == NL80211_BAND_2GHZ) return val & MT_EE_NIC_CONF_1_LNA_EXT_2G; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_init.c b/drivers/net/wireless/mediatek/mt76/mt76x2_init.c index 33f7fabf45c0..72005faee00e 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_init.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_init.c @@ -44,7 +44,7 @@ mt76x2_fixup_xtal(struct mt76x2_dev *dev) u16 eep_val; s8 offset = 0; - eep_val = mt76x2_eeprom_get(dev, MT_EE_XTAL_TRIM_2); + eep_val = mt76x02_eeprom_get(&dev->mt76, MT_EE_XTAL_TRIM_2); offset = eep_val & 0x7f; if ((eep_val & 0xff) == 0xff) @@ -54,7 +54,7 @@ mt76x2_fixup_xtal(struct mt76x2_dev *dev) eep_val >>= 8; if (eep_val == 0x00 || eep_val == 0xff) { - eep_val = mt76x2_eeprom_get(dev, MT_EE_XTAL_TRIM_1); + eep_val = mt76x02_eeprom_get(&dev->mt76, MT_EE_XTAL_TRIM_1); eep_val &= 0xff; if (eep_val == 0x00 || eep_val == 0xff) @@ -65,7 +65,7 @@ mt76x2_fixup_xtal(struct mt76x2_dev *dev) mt76_rmw_field(dev, MT_XO_CTRL5, MT_XO_CTRL5_C2_VAL, eep_val + offset); mt76_set(dev, MT_XO_CTRL6, MT_XO_CTRL6_C2_CTRL); - eep_val = mt76x2_eeprom_get(dev, MT_EE_NIC_CONF_2); + eep_val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_2); switch (FIELD_GET(MT_EE_NIC_CONF_2_XTAL_OPTION, eep_val)) { case 0: mt76_wr(dev, MT_XO_CTRL7, 0x5c1fee80); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_mcu.c b/drivers/net/wireless/mediatek/mt76/mt76x2_mcu.c index f92bebfa21fd..2b25414ed16b 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_mcu.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_mcu.c @@ -141,7 +141,7 @@ mt76pci_load_firmware(struct mt76x2_dev *dev) mt76_wr(dev, MT_MCU_PCIE_REMAP_BASE4, 0); - val = mt76x2_eeprom_get(dev, MT_EE_NIC_CONF_2); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_2); if (FIELD_GET(MT_EE_NIC_CONF_2_XTAL_OPTION, val) == 1) mt76_set(dev, MT_MCU_COM_REG0, BIT(30)); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_mcu_common.c b/drivers/net/wireless/mediatek/mt76/mt76x2_mcu_common.c index 72f6bfb7a258..a3669c00ddd5 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_mcu_common.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_mcu_common.c @@ -60,6 +60,7 @@ EXPORT_SYMBOL_GPL(mt76x2_mcu_set_channel); int mt76x2_mcu_load_cr(struct mt76x2_dev *dev, u8 type, u8 temp_level, u8 channel) { + struct mt76_dev *mdev = &dev->mt76; struct sk_buff *skb; struct { u8 cr_mode; @@ -76,8 +77,8 @@ int mt76x2_mcu_load_cr(struct mt76x2_dev *dev, u8 type, u8 temp_level, u32 val; val = BIT(31); - val |= (mt76x2_eeprom_get(dev, MT_EE_NIC_CONF_0) >> 8) & 0x00ff; - val |= (mt76x2_eeprom_get(dev, MT_EE_NIC_CONF_1) << 8) & 0xff00; + val |= (mt76x02_eeprom_get(mdev, MT_EE_NIC_CONF_0) >> 8) & 0x00ff; + val |= (mt76x02_eeprom_get(mdev, MT_EE_NIC_CONF_1) << 8) & 0xff00; msg.cfg = cpu_to_le32(val); /* first set the channel without the extension channel info */ diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x2_phy.c index 920bb7c89af9..4477a4e184e9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_phy.c @@ -360,7 +360,7 @@ int mt76x2_phy_set_channel(struct mt76x2_dev *dev, mt76_set(dev, MT_BBP(RXO, 13), BIT(10)); if (!dev->cal.init_cal_done) { - u8 val = mt76x2_eeprom_get(dev, MT_EE_BT_RCAL_RESULT); + u8 val = mt76x02_eeprom_get(&dev->mt76, MT_EE_BT_RCAL_RESULT); if (val != 0xff) mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_R, 0, true); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2u_mac.c b/drivers/net/wireless/mediatek/mt76/mt76x2u_mac.c index 9604c6a809be..b59336110746 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2u_mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2u_mac.c @@ -32,7 +32,7 @@ static void mt76x2u_mac_fixup_xtal(struct mt76x2_dev *dev) s8 offset = 0; u16 eep_val; - eep_val = mt76x2_eeprom_get(dev, MT_EE_XTAL_TRIM_2); + eep_val = mt76x02_eeprom_get(&dev->mt76, MT_EE_XTAL_TRIM_2); offset = eep_val & 0x7f; if ((eep_val & 0xff) == 0xff) @@ -42,7 +42,7 @@ static void mt76x2u_mac_fixup_xtal(struct mt76x2_dev *dev) eep_val >>= 8; if (eep_val == 0x00 || eep_val == 0xff) { - eep_val = mt76x2_eeprom_get(dev, MT_EE_XTAL_TRIM_1); + eep_val = mt76x02_eeprom_get(&dev->mt76, MT_EE_XTAL_TRIM_1); eep_val &= 0xff; if (eep_val == 0x00 || eep_val == 0xff) @@ -67,7 +67,7 @@ static void mt76x2u_mac_fixup_xtal(struct mt76x2_dev *dev) /* init fce */ mt76_clear(dev, MT_FCE_L2_STUFF, MT_FCE_L2_STUFF_WR_MPDU_LEN_EN); - eep_val = mt76x2_eeprom_get(dev, MT_EE_NIC_CONF_2); + eep_val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_2); switch (FIELD_GET(MT_EE_NIC_CONF_2_XTAL_OPTION, eep_val)) { case 0: mt76_wr(dev, MT_XO_CTRL7, 0x5c1fee80); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2u_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x2u_phy.c index 97f40fef5559..9842ed04d764 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2u_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2u_phy.c @@ -209,7 +209,7 @@ int mt76x2u_phy_set_channel(struct mt76x2_dev *dev, mt76_set(dev, MT_BBP(RXO, 13), BIT(10)); if (!dev->cal.init_cal_done) { - u8 val = mt76x2_eeprom_get(dev, MT_EE_BT_RCAL_RESULT); + u8 val = mt76x02_eeprom_get(&dev->mt76, MT_EE_BT_RCAL_RESULT); if (val != 0xff) mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_R, From patchwork Thu Sep 20 09:11:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607173 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 750E66CB 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 6512E2CC43 for ; Thu, 20 Sep 2018 09:12:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 599E52CC7A; 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 9E3CC2CC43 for ; Thu, 20 Sep 2018 09:12:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387453AbeITOzB (ORCPT ); Thu, 20 Sep 2018 10:55:01 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:40261 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387441AbeITOzB (ORCPT ); Thu, 20 Sep 2018 10:55:01 -0400 Received: by mail-wm1-f68.google.com with SMTP id 207-v6so9998776wme.5 for ; Thu, 20 Sep 2018 02:12:31 -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=6K0R/oEQr3kzeFHqnDvsvaeF64pOJY53JAagoAvOmac=; b=I8fQMzFDDqfAiMVdBRRBmpREcg5EV4Qa+BaSYGdTnmFQbd7l7vj9Unpc1CDWtHjsq/ ZjcqBVVRlEYqPBvQY6XchMDDxWhp9e407XVYQz/vhu3c44XM7Uo+XGcLM54FS4JJ4c7P Hn404KfnbyB2x6nD+88bDkx8lew3Ih8Y8L4ZFqHA/iiWX6G2gfaZ0T3ZpPgjNaOFhuzG JxuEyALQWlk8Tc0xDl9ZgNVjs54lFB7LgfjTHiBB++IYL0V71C8PJ4hagzVfLaW+mvoH x0fzIuWiAdSMhmM2dww8QgVrDdaLkb4aHLwBD3kwsEZgpd3zi1gETuUbNtzP1opoI8Mn DaGg== X-Gm-Message-State: APzg51CU36AHTBXGdooY3lBB9ZXwH8IyrI+9viZeublveD+Ww9dvwxbS pgiLKuOWdHRQHebEQJafrKyBcg== X-Google-Smtp-Source: ANB0VdbohNGeMvJEaV5Ys1yx+5/tm8YyvbB7u2RcasKKyEps5hJGrkITXXyXF+pO/GFBy+bB4OjsHA== X-Received: by 2002:a1c:ba84:: with SMTP id k126-v6mr1574453wmf.96.1537434750972; Thu, 20 Sep 2018 02:12:30 -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.30 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:30 -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 06/20] mt76: move mt76x02_mac_setaddr in mt76x02-lib module Date: Thu, 20 Sep 2018 11:11:53 +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 mt76x02_mac_setaddr utility routine in mt76x02-lib module and remove duplicated code. This is a preliminary patch to unify eeprom code between mt76x2 and mt76x0 driver Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/eeprom.c | 24 +------------------ .../net/wireless/mediatek/mt76/mt76x02_mac.c | 18 ++++++++++++++ .../net/wireless/mediatek/mt76/mt76x02_mac.h | 1 + drivers/net/wireless/mediatek/mt76/mt76x2u.h | 1 - .../net/wireless/mediatek/mt76/mt76x2u_init.c | 3 ++- .../net/wireless/mediatek/mt76/mt76x2u_mac.c | 18 -------------- .../net/wireless/mediatek/mt76/mt76x2u_main.c | 2 +- 7 files changed, 23 insertions(+), 44 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index c935d98f5710..a93da6c5ce59 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -131,28 +131,6 @@ mt76x0_set_chip_cap(struct mt76x0_dev *dev, u8 *eeprom) dev_dbg(dev->mt76.dev, "PA Type %d\n", dev->ee->pa_type); } -static int -mt76x0_set_macaddr(struct mt76x0_dev *dev, const u8 *eeprom) -{ - const void *src = eeprom + MT_EE_MAC_ADDR; - u8 *dst = dev->mt76.macaddr; - - ether_addr_copy(dev->mt76.macaddr, src); - - if (!is_valid_ether_addr(dst)) { - eth_random_addr(dst); - dev_info(dev->mt76.dev, - "Invalid MAC address, using random address %pM\n", - dst); - } - - mt76_wr(dev, MT_MAC_ADDR_DW0, get_unaligned_le32(dst)); - mt76_wr(dev, MT_MAC_ADDR_DW1, get_unaligned_le16(dst + 4) | - FIELD_PREP(MT_MAC_ADDR_DW1_U2ME_MASK, 0xff)); - - return 0; -} - static void mt76x0_set_temp_offset(struct mt76x0_dev *dev, u8 *eeprom) { @@ -409,7 +387,7 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev) dev_info(dev->mt76.dev, "EEPROM ver:%02hhx fae:%02hhx\n", eeprom[MT_EE_VERSION + 1], eeprom[MT_EE_VERSION]); - mt76x0_set_macaddr(dev, eeprom); + mt76x02_mac_setaddr(&dev->mt76, eeprom + MT_EE_MAC_ADDR); mt76x0_set_chip_cap(dev, eeprom); mt76x0_set_country_reg(dev, eeprom); mt76x0_set_rf_freq_off(dev, eeprom); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c index 0b12299c7a41..df4366a702c9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.c @@ -502,3 +502,21 @@ mt76x02_mac_process_rate(struct mt76_rx_status *status, u16 rate) return 0; } EXPORT_SYMBOL_GPL(mt76x02_mac_process_rate); + +void mt76x02_mac_setaddr(struct mt76_dev *dev, u8 *addr) +{ + ether_addr_copy(dev->macaddr, addr); + + if (!is_valid_ether_addr(dev->macaddr)) { + eth_random_addr(dev->macaddr); + dev_info(dev->dev, + "Invalid MAC address, using random address %pM\n", + dev->macaddr); + } + + __mt76_wr(dev, MT_MAC_ADDR_DW0, get_unaligned_le32(dev->macaddr)); + __mt76_wr(dev, MT_MAC_ADDR_DW1, + get_unaligned_le16(dev->macaddr + 4) | + FIELD_PREP(MT_MAC_ADDR_DW1_U2ME_MASK, 0xff)); +} +EXPORT_SYMBOL_GPL(mt76x02_mac_setaddr); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h index 1a5da35702e6..f12ecbe15d8c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_mac.h @@ -202,4 +202,5 @@ void mt76x02_send_tx_status(struct mt76_dev *dev, struct mt76x02_tx_status *stat, u8 *update); int mt76x02_mac_process_rate(struct mt76_rx_status *status, u16 rate); +void mt76x02_mac_setaddr(struct mt76_dev *dev, u8 *addr); #endif diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2u.h b/drivers/net/wireless/mediatek/mt76/mt76x2u.h index a0ff6472de1f..74fde9f107e1 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2u.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x2u.h @@ -36,7 +36,6 @@ int mt76x2u_init_hardware(struct mt76x2_dev *dev); void mt76x2u_cleanup(struct mt76x2_dev *dev); void mt76x2u_stop_hw(struct mt76x2_dev *dev); -void mt76x2u_mac_setaddr(struct mt76x2_dev *dev, u8 *addr); int mt76x2u_mac_reset(struct mt76x2_dev *dev); void mt76x2u_mac_resume(struct mt76x2_dev *dev); int mt76x2u_mac_start(struct mt76x2_dev *dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2u_init.c b/drivers/net/wireless/mediatek/mt76/mt76x2u_init.c index e41880c43fa7..89cfacfb276c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2u_init.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2u_init.c @@ -212,7 +212,8 @@ int mt76x2u_init_hardware(struct mt76x2_dev *dev) if (err < 0) return err; - mt76x2u_mac_setaddr(dev, dev->mt76.eeprom.data + MT_EE_MAC_ADDR); + mt76x02_mac_setaddr(&dev->mt76, + dev->mt76.eeprom.data + MT_EE_MAC_ADDR); dev->mt76.rxfilter = mt76_rr(dev, MT_RX_FILTR_CFG); mt76x2u_init_beacon_offsets(dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2u_mac.c b/drivers/net/wireless/mediatek/mt76/mt76x2u_mac.c index b59336110746..0f5d781b13dc 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2u_mac.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2u_mac.c @@ -220,21 +220,3 @@ void mt76x2u_mac_resume(struct mt76x2_dev *dev) mt76_set(dev, MT_TXOP_CTRL_CFG, BIT(20)); mt76_set(dev, MT_TXOP_HLDR_ET, BIT(1)); } - -void mt76x2u_mac_setaddr(struct mt76x2_dev *dev, u8 *addr) -{ - ether_addr_copy(dev->mt76.macaddr, addr); - - if (!is_valid_ether_addr(dev->mt76.macaddr)) { - eth_random_addr(dev->mt76.macaddr); - dev_info(dev->mt76.dev, - "Invalid MAC address, using random address %pM\n", - dev->mt76.macaddr); - } - - mt76_wr(dev, MT_MAC_ADDR_DW0, get_unaligned_le32(dev->mt76.macaddr)); - mt76_wr(dev, MT_MAC_ADDR_DW1, - get_unaligned_le16(dev->mt76.macaddr + 4) | - FIELD_PREP(MT_MAC_ADDR_DW1_U2ME_MASK, 0xff)); -} - diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2u_main.c b/drivers/net/wireless/mediatek/mt76/mt76x2u_main.c index c6855549c312..620aeb3eb79f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2u_main.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2u_main.c @@ -51,7 +51,7 @@ static int mt76x2u_add_interface(struct ieee80211_hw *hw, struct mt76x2_dev *dev = hw->priv; if (!ether_addr_equal(dev->mt76.macaddr, vif->addr)) - mt76x2u_mac_setaddr(dev, vif->addr); + mt76x02_mac_setaddr(&dev->mt76, vif->addr); mt76x02_vif_init(&dev->mt76, vif, 0); return 0; From patchwork Thu Sep 20 09:11:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607175 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 C140C1508 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 AE4B42CC43 for ; Thu, 20 Sep 2018 09:12:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2A5A2CC7A; 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 E91592CC8E for ; Thu, 20 Sep 2018 09:12:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387467AbeITOzC (ORCPT ); Thu, 20 Sep 2018 10:55:02 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:40265 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387445AbeITOzC (ORCPT ); Thu, 20 Sep 2018 10:55:02 -0400 Received: by mail-wm1-f68.google.com with SMTP id 207-v6so9998867wme.5 for ; Thu, 20 Sep 2018 02:12:33 -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=XHBp+zVhdMDyZFqnEKl3zraNUTrEgytIAcanL48FCDo=; b=D+tZaXJU6FBXMX7J7x6inOQ7JRw65ZSKpqSY4jQafCfbQeTZOeIDR+X/F7rcNSReZg mCEBwBtp/3Vtm504YdtW744elefYv4jclI1ig/QYqtlq9MeAEdq/Gj2G3Eu5s3QUN6m9 MbDmeekcKk7Wg0JfYKPEKuzx5jEiss9WqGdXbl60qmFdCQXTxeqTIx2iv71b4NCa3na6 jBYL6BlPKKiiHF/Ck4qrT1vHe850yXTpkKE+UV4FsWEssRlxe23bDGAQ2LObvf3TLHla GAOflxZNEOH+rco56+10DRjX1eHThumJlE4XJMLh4ZMq9dByNTTbBuOxnkJU++d0p02B f/Yw== X-Gm-Message-State: APzg51CnItBqFFDemZInmWOtUndvd5ePHZfqBpVnh37TbqY33gGeGAWQ fxyJiqe6060tyRJbv477wKdWqw== X-Google-Smtp-Source: ANB0Vda7jlp4iJyKLji+QpW3s61z24iuVuhLuyTgMy9qiqhOQpEBhL6m5gAUUq2f/x43K1eY9caIhw== X-Received: by 2002:a1c:760a:: with SMTP id r10-v6mr1655523wmc.86.1537434751990; Thu, 20 Sep 2018 02:12:31 -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.31 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:31 -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 07/20] mt76: move mt76x2_get_efuse_data in mt76x02-lib module Date: Thu, 20 Sep 2018 11:11:54 +0200 Message-Id: <5403d92a53303ed70c8257342a02e6d4d76804d5.1537433365.git.lorenzo.bianconi@redhat.com> 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 mt76x2_efuse_read and mt76x2_get_efuse_data in mt76x02_eeprom.c in order to be reused in mt76x0 driver for eeprom parsing Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/Makefile | 3 +- .../wireless/mediatek/mt76/mt76x0/eeprom.c | 59 +++------------ .../wireless/mediatek/mt76/mt76x0/eeprom.h | 5 -- .../wireless/mediatek/mt76/mt76x02_eeprom.c | 72 +++++++++++++++++++ .../wireless/mediatek/mt76/mt76x02_eeprom.h | 8 +++ .../wireless/mediatek/mt76/mt76x2_eeprom.c | 49 +------------ 6 files changed, 95 insertions(+), 101 deletions(-) create mode 100644 drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c diff --git a/drivers/net/wireless/mediatek/mt76/Makefile b/drivers/net/wireless/mediatek/mt76/Makefile index 4d25b5c3b70b..dbe0ec020391 100644 --- a/drivers/net/wireless/mediatek/mt76/Makefile +++ b/drivers/net/wireless/mediatek/mt76/Makefile @@ -15,7 +15,8 @@ mt76-usb-y := usb.o usb_trace.o usb_mcu.o CFLAGS_trace.o := -I$(src) CFLAGS_usb_trace.o := -I$(src) -mt76x02-lib-y := mt76x02_util.o mt76x02_mac.o mt76x02_mcu.o +mt76x02-lib-y := mt76x02_util.o mt76x02_mac.o mt76x02_mcu.o \ + mt76x02_eeprom.o mt76x02-usb-y := mt76x02_usb_mcu.o mt76x02_usb_core.o diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index a93da6c5ce59..43239a1cb1e5 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -21,41 +21,6 @@ #include "mt76x0.h" #include "eeprom.h" -static int -mt76x0_efuse_read(struct mt76x0_dev *dev, u16 addr, u8 *data, - enum mt76x0_eeprom_access_modes mode) -{ - u32 val; - int i; - - val = mt76_rr(dev, MT_EFUSE_CTRL); - val &= ~(MT_EFUSE_CTRL_AIN | - MT_EFUSE_CTRL_MODE); - val |= FIELD_PREP(MT_EFUSE_CTRL_AIN, addr & ~0xf) | - FIELD_PREP(MT_EFUSE_CTRL_MODE, mode) | - MT_EFUSE_CTRL_KICK; - mt76_wr(dev, MT_EFUSE_CTRL, val); - - if (!mt76_poll(dev, MT_EFUSE_CTRL, MT_EFUSE_CTRL_KICK, 0, 1000)) - return -ETIMEDOUT; - - val = mt76_rr(dev, MT_EFUSE_CTRL); - if ((val & MT_EFUSE_CTRL_AOUT) == MT_EFUSE_CTRL_AOUT) { - /* Parts of eeprom not in the usage map (0x80-0xc0,0xf0) - * will not return valid data but it's ok. - */ - memset(data, 0xff, 16); - return 0; - } - - for (i = 0; i < 4; i++) { - val = mt76_rr(dev, MT_EFUSE_DATA(i)); - put_unaligned_le32(val, data + 4 * i); - } - - return 0; -} - #define MT_MAP_READS DIV_ROUND_UP(MT_EFUSE_USAGE_MAP_SIZE, 16) static int mt76x0_efuse_physical_size_check(struct mt76x0_dev *dev) @@ -64,12 +29,10 @@ mt76x0_efuse_physical_size_check(struct mt76x0_dev *dev) int ret, i; u32 start = 0, end = 0, cnt_free; - for (i = 0; i < MT_MAP_READS; i++) { - ret = mt76x0_efuse_read(dev, MT_EE_USAGE_MAP_START + i * 16, - data + i * 16, MT_EE_PHYSICAL_READ); - if (ret) - return ret; - } + ret = mt76x02_get_efuse_data(&dev->mt76, MT_EE_USAGE_MAP_START, + data, sizeof(data), MT_EE_PHYSICAL_READ); + if (ret) + return ret; for (i = 0; i < MT_EFUSE_USAGE_MAP_SIZE; i++) if (!data[i]) { @@ -80,7 +43,8 @@ mt76x0_efuse_physical_size_check(struct mt76x0_dev *dev) cnt_free = end - start + 1; if (MT_EFUSE_USAGE_MAP_SIZE - cnt_free < 5) { - dev_err(dev->mt76.dev, "Error: your device needs default EEPROM file and this driver doesn't support it!\n"); + dev_err(dev->mt76.dev, + "driver does not support default EEPROM\n"); return -EINVAL; } @@ -360,7 +324,7 @@ int mt76x0_eeprom_init(struct mt76x0_dev *dev) { u8 *eeprom; - int i, ret; + int ret; ret = mt76x0_efuse_physical_size_check(dev); if (ret) @@ -374,11 +338,10 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev) if (!eeprom) return -ENOMEM; - for (i = 0; i + 16 <= MT76X0_EEPROM_SIZE; i += 16) { - ret = mt76x0_efuse_read(dev, i, eeprom + i, MT_EE_READ); - if (ret) - goto out; - } + ret = mt76x02_get_efuse_data(&dev->mt76, 0, eeprom, + MT76X0_EEPROM_SIZE, MT_EE_READ); + if (ret) + goto out; if (eeprom[MT_EE_VERSION + 1] > MT76X0U_EE_MAX_VER) dev_warn(dev->mt76.dev, diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h index 1da90f056442..1051e3216614 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h @@ -23,11 +23,6 @@ struct mt76x0_dev; #define MT76X0U_EE_MAX_VER 0x0c #define MT76X0_EEPROM_SIZE 512 -enum mt76x0_eeprom_access_modes { - MT_EE_READ = 0, - MT_EE_PHYSICAL_READ = 1, -}; - struct reg_channel_bounds { u8 start; u8 num; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c new file mode 100644 index 000000000000..21fe7eb0652d --- /dev/null +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2016 Felix Fietkau + * Copyright (C) 2018 Lorenzo Bianconi + * + * Permission to use, copy, modify, and/or distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include + +#include "mt76.h" +#include "mt76x02_eeprom.h" +#include "mt76x02_regs.h" + +static int +mt76x02_efuse_read(struct mt76_dev *dev, u16 addr, u8 *data, + enum mt76x02_eeprom_modes mode) +{ + u32 val; + int i; + + val = __mt76_rr(dev, MT_EFUSE_CTRL); + val &= ~(MT_EFUSE_CTRL_AIN | + MT_EFUSE_CTRL_MODE); + val |= FIELD_PREP(MT_EFUSE_CTRL_AIN, addr & ~0xf); + val |= FIELD_PREP(MT_EFUSE_CTRL_MODE, mode); + val |= MT_EFUSE_CTRL_KICK; + __mt76_wr(dev, MT_EFUSE_CTRL, val); + + if (!__mt76_poll_msec(dev, MT_EFUSE_CTRL, MT_EFUSE_CTRL_KICK, + 0, 1000)) + return -ETIMEDOUT; + + udelay(2); + + val = __mt76_rr(dev, MT_EFUSE_CTRL); + if ((val & MT_EFUSE_CTRL_AOUT) == MT_EFUSE_CTRL_AOUT) { + memset(data, 0xff, 16); + return 0; + } + + for (i = 0; i < 4; i++) { + val = __mt76_rr(dev, MT_EFUSE_DATA(i)); + put_unaligned_le32(val, data + 4 * i); + } + + return 0; +} + +int mt76x02_get_efuse_data(struct mt76_dev *dev, u16 base, void *buf, + int len, enum mt76x02_eeprom_modes mode) +{ + int ret, i; + + for (i = 0; i + 16 <= len; i += 16) { + ret = mt76x02_efuse_read(dev, base + i, buf + i, mode); + if (ret) + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(mt76x02_get_efuse_data); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h index 85dd4f9b97a5..852ea9b51e97 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h @@ -121,6 +121,11 @@ enum mt76x02_eeprom_field { #define MT_EFUSE_USAGE_MAP_SIZE (MT_EE_USAGE_MAP_END - \ MT_EE_USAGE_MAP_START + 1) +enum mt76x02_eeprom_modes { + MT_EE_READ, + MT_EE_PHYSICAL_READ, +}; + static inline bool mt76x02_field_valid(u8 val) { return val != 0 && val != 0xff; @@ -146,4 +151,7 @@ mt76x02_eeprom_get(struct mt76_dev *dev, return get_unaligned_le16(dev->eeprom.data + field); } +int mt76x02_get_efuse_data(struct mt76_dev *dev, u16 base, void *buf, + int len, enum mt76x02_eeprom_modes mode); + #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 aea8033f13ce..333faa44d7cc 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c @@ -59,52 +59,6 @@ void mt76x2_eeprom_parse_hw_cap(struct mt76x2_dev *dev) } EXPORT_SYMBOL_GPL(mt76x2_eeprom_parse_hw_cap); -static int -mt76x2_efuse_read(struct mt76x2_dev *dev, u16 addr, u8 *data) -{ - u32 val; - int i; - - val = mt76_rr(dev, MT_EFUSE_CTRL); - val &= ~(MT_EFUSE_CTRL_AIN | - MT_EFUSE_CTRL_MODE); - val |= FIELD_PREP(MT_EFUSE_CTRL_AIN, addr & ~0xf); - val |= MT_EFUSE_CTRL_KICK; - mt76_wr(dev, MT_EFUSE_CTRL, val); - - if (!mt76_poll(dev, MT_EFUSE_CTRL, MT_EFUSE_CTRL_KICK, 0, 1000)) - return -ETIMEDOUT; - - udelay(2); - - val = mt76_rr(dev, MT_EFUSE_CTRL); - if ((val & MT_EFUSE_CTRL_AOUT) == MT_EFUSE_CTRL_AOUT) { - memset(data, 0xff, 16); - return 0; - } - - for (i = 0; i < 4; i++) { - val = mt76_rr(dev, MT_EFUSE_DATA(i)); - put_unaligned_le32(val, data + 4 * i); - } - - return 0; -} - -static int -mt76x2_get_efuse_data(struct mt76x2_dev *dev, void *buf, int len) -{ - int ret, i; - - for (i = 0; i + 16 <= len; i += 16) { - ret = mt76x2_efuse_read(dev, i, buf + i); - if (ret) - return ret; - } - - return 0; -} - static bool mt76x2_has_cal_free_data(struct mt76x2_dev *dev, u8 *efuse) { @@ -241,7 +195,8 @@ mt76x2_eeprom_load(struct mt76x2_dev *dev) efuse = dev->mt76.otp.data; - if (mt76x2_get_efuse_data(dev, efuse, MT7662_EEPROM_SIZE)) + if (mt76x02_get_efuse_data(&dev->mt76, 0, efuse, + MT7662_EEPROM_SIZE, MT_EE_READ)) goto out; if (found) { From patchwork Thu Sep 20 09:11:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607181 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 336356CB for ; Thu, 20 Sep 2018 09:12:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23A9E2CC13 for ; Thu, 20 Sep 2018 09:12:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1836D2CC43; Thu, 20 Sep 2018 09:12:38 +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 152102CC95 for ; Thu, 20 Sep 2018 09:12:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387469AbeITOzD (ORCPT ); Thu, 20 Sep 2018 10:55:03 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:38450 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387441AbeITOzD (ORCPT ); Thu, 20 Sep 2018 10:55:03 -0400 Received: by mail-wm1-f67.google.com with SMTP id t25-v6so10014432wmi.3 for ; Thu, 20 Sep 2018 02:12:34 -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=UYq30IwoExy+MxryJk6RepFaSHrJ+k1S9godW85/lws=; b=mi3cre+hzWBRQLcPEjpJi8XlExGqjsjvcCJ07rrXBYK/bOAXOpCkK3oX0YRSomTPbJ DrKGOQQRt6BniDvo9MCmkERkmVkxmBI9wPF9+X+22RVR9Gbt58Tl1OD2AoTcNeElryab RksjLizdmlKVuH1pEJv2Vs3Q2G1MnBkm+gVpQ6wlr1rit2T002gZBz8JkWUTWn1jBSXK txKn0reXKVOxV7qGOGRwoAgsum83/DkD52DqyQwwnByfqpOq3rNsTr4mFsH/xzrIzLlA nkgu1s7giKap+pvcc4RuKAsH+MAo2D6aQRb+Ez35d7+yjQYpAZ3efQxrhqD6kqQ3NXoh 9jhA== X-Gm-Message-State: APzg51B5U3r78ulovJCmKmYf3Cj20J2yaXLscNQmL8QJU3WWHdwVVM07 gienf8KBXrhr/u/Y+h2Daa0DFQ== X-Google-Smtp-Source: ANB0VdbLoMPhj4s1M9pc7Hk22L8aXcc2ALSg87uTu0me27pq6U9vHO+yG5Wq4v+VcrsILtHZ43EFbw== X-Received: by 2002:a1c:2bc3:: with SMTP id r186-v6mr1664529wmr.71.1537434752973; Thu, 20 Sep 2018 02:12:32 -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.32 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:32 -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 08/20] mt76: move mt76x2_ext_pa_enabled routine in mt76x02_eeprom.c Date: Thu, 20 Sep 2018 11:11:55 +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 mt76x2_ext_pa_enabled utility routine in mt76x02_eeprom.c and remove duplicated code. This is a preliminary patch to unify eeprom code between mt76x2 and mt76x0 driver Signed-off-by: Lorenzo Bianconi --- drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c | 6 +++++- drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c | 7 ++++--- drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h | 1 - drivers/net/wireless/mediatek/mt76/mt76x0/phy.c | 13 +++---------- drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c | 11 +++++++++++ drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h | 1 + drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c | 13 +------------ drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h | 1 - drivers/net/wireless/mediatek/mt76/mt76x2_phy.c | 2 +- .../net/wireless/mediatek/mt76/mt76x2_phy_common.c | 12 ++++++------ drivers/net/wireless/mediatek/mt76/mt76x2u_phy.c | 2 +- 11 files changed, 33 insertions(+), 36 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c index e7a77a886068..f9e305840176 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c @@ -99,6 +99,7 @@ static int mt76x0_eeprom_param_read(struct seq_file *file, void *data) { struct mt76x0_dev *dev = file->private; + u16 val; int i; seq_printf(file, "RF freq offset: %hhx\n", dev->ee->rf_freq_off); @@ -112,7 +113,10 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data) seq_printf(file, "LNA gain 5Ghz: %hhx %hhx %hhx\n", dev->ee->lna_gain_5ghz[0], dev->ee->lna_gain_5ghz[1], dev->ee->lna_gain_5ghz[2]); - seq_printf(file, "Power Amplifier type %hhx\n", dev->ee->pa_type); + + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_0); + seq_printf(file, "Power Amplifier type %lx\n", + val & MT_EE_NIC_CONF_0_PA_TYPE); seq_printf(file, "Reg channels: %hhu-%hhu\n", dev->ee->reg.start, dev->ee->reg.start + dev->ee->reg.num - 1); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index 43239a1cb1e5..6c492a21be26 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -90,9 +90,6 @@ mt76x0_set_chip_cap(struct mt76x0_dev *dev, u8 *eeprom) FIELD_GET(MT_EE_NIC_CONF_0_TX_PATH, nic_conf0) > 1) dev_err(dev->mt76.dev, "Error: device has more than 1 RX/TX stream!\n"); - - dev->ee->pa_type = FIELD_GET(MT_EE_NIC_CONF_0_PA_TYPE, nic_conf0); - dev_dbg(dev->mt76.dev, "PA Type %d\n", dev->ee->pa_type); } static void @@ -330,6 +327,10 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev) if (ret) return ret; + ret = mt76_eeprom_init(&dev->mt76, MT76X0_EEPROM_SIZE); + if (ret < 0) + return ret; + dev->ee = devm_kzalloc(dev->mt76.dev, sizeof(*dev->ee), GFP_KERNEL); if (!dev->ee) return -ENOMEM; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h index 1051e3216614..e58a30589aa2 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h @@ -35,7 +35,6 @@ struct mt76x0_eeprom_params { s8 rssi_offset_5ghz[3]; s8 lna_gain_2ghz; s8 lna_gain_5ghz[3]; - u8 pa_type; /* TX_PWR_CFG_* values from EEPROM for 20 and 40 Mhz bandwidths. */ u32 tx_pwr_cfg_2g[5][2]; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index 2b6d928aab89..ba0e68b33ae7 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -340,16 +340,12 @@ mt76x0_phy_set_band(struct mt76x0_dev *dev, enum nl80211_band band) } } -#define EXT_PA_2G_5G 0x0 -#define EXT_PA_5G_ONLY 0x1 -#define EXT_PA_2G_ONLY 0x2 -#define INT_PA_2G_5G 0x3 - static void mt76x0_phy_set_chan_rf_params(struct mt76x0_dev *dev, u8 channel, u16 rf_bw_band) { u16 rf_band = rf_bw_band & 0xff00; u16 rf_bw = rf_bw_band & 0x00ff; + enum nl80211_band band; u32 mac_reg; u8 rf_val; int i; @@ -496,11 +492,8 @@ mt76x0_phy_set_chan_rf_params(struct mt76x0_dev *dev, u8 channel, u16 rf_bw_band mac_reg &= ~0xC; /* Clear 0x518[3:2] */ mt76_wr(dev, MT_RF_MISC, mac_reg); - if (dev->ee->pa_type == INT_PA_2G_5G || - (dev->ee->pa_type == EXT_PA_5G_ONLY && (rf_band & RF_G_BAND)) || - (dev->ee->pa_type == EXT_PA_2G_ONLY && (rf_band & RF_A_BAND))) { - ; /* Internal PA - nothing to do. */ - } else { + band = (rf_band & RF_G_BAND) ? NL80211_BAND_2GHZ : NL80211_BAND_5GHZ; + if (mt76x02_ext_pa_enabled(&dev->mt76, band)) { /* MT_RF_MISC (offset: 0x0518) [2]1'b1: enable external A band PA, 1'b0: disable external A band PA diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c index 21fe7eb0652d..edb08863e4ba 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c @@ -70,3 +70,14 @@ int mt76x02_get_efuse_data(struct mt76_dev *dev, u16 base, void *buf, return 0; } EXPORT_SYMBOL_GPL(mt76x02_get_efuse_data); + +bool mt76x02_ext_pa_enabled(struct mt76_dev *dev, enum nl80211_band band) +{ + u16 conf0 = mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_0); + + if (band == NL80211_BAND_5GHZ) + return !(conf0 & MT_EE_NIC_CONF_0_PA_INT_5G); + else + return !(conf0 & MT_EE_NIC_CONF_0_PA_INT_2G); +} +EXPORT_SYMBOL_GPL(mt76x02_ext_pa_enabled); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h index 852ea9b51e97..70ca2729895c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h @@ -151,6 +151,7 @@ mt76x02_eeprom_get(struct mt76_dev *dev, return get_unaligned_le16(dev->eeprom.data + field); } +bool mt76x02_ext_pa_enabled(struct mt76_dev *dev, enum nl80211_band band); int mt76x02_get_efuse_data(struct mt76_dev *dev, u16 base, void *buf, int len, enum mt76x02_eeprom_modes mode); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c index 333faa44d7cc..ab52a7f19611 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c @@ -568,7 +568,7 @@ int mt76x2_get_temp_comp(struct mt76x2_dev *dev, struct mt76x2_temp_comp *t) if (!mt76x2_temp_tx_alc_enabled(dev)) return -EINVAL; - if (!mt76x2_ext_pa_enabled(dev, band)) + if (!mt76x02_ext_pa_enabled(&dev->mt76, band)) return -EINVAL; val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_EXT_PA_5G) >> 8; @@ -594,17 +594,6 @@ int mt76x2_get_temp_comp(struct mt76x2_dev *dev, struct mt76x2_temp_comp *t) } EXPORT_SYMBOL_GPL(mt76x2_get_temp_comp); -bool mt76x2_ext_pa_enabled(struct mt76x2_dev *dev, enum nl80211_band band) -{ - u16 conf0 = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_0); - - if (band == NL80211_BAND_5GHZ) - return !(conf0 & MT_EE_NIC_CONF_0_PA_INT_5G); - else - return !(conf0 & MT_EE_NIC_CONF_0_PA_INT_2G); -} -EXPORT_SYMBOL_GPL(mt76x2_ext_pa_enabled); - int mt76x2_eeprom_init(struct mt76x2_dev *dev) { int ret; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h index 6064ef103d2c..da476aad65fb 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h @@ -63,7 +63,6 @@ void mt76x2_get_power_info(struct mt76x2_dev *dev, struct mt76x2_tx_power_info *t, struct ieee80211_channel *chan); int mt76x2_get_temp_comp(struct mt76x2_dev *dev, struct mt76x2_temp_comp *t); -bool mt76x2_ext_pa_enabled(struct mt76x2_dev *dev, enum nl80211_band band); void mt76x2_read_rx_gain(struct mt76x2_dev *dev); void mt76x2_eeprom_parse_hw_cap(struct mt76x2_dev *dev); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x2_phy.c index 4477a4e184e9..3f786596e586 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_phy.c @@ -34,7 +34,7 @@ mt76x2_phy_tssi_init_cal(struct mt76x2_dev *dev) if (chan->band == NL80211_BAND_5GHZ) flag |= BIT(0); - if (mt76x2_ext_pa_enabled(dev, chan->band)) + if (mt76x02_ext_pa_enabled(&dev->mt76, chan->band)) flag |= BIT(8); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TSSI, flag, true); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_phy_common.c b/drivers/net/wireless/mediatek/mt76/mt76x2_phy_common.c index 42ca855c7579..c059305b9186 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_phy_common.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_phy_common.c @@ -64,7 +64,7 @@ void mt76x2_phy_set_txpower_regs(struct mt76x2_dev *dev, mt76_wr(dev, MT_TX_ALC_CFG_2, 0x35160a00); mt76_wr(dev, MT_TX_ALC_CFG_3, 0x35160a06); - if (mt76x2_ext_pa_enabled(dev, band)) { + if (mt76x02_ext_pa_enabled(&dev->mt76, band)) { mt76_wr(dev, MT_RF_PA_MODE_ADJ0, 0x0000ec00); mt76_wr(dev, MT_RF_PA_MODE_ADJ1, 0x0000ec00); } else { @@ -75,7 +75,7 @@ void mt76x2_phy_set_txpower_regs(struct mt76x2_dev *dev, pa_mode[0] = 0x0000ffff; pa_mode[1] = 0x00ff00ff; - if (mt76x2_ext_pa_enabled(dev, band)) { + if (mt76x02_ext_pa_enabled(&dev->mt76, band)) { mt76_wr(dev, MT_TX_ALC_CFG_2, 0x2f0f0400); mt76_wr(dev, MT_TX_ALC_CFG_3, 0x2f0f0476); } else { @@ -83,7 +83,7 @@ void mt76x2_phy_set_txpower_regs(struct mt76x2_dev *dev, mt76_wr(dev, MT_TX_ALC_CFG_3, 0x1b0f0476); } - if (mt76x2_ext_pa_enabled(dev, band)) + if (mt76x02_ext_pa_enabled(&dev->mt76, band)) pa_mode_adj = 0x04000000; else pa_mode_adj = 0; @@ -97,7 +97,7 @@ void mt76x2_phy_set_txpower_regs(struct mt76x2_dev *dev, mt76_wr(dev, MT_RF_PA_MODE_CFG0, pa_mode[0]); mt76_wr(dev, MT_RF_PA_MODE_CFG1, pa_mode[1]); - if (mt76x2_ext_pa_enabled(dev, band)) { + if (mt76x02_ext_pa_enabled(&dev->mt76, band)) { u32 val; if (band == NL80211_BAND_2GHZ) @@ -244,7 +244,7 @@ void mt76x2_configure_tx_delay(struct mt76x2_dev *dev, { u32 cfg0, cfg1; - if (mt76x2_ext_pa_enabled(dev, band)) { + if (mt76x02_ext_pa_enabled(&dev->mt76, band)) { cfg0 = bw ? 0x000b0c01 : 0x00101101; cfg1 = 0x00011414; } else { @@ -370,7 +370,7 @@ void mt76x2_phy_tssi_compensate(struct mt76x2_dev *dev, bool wait) dev->cal.tssi_comp_pending = false; mt76x2_get_power_info(dev, &txp, chan); - if (mt76x2_ext_pa_enabled(dev, chan->band)) + if (mt76x02_ext_pa_enabled(&dev->mt76, chan->band)) t.pa_mode = 1; t.cal_mode = BIT(1); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2u_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x2u_phy.c index 9842ed04d764..1cd9b2468ef0 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2u_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2u_phy.c @@ -250,7 +250,7 @@ int mt76x2u_phy_set_channel(struct mt76x2_dev *dev, chan = dev->mt76.chandef.chan; if (chan->band == NL80211_BAND_5GHZ) flag |= BIT(0); - if (mt76x2_ext_pa_enabled(dev, chan->band)) + if (mt76x02_ext_pa_enabled(&dev->mt76, chan->band)) flag |= BIT(8); mt76x02_mcu_calibrate(&dev->mt76, MCU_CAL_TSSI, flag, false); From patchwork Thu Sep 20 09:11:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607177 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 CF6721390 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 C11702CC77 for ; Thu, 20 Sep 2018 09:12:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B587D2CCB4; 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 36A142CC13 for ; Thu, 20 Sep 2018 09:12:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387474AbeITOzE (ORCPT ); Thu, 20 Sep 2018 10:55:04 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:37296 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387433AbeITOzD (ORCPT ); Thu, 20 Sep 2018 10:55:03 -0400 Received: by mail-wr1-f65.google.com with SMTP id u12-v6so8581175wrr.4 for ; Thu, 20 Sep 2018 02:12:34 -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=pTP+Z4WWIn6SO7Fo1gacwASAnQom8Px1On+RC6dcYAQ=; b=U078DKKh1AHoV3Er7zbzRA09ODjp7cR5ly7RNs6XLqvkJe+dzcjnpJfqJbfyC8ovI0 wHIKn4k3Axy7XD4wrYlaqOetsHrNKGfPJDlWAjMOd+L3m9Q87E5BiSEQofFKnsh20ySF uHMXn7GWfKdVSCU+B9xrSEdVvCZXThFgK86hbRpw9aR/a2T9yC348baxcNVDpTlS6QrO F5dI3nZOWYlMmfHG3QCAwIil3UqhQnFxGjhb8PEYBF56HLiXO5UxIWJDnfGxOp7Z9jxn zPeB0XK/neB+9JLNPOUcRqJFkMs2YV7u3racPics2mycWZo7Wa4IBLjwOerFRSBFQ1IK 99LQ== X-Gm-Message-State: APzg51BBkVdg6CqPrhdW/Vuzx5KFeqM492UiL9S9lHoO7Q8/Pkto8g23 6XBS8uhHhswgoogxNs4xjn+qpA== X-Google-Smtp-Source: ANB0VdaMO3xLYwNtTExH+p1Xh8XbeEh+5anCtTTRGI5ksepZlGRcpm1tKvTonbcArSWv0VXIRJB+0A== X-Received: by 2002:adf:add0:: with SMTP id w74-v6mr33249412wrc.73.1537434753912; Thu, 20 Sep 2018 02:12:33 -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.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:33 -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 09/20] mt76x0: remove mt76x0_set_country_reg routine Date: Thu, 20 Sep 2018 11:11:56 +0200 Message-Id: <249232763e7ee05755b26bbb0a05c933d2a1ae95.1537433365.git.lorenzo.bianconi@redhat.com> 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 Remove mt76x0_set_country_reg routine for the moment since it is partial and it is not actually used Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/debugfs.c | 2 - .../wireless/mediatek/mt76/mt76x0/eeprom.c | 38 ------------------- .../wireless/mediatek/mt76/mt76x0/eeprom.h | 2 - 3 files changed, 42 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c index f9e305840176..932c0e41196c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c @@ -117,8 +117,6 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data) val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_0); seq_printf(file, "Power Amplifier type %lx\n", val & MT_EE_NIC_CONF_0_PA_TYPE); - seq_printf(file, "Reg channels: %hhu-%hhu\n", dev->ee->reg.start, - dev->ee->reg.start + dev->ee->reg.num - 1); seq_puts(file, "Per channel power:\n"); for (i = 0; i < 58; i++) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index 6c492a21be26..5d08a7bb16ce 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -103,43 +103,6 @@ mt76x0_set_temp_offset(struct mt76x0_dev *dev, u8 *eeprom) dev->ee->temp_off = -10; } -static void -mt76x0_set_country_reg(struct mt76x0_dev *dev, u8 *eeprom) -{ - /* Note: - region 31 is not valid for mt76x0 (see rtmp_init.c) - * - comments in rtmp_def.h are incorrect (see rt_channel.c) - */ - static const struct reg_channel_bounds chan_bounds[] = { - /* EEPROM country regions 0 - 7 */ - { 1, 11 }, { 1, 13 }, { 10, 2 }, { 10, 4 }, - { 14, 1 }, { 1, 14 }, { 3, 7 }, { 5, 9 }, - /* EEPROM country regions 32 - 33 */ - { 1, 11 }, { 1, 14 } - }; - u8 val = eeprom[MT_EE_COUNTRY_REGION_2GHZ]; - int idx = -1; - - dev_dbg(dev->mt76.dev, "REG 2GHZ %u REG 5GHZ %u\n", val, eeprom[MT_EE_COUNTRY_REGION_5GHZ]); - if (val < 8) - idx = val; - if (val > 31 && val < 33) - idx = val - 32 + 8; - - if (idx != -1) - dev_info(dev->mt76.dev, - "EEPROM country region %02hhx (channels %hhd-%hhd)\n", - val, chan_bounds[idx].start, - chan_bounds[idx].start + chan_bounds[idx].num - 1); - else - idx = 5; /* channels 1 - 14 */ - - dev->ee->reg = chan_bounds[idx]; - - /* TODO: country region 33 is special - phy should be set to B-mode - * before entering channel 14 (see sta/connect.c) - */ -} - static void mt76x0_set_rf_freq_off(struct mt76x0_dev *dev, u8 *eeprom) { @@ -353,7 +316,6 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev) mt76x02_mac_setaddr(&dev->mt76, eeprom + MT_EE_MAC_ADDR); mt76x0_set_chip_cap(dev, eeprom); - mt76x0_set_country_reg(dev, eeprom); mt76x0_set_rf_freq_off(dev, eeprom); mt76x0_set_temp_offset(dev, eeprom); mt76x0_set_lna_gain(dev, eeprom); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h index e58a30589aa2..dbfcbfa71291 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h @@ -41,8 +41,6 @@ struct mt76x0_eeprom_params { u32 tx_pwr_cfg_5g[5][2]; u8 tx_pwr_per_chan[58]; - - struct reg_channel_bounds reg; }; int mt76x0_eeprom_init(struct mt76x0_dev *dev); From patchwork Thu Sep 20 09:11:57 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607183 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 0D6DC1390 for ; Thu, 20 Sep 2018 09:12:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F03BB2CC13 for ; Thu, 20 Sep 2018 09:12:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E4C7A2CC70; Thu, 20 Sep 2018 09:12:38 +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 748522CC13 for ; Thu, 20 Sep 2018 09:12:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387481AbeITOzF (ORCPT ); Thu, 20 Sep 2018 10:55:05 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:38395 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387441AbeITOzF (ORCPT ); Thu, 20 Sep 2018 10:55:05 -0400 Received: by mail-wr1-f65.google.com with SMTP id j8-v6so4849683wrw.5 for ; Thu, 20 Sep 2018 02:12:35 -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=vfDedjguJSRlsnqSUvE25v21Wi8DoQLscqFLlqeO82A=; b=Ow6v15Cgp/jBOau71bB9QLU8zpiVcqTgdRlVSH5tbqPA57ed9uA7rb+LPRbQt+xOMn +dr66Gg/IvLbd9uGV2yQsu80sq3yF42R63/Ac65F8neINHRNb0r9uHrCx15/C3f5jtoO Ee/GwxMvxqAco2Ktg3+v7Wk+0YvnUU87PcIr1mxbgPxDLBI9zpZOHxTFVps6KIan5LGV /boTfsE1yhhxNLVdeYmJzQZ/u3+cV9C8Y7CbmwCyZhhsv4LpBuZKIbmog3pClnWI+vo3 Io4t6D8Q1Yld2cB3Z0zypJCz6Li3pTtctkumgd1BvYAwC/vfjTpncE49qYi8d9etU4Q9 Sj6w== X-Gm-Message-State: APzg51A6rv0GDMGIx3NYkdtbWPSTzl0ohmbzxYLZ3sC5lVrkDq12HXAP XTPzhW1t6J5x9wWY2zSA+4B+UBRRtqY= X-Google-Smtp-Source: ANB0VdYiOljuHMvn1we1BZWo+14yKDTAnV47+LrSSUDkMCyACIvuX2g9j9sYm9BSVsOqDuzkPwUROA== X-Received: by 2002:adf:b243:: with SMTP id y3-v6mr32694353wra.90.1537434754866; Thu, 20 Sep 2018 02:12:34 -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.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:34 -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 10/20] mt76: add mt76x02_get_rx_gain and mt76x02_get_lna_gain utility routines Date: Thu, 20 Sep 2018 11:11:57 +0200 Message-Id: <4a7eb29d1cc6193b58a89de88c6b3b6af65c75f3.1537433365.git.lorenzo.bianconi@redhat.com> 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 Add mt76x02_get_rx_gain and mt76x02_get_lna_gain utility routines for rx gain parsing. mt76x02_get_rx_gain and mt76x02_get_lna_gain will be reused for eeprom parsing in mt76x0 driver Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x02_eeprom.c | 54 +++++++++++++++++++ .../wireless/mediatek/mt76/mt76x02_eeprom.h | 5 ++ .../wireless/mediatek/mt76/mt76x2_eeprom.c | 47 ++-------------- 3 files changed, 63 insertions(+), 43 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c index edb08863e4ba..2377c758da5d 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c @@ -81,3 +81,57 @@ bool mt76x02_ext_pa_enabled(struct mt76_dev *dev, enum nl80211_band band) return !(conf0 & MT_EE_NIC_CONF_0_PA_INT_2G); } EXPORT_SYMBOL_GPL(mt76x02_ext_pa_enabled); + +void mt76x02_get_rx_gain(struct mt76_dev *dev, enum nl80211_band band, + u16 *rssi_offset, s8 *lna_2g, s8 *lna_5g) +{ + u16 val; + + val = mt76x02_eeprom_get(dev, MT_EE_LNA_GAIN); + *lna_2g = val & 0xff; + lna_5g[0] = val >> 8; + + val = mt76x02_eeprom_get(dev, MT_EE_RSSI_OFFSET_2G_1); + lna_5g[1] = val >> 8; + + val = mt76x02_eeprom_get(dev, MT_EE_RSSI_OFFSET_5G_1); + lna_5g[2] = val >> 8; + + if (!mt76x02_field_valid(lna_5g[1])) + lna_5g[1] = lna_5g[0]; + + if (!mt76x02_field_valid(lna_5g[2])) + lna_5g[2] = lna_5g[0]; + + if (band == NL80211_BAND_2GHZ) + *rssi_offset = mt76x02_eeprom_get(dev, MT_EE_RSSI_OFFSET_2G_0); + else + *rssi_offset = mt76x02_eeprom_get(dev, MT_EE_RSSI_OFFSET_5G_0); +} +EXPORT_SYMBOL_GPL(mt76x02_get_rx_gain); + +u8 mt76x02_get_lna_gain(struct mt76_dev *dev, + s8 *lna_2g, s8 *lna_5g, + struct ieee80211_channel *chan) +{ + u16 val; + u8 lna; + + val = mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1); + if (val & MT_EE_NIC_CONF_1_LNA_EXT_2G) + *lna_2g = 0; + if (val & MT_EE_NIC_CONF_1_LNA_EXT_5G) + memset(lna_5g, 0, sizeof(s8) * 3); + + if (chan->band == NL80211_BAND_2GHZ) + lna = *lna_2g; + else if (chan->hw_value <= 64) + lna = lna_5g[0]; + else if (chan->hw_value <= 128) + lna = lna_5g[1]; + else + lna = lna_5g[2]; + + return lna != 0xff ? lna : 0; +} +EXPORT_SYMBOL_GPL(mt76x02_get_lna_gain); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h index 70ca2729895c..c22ca507b418 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h @@ -154,5 +154,10 @@ mt76x02_eeprom_get(struct mt76_dev *dev, bool mt76x02_ext_pa_enabled(struct mt76_dev *dev, enum nl80211_band band); int mt76x02_get_efuse_data(struct mt76_dev *dev, u16 base, void *buf, int len, enum mt76x02_eeprom_modes mode); +void mt76x02_get_rx_gain(struct mt76_dev *dev, enum nl80211_band band, + u16 *rssi_offset, s8 *lna_2g, s8 *lna_5g); +u8 mt76x02_get_lna_gain(struct mt76_dev *dev, + s8 *lna_2g, s8 *lna_5g, + struct ieee80211_channel *chan); #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 ab52a7f19611..b9641e2408ee 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c @@ -310,55 +310,16 @@ void mt76x2_read_rx_gain(struct mt76x2_dev *dev) mt76x2_set_rx_gain_group(dev, val); - if (chan->band == NL80211_BAND_2GHZ) { - val = mt76x02_eeprom_get(&dev->mt76, MT_EE_RSSI_OFFSET_2G_0); - mt76x2_set_rssi_offset(dev, 0, val); - mt76x2_set_rssi_offset(dev, 1, val >> 8); - } else { - val = mt76x02_eeprom_get(&dev->mt76, MT_EE_RSSI_OFFSET_5G_0); - mt76x2_set_rssi_offset(dev, 0, val); - mt76x2_set_rssi_offset(dev, 1, val >> 8); - } - - val = mt76x02_eeprom_get(&dev->mt76, MT_EE_LNA_GAIN); - lna_2g = val & 0xff; - lna_5g[0] = val >> 8; - - val = mt76x02_eeprom_get(&dev->mt76, MT_EE_RSSI_OFFSET_2G_1); - lna_5g[1] = val >> 8; - - val = mt76x02_eeprom_get(&dev->mt76, MT_EE_RSSI_OFFSET_5G_1); - lna_5g[2] = val >> 8; - - if (!mt76x02_field_valid(lna_5g[1])) - lna_5g[1] = lna_5g[0]; - - if (!mt76x02_field_valid(lna_5g[2])) - lna_5g[2] = lna_5g[0]; + mt76x02_get_rx_gain(&dev->mt76, chan->band, &val, &lna_2g, lna_5g); + mt76x2_set_rssi_offset(dev, 0, val); + mt76x2_set_rssi_offset(dev, 1, val >> 8); dev->cal.rx.mcu_gain = (lna_2g & 0xff); dev->cal.rx.mcu_gain |= (lna_5g[0] & 0xff) << 8; dev->cal.rx.mcu_gain |= (lna_5g[1] & 0xff) << 16; dev->cal.rx.mcu_gain |= (lna_5g[2] & 0xff) << 24; - val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_1); - if (val & MT_EE_NIC_CONF_1_LNA_EXT_2G) - lna_2g = 0; - if (val & MT_EE_NIC_CONF_1_LNA_EXT_5G) - memset(lna_5g, 0, sizeof(lna_5g)); - - if (chan->band == NL80211_BAND_2GHZ) - lna = lna_2g; - else if (channel <= 64) - lna = lna_5g[0]; - else if (channel <= 128) - lna = lna_5g[1]; - else - lna = lna_5g[2]; - - if (lna == 0xff) - lna = 0; - + lna = mt76x02_get_lna_gain(&dev->mt76, &lna_2g, lna_5g, chan); dev->cal.rx.lna_gain = mt76x02_sign_extend(lna, 8); } EXPORT_SYMBOL_GPL(mt76x2_read_rx_gain); From patchwork Thu Sep 20 09:11:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607187 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 6646F1390 for ; Thu, 20 Sep 2018 09:12:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 563072CBE7 for ; Thu, 20 Sep 2018 09:12:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4A55A2CC43; Thu, 20 Sep 2018 09:12:40 +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 B731F2CC13 for ; Thu, 20 Sep 2018 09:12:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387487AbeITOzG (ORCPT ); Thu, 20 Sep 2018 10:55:06 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:36677 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387433AbeITOzG (ORCPT ); Thu, 20 Sep 2018 10:55:06 -0400 Received: by mail-wm1-f65.google.com with SMTP id j192-v6so10093136wmj.1 for ; Thu, 20 Sep 2018 02:12:36 -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=CHgh41U0YR4iIGUE1ZR/icGAqik8AGeV0Dg4TCU/Qu4=; b=iAfjj1BKJZOKuqgzSVwswfFlDo9b/c4B2ucd4yjytro8zHBWV7VcJ0i8xxsKMAZEJ4 GfVY5Ajhjld0/zDrwhEtBsCZ0hdnFDsn1EP0FuJ35L/EWUjpAB1qcjwhkWWep6sxB3R2 vm6JdIe9ZD8lINhwHUH2QP+l6qtwSVLU3XJF3smJKCOIVbV7CMW2h2JgxvDwlruTzn+G dzbTjckrhgJdDmh5iJapPJjsvVDT6zMN5W/eFU5XQ+fBWDL2nluteXzDoGjjPnAWCW3V kjkY09FCe1mQqcgQSn5OUxHlOMNRCAAcqyhuaXMnqVmFsUqGma+DSBPdN9/VZk2gRR49 Ynrg== X-Gm-Message-State: APzg51A5oyd4ayrtgSIbFcX0M6Jzmo08dByIRzmbAdCviNy/ITBNASaB rhp/+Eay7fFiUyr1pLZ1LmzMAA== X-Google-Smtp-Source: ANB0VdYHtQaOiUFH/IjKox/ca3xI5BL7YSEZDKTikuR9glih1ebNrVdd2nVpiFzy12Rxzu5f9kBkOg== X-Received: by 2002:a1c:f913:: with SMTP id x19-v6mr1695881wmh.63.1537434755789; Thu, 20 Sep 2018 02:12:35 -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.34 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:35 -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 11/20] mt76x0: unify lna_gain parsing Date: Thu, 20 Sep 2018 11:11:58 +0200 Message-Id: <697986870ee86c266689c8387b20803255bd5d5d.1537433365.git.lorenzo.bianconi@redhat.com> 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 Unify lna gain parsing with mt76x2 driver using eeprom utility routines available in mt76x02-lib module Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/debugfs.c | 5 +--- .../wireless/mediatek/mt76/mt76x0/eeprom.c | 26 +++++++------------ .../wireless/mediatek/mt76/mt76x0/eeprom.h | 7 +++-- .../wireless/mediatek/mt76/mt76x0/mt76x0.h | 2 ++ .../net/wireless/mediatek/mt76/mt76x0/phy.c | 24 +++++------------ 5 files changed, 24 insertions(+), 40 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c index 932c0e41196c..566ed0b61035 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c @@ -109,10 +109,7 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data) dev->ee->rssi_offset_5ghz[0], dev->ee->rssi_offset_5ghz[1], dev->ee->rssi_offset_5ghz[2]); seq_printf(file, "Temperature offset: %hhx\n", dev->ee->temp_off); - seq_printf(file, "LNA gain 2Ghz: %hhx\n", dev->ee->lna_gain_2ghz); - seq_printf(file, "LNA gain 5Ghz: %hhx %hhx %hhx\n", - dev->ee->lna_gain_5ghz[0], dev->ee->lna_gain_5ghz[1], - dev->ee->lna_gain_5ghz[2]); + seq_printf(file, "LNA gain: %x\n", dev->caldata.lna_gain); val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_0); seq_printf(file, "Power Amplifier type %lx\n", diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index 5d08a7bb16ce..20a9f8fb20da 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -122,25 +122,18 @@ mt76x0_set_rf_freq_off(struct mt76x0_dev *dev, u8 *eeprom) dev->ee->rf_freq_off += comp; } -static void -mt76x0_set_lna_gain(struct mt76x0_dev *dev, u8 *eeprom) +void mt76x0_read_rx_gain(struct mt76x0_dev *dev) { - u8 gain; - - dev->ee->lna_gain_2ghz = eeprom[MT_EE_LNA_GAIN]; - dev->ee->lna_gain_5ghz[0] = eeprom[MT_EE_LNA_GAIN + 1]; + struct ieee80211_channel *chan = dev->mt76.chandef.chan; + struct mt76x0_caldata *caldata = &dev->caldata; + s8 lna_5g[3], lna_2g; + u16 rssi_offset; - gain = eeprom[MT_EE_LNA_GAIN_5GHZ_1]; - if (gain == 0xff || gain == 0) - dev->ee->lna_gain_5ghz[1] = dev->ee->lna_gain_5ghz[0]; - else - dev->ee->lna_gain_5ghz[1] = gain; + mt76x02_get_rx_gain(&dev->mt76, chan->band, &rssi_offset, + &lna_2g, lna_5g); + caldata->lna_gain = mt76x02_get_lna_gain(&dev->mt76, &lna_2g, + lna_5g, chan); - gain = eeprom[MT_EE_LNA_GAIN_5GHZ_2]; - if (gain == 0xff || gain == 0) - dev->ee->lna_gain_5ghz[2] = dev->ee->lna_gain_5ghz[0]; - else - dev->ee->lna_gain_5ghz[2] = gain; } static void @@ -318,7 +311,6 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev) mt76x0_set_chip_cap(dev, eeprom); mt76x0_set_rf_freq_off(dev, eeprom); mt76x0_set_temp_offset(dev, eeprom); - mt76x0_set_lna_gain(dev, eeprom); mt76x0_set_rssi_offset(dev, eeprom); dev->chainmask = 0x0101; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h index dbfcbfa71291..e62c61d91505 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h @@ -28,13 +28,15 @@ struct reg_channel_bounds { u8 num; }; +struct mt76x0_caldata { + s8 lna_gain; +}; + struct mt76x0_eeprom_params { u8 rf_freq_off; s16 temp_off; s8 rssi_offset_2ghz[2]; s8 rssi_offset_5ghz[3]; - s8 lna_gain_2ghz; - s8 lna_gain_5ghz[3]; /* TX_PWR_CFG_* values from EEPROM for 20 and 40 Mhz bandwidths. */ u32 tx_pwr_cfg_2g[5][2]; @@ -44,6 +46,7 @@ struct mt76x0_eeprom_params { }; int mt76x0_eeprom_init(struct mt76x0_dev *dev); +void mt76x0_read_rx_gain(struct mt76x0_dev *dev); static inline u32 s6_validate(u32 reg) { diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h index 6aaa9a5b51db..99d48fa96fd9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h @@ -28,6 +28,7 @@ #include "../mt76.h" #include "../mt76x02_regs.h" #include "../mt76x02_mac.h" +#include "eeprom.h" #define MT_CALIBRATE_INTERVAL (4 * HZ) @@ -89,6 +90,7 @@ struct mt76x0_dev { const u16 *beacon_offsets; struct mt76x0_eeprom_params *ee; + struct mt76x0_caldata caldata; struct mutex reg_atomic_mutex; struct mutex hw_atomic_mutex; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index ba0e68b33ae7..08041ea70a1c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -228,18 +228,17 @@ mt76x0_bbp_set_ctrlch(struct mt76x0_dev *dev, enum nl80211_chan_width width, int mt76x0_phy_get_rssi(struct mt76x0_dev *dev, struct mt76x02_rxwi *rxwi) { - s8 lna_gain, rssi_offset; + struct mt76x0_caldata *caldata = &dev->caldata; + s8 rssi_offset; int val; if (dev->mt76.chandef.chan->band == NL80211_BAND_2GHZ) { - lna_gain = dev->ee->lna_gain_2ghz; rssi_offset = dev->ee->rssi_offset_2ghz[0]; } else { - lna_gain = dev->ee->lna_gain_5ghz[0]; rssi_offset = dev->ee->rssi_offset_5ghz[0]; } - val = rxwi->rssi[0] + rssi_offset - lna_gain; + val = rxwi->rssi[0] + rssi_offset - caldata->lna_gain; return val; } @@ -545,20 +544,10 @@ mt76x0_phy_set_chan_bbp_params(struct mt76x0_dev *dev, u8 channel, u16 rf_bw_ban if (pair->reg == MT_BBP(AGC, 8)) { u32 val = pair->value; - u8 gain = FIELD_GET(MT_BBP_AGC_GAIN, val); - - if (channel > 14) { - if (channel < 100) - gain -= dev->ee->lna_gain_5ghz[0]*2; - else if (channel < 137) - gain -= dev->ee->lna_gain_5ghz[1]*2; - else - gain -= dev->ee->lna_gain_5ghz[2]*2; - - } else { - gain -= dev->ee->lna_gain_2ghz*2; - } + u8 gain; + gain = FIELD_GET(MT_BBP_AGC_GAIN, val); + gain -= dev->caldata.lna_gain * 2; val &= ~MT_BBP_AGC_GAIN; val |= FIELD_PREP(MT_BBP_AGC_GAIN, gain); mt76_wr(dev, pair->reg, val); @@ -737,6 +726,7 @@ __mt76x0_phy_set_channel(struct mt76x0_dev *dev, mt76x0_phy_set_band(dev, chandef->chan->band); mt76x0_phy_set_chan_rf_params(dev, channel, rf_bw_band); + mt76x0_read_rx_gain(dev); /* set Japan Tx filter at channel 14 */ val = mt76_rr(dev, MT_BBP(CORE, 1)); From patchwork Thu Sep 20 09:11:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607189 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 12F701508 for ; Thu, 20 Sep 2018 09:12:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F3E792CC13 for ; Thu, 20 Sep 2018 09:12:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E849A2CC43; Thu, 20 Sep 2018 09:12:41 +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 6F3F02CC13 for ; Thu, 20 Sep 2018 09:12:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387490AbeITOzH (ORCPT ); Thu, 20 Sep 2018 10:55:07 -0400 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41720 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387475AbeITOzH (ORCPT ); Thu, 20 Sep 2018 10:55:07 -0400 Received: by mail-wr1-f65.google.com with SMTP id j15-v6so4504070wrt.8 for ; Thu, 20 Sep 2018 02:12:37 -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=JrRqjB+6AoD0LVCIqg1g/PP7bL82hE7G8sdiyy53EjE=; b=ZEBEXHlKwCByrhpDv+qup2pTvZB7XfHYIRBdO6a9VoaBGRmxDRAIXsZI4INxyP2nlj fBXqC15UmrH+ntF6HxEuDsuSLjr6A5CCS/kWmyc/McnW86coUqbRlNkb95LtYg37S51l t4Eh+qAvnFiDcauCo6kAgWKcDzHNqgKZYvGtQh4JTmtjO9ZP/8D3Jilgv75tOCtYZkMX B5nWVYYhpynhxbgyL9fe2hWSX4SfFxoxCck7GEcxxRPKH1q8UNQ21EQw3JRM/PgLfQ8a azvFNDkba7K7pDw3Afs61sthqGzYuayKsux8v7/9kL620WlY3JmGz40SP3VRXDHAiunI PK1w== X-Gm-Message-State: APzg51D5Zpz5u7XXm1X3lo3h199CAikietm0Rzf+lhgtC3eSJU71LChl N/TNxiAYeJ94DkGNl3qcL73uTw== X-Google-Smtp-Source: ANB0VdZ0uQzPhzUXQhoO55J0u+1f9NT23S+TBQZ+h8UvPNCiiqC3rIR0pEPofKbN8GRF6OQGsX8nRQ== X-Received: by 2002:adf:9f13:: with SMTP id l19-v6mr33029742wrf.206.1537434756695; Thu, 20 Sep 2018 02:12:36 -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.35 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:36 -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 12/20] mt76x0: unify rssi_offset parsing Date: Thu, 20 Sep 2018 11:11:59 +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 Unify rssi_offset parsing with mt76x2 driver using eeprom utility routines available in mt76x02-lib module Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/debugfs.c | 7 +--- .../wireless/mediatek/mt76/mt76x0/eeprom.c | 38 ++++--------------- .../wireless/mediatek/mt76/mt76x0/eeprom.h | 3 +- .../net/wireless/mediatek/mt76/mt76x0/phy.c | 12 +----- 4 files changed, 11 insertions(+), 49 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c index 566ed0b61035..b6f467e7ee8c 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c @@ -103,11 +103,8 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data) int i; seq_printf(file, "RF freq offset: %hhx\n", dev->ee->rf_freq_off); - seq_printf(file, "RSSI offset 2GHz: %hhx %hhx\n", - dev->ee->rssi_offset_2ghz[0], dev->ee->rssi_offset_2ghz[1]); - seq_printf(file, "RSSI offset 5GHz: %hhx %hhx %hhx\n", - dev->ee->rssi_offset_5ghz[0], dev->ee->rssi_offset_5ghz[1], - dev->ee->rssi_offset_5ghz[2]); + seq_printf(file, "RSSI offset: %hhx %hhx\n", + dev->caldata.rssi_offset[0], dev->caldata.rssi_offset[1]); seq_printf(file, "Temperature offset: %hhx\n", dev->ee->temp_off); seq_printf(file, "LNA gain: %x\n", dev->caldata.lna_gain); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index 20a9f8fb20da..6c24274d23f4 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -126,44 +126,21 @@ void mt76x0_read_rx_gain(struct mt76x0_dev *dev) { struct ieee80211_channel *chan = dev->mt76.chandef.chan; struct mt76x0_caldata *caldata = &dev->caldata; - s8 lna_5g[3], lna_2g; + s8 val, lna_5g[3], lna_2g; u16 rssi_offset; + int i; mt76x02_get_rx_gain(&dev->mt76, chan->band, &rssi_offset, &lna_2g, lna_5g); caldata->lna_gain = mt76x02_get_lna_gain(&dev->mt76, &lna_2g, lna_5g, chan); -} - -static void -mt76x0_set_rssi_offset(struct mt76x0_dev *dev, u8 *eeprom) -{ - int i; - s8 *rssi_offset = dev->ee->rssi_offset_2ghz; - - for (i = 0; i < 2; i++) { - rssi_offset[i] = eeprom[MT_EE_RSSI_OFFSET_2G_0 + i]; + for (i = 0; i < ARRAY_SIZE(caldata->rssi_offset); i++) { + val = rssi_offset >> (8 * i); + if (val < -10 || val > 10) + val = 0; - if (rssi_offset[i] < -10 || rssi_offset[i] > 10) { - dev_warn(dev->mt76.dev, - "Warning: EEPROM RSSI is invalid %02hhx\n", - rssi_offset[i]); - rssi_offset[i] = 0; - } - } - - rssi_offset = dev->ee->rssi_offset_5ghz; - - for (i = 0; i < 3; i++) { - rssi_offset[i] = eeprom[MT_EE_RSSI_OFFSET_5G_0 + i]; - - if (rssi_offset[i] < -10 || rssi_offset[i] > 10) { - dev_warn(dev->mt76.dev, - "Warning: EEPROM RSSI is invalid %02hhx\n", - rssi_offset[i]); - rssi_offset[i] = 0; - } + caldata->rssi_offset[i] = val; } } @@ -311,7 +288,6 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev) mt76x0_set_chip_cap(dev, eeprom); mt76x0_set_rf_freq_off(dev, eeprom); mt76x0_set_temp_offset(dev, eeprom); - mt76x0_set_rssi_offset(dev, eeprom); dev->chainmask = 0x0101; mt76x0_set_tx_power_per_rate(dev, eeprom); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h index e62c61d91505..dd9cb0d2de41 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h @@ -29,14 +29,13 @@ struct reg_channel_bounds { }; struct mt76x0_caldata { + s8 rssi_offset[2]; s8 lna_gain; }; struct mt76x0_eeprom_params { u8 rf_freq_off; s16 temp_off; - s8 rssi_offset_2ghz[2]; - s8 rssi_offset_5ghz[3]; /* TX_PWR_CFG_* values from EEPROM for 20 and 40 Mhz bandwidths. */ u32 tx_pwr_cfg_2g[5][2]; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index 08041ea70a1c..72d0ddc381b9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -229,18 +229,8 @@ mt76x0_bbp_set_ctrlch(struct mt76x0_dev *dev, enum nl80211_chan_width width, int mt76x0_phy_get_rssi(struct mt76x0_dev *dev, struct mt76x02_rxwi *rxwi) { struct mt76x0_caldata *caldata = &dev->caldata; - s8 rssi_offset; - int val; - if (dev->mt76.chandef.chan->band == NL80211_BAND_2GHZ) { - rssi_offset = dev->ee->rssi_offset_2ghz[0]; - } else { - rssi_offset = dev->ee->rssi_offset_5ghz[0]; - } - - val = rxwi->rssi[0] + rssi_offset - caldata->lna_gain; - - return val; + return rxwi->rssi[0] + caldata->rssi_offset[0] - caldata->lna_gain; } static void mt76x0_vco_cal(struct mt76x0_dev *dev, u8 channel) From patchwork Thu Sep 20 09:12:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607185 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 170896CB for ; Thu, 20 Sep 2018 09:12:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05DE12CBE7 for ; Thu, 20 Sep 2018 09:12:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE2CD2CC43; Thu, 20 Sep 2018 09:12:40 +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 823012CBE7 for ; Thu, 20 Sep 2018 09:12:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387492AbeITOzH (ORCPT ); Thu, 20 Sep 2018 10:55:07 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:34869 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387441AbeITOzH (ORCPT ); Thu, 20 Sep 2018 10:55:07 -0400 Received: by mail-wm1-f66.google.com with SMTP id o18-v6so10080504wmc.0 for ; Thu, 20 Sep 2018 02:12:38 -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=FxNonfTywGDrcfsW9iBpQWuscO0kRWyqjgRrKkmDuKc=; b=qHTxj/X1iemdxis9kTeOfeo3RbSsy3VOOu7w3m1pYnKnIko8Mt2Id+BKJWvFyzxRZs qzSJ3qP/TJ2yNrHH18G6TheVNqgDnX1+dS3ruBF89qvSjwncMI8bPbU5F7oKM9bNdsqi Yo7jZCeig1BrYE/hpnzgxcUS0BgYxsfwFVqbM8fusbmn/VzGKsIBPSsVirgxXAqC/Uha n197m3IUFbs8uhPJf2089xBvWgklT752zMtHuLf7VxFbevfimcfPnI0GwpPRF4pzNWuZ 7K5Mjso5B2W3k2gj2kxejA/VaTsc91sxh4sKWjUyuRPc8TRXJkNP4h2LvteE8vnORpfP 5c2g== X-Gm-Message-State: APzg51Ag23kNjmPEhiiHY5rwa/R7inoZG0lZ6rN3LDnGOiYiEJp48O+y dRWFzwrNniubAnOHOAW+466oKw== X-Google-Smtp-Source: ANB0VdZM6krSGz8RH/kH+1gUfmOAeFTH0wkMjarFUM05PdJvZpLCQMXKnTeXJLGVXF+gtr3vpJLcsw== X-Received: by 2002:a1c:ba84:: with SMTP id k126-v6mr1574878wmf.96.1537434757701; Thu, 20 Sep 2018 02:12:37 -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.36 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:37 -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 13/20] mt76x0: unify temperature offset parsing Date: Thu, 20 Sep 2018 11:12:00 +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 Unify temperature offset parsing with mt76x2 driver using eeprom utility routines available in mt76x02-lib module Signed-off-by: Lorenzo Bianconi --- .../net/wireless/mediatek/mt76/mt76x0/debugfs.c | 3 ++- drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c | 14 +++++++------- drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h | 3 ++- drivers/net/wireless/mediatek/mt76/mt76x0/phy.c | 2 +- .../net/wireless/mediatek/mt76/mt76x02_eeprom.h | 1 + 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c index b6f467e7ee8c..d138ed3bda17 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c @@ -105,7 +105,8 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data) seq_printf(file, "RF freq offset: %hhx\n", dev->ee->rf_freq_off); seq_printf(file, "RSSI offset: %hhx %hhx\n", dev->caldata.rssi_offset[0], dev->caldata.rssi_offset[1]); - seq_printf(file, "Temperature offset: %hhx\n", dev->ee->temp_off); + seq_printf(file, "Temperature offset: %hhx\n", + dev->caldata.temp_offset); seq_printf(file, "LNA gain: %x\n", dev->caldata.lna_gain); val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_0); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index 6c24274d23f4..ae7c11519b0a 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -92,15 +92,15 @@ mt76x0_set_chip_cap(struct mt76x0_dev *dev, u8 *eeprom) "Error: device has more than 1 RX/TX stream!\n"); } -static void -mt76x0_set_temp_offset(struct mt76x0_dev *dev, u8 *eeprom) +static void mt76x0_set_temp_offset(struct mt76x0_dev *dev) { - u8 temp = eeprom[MT_EE_TEMP_OFFSET]; + u8 val; - if (mt76x02_field_valid(temp)) - dev->ee->temp_off = mt76x02_sign_extend(temp, 8); + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_2G_TARGET_POWER) >> 8; + if (mt76x02_field_valid(val)) + dev->caldata.temp_offset = mt76x02_sign_extend(val, 8); else - dev->ee->temp_off = -10; + dev->caldata.temp_offset = -10; } static void @@ -287,7 +287,7 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev) mt76x02_mac_setaddr(&dev->mt76, eeprom + MT_EE_MAC_ADDR); mt76x0_set_chip_cap(dev, eeprom); mt76x0_set_rf_freq_off(dev, eeprom); - mt76x0_set_temp_offset(dev, eeprom); + mt76x0_set_temp_offset(dev); dev->chainmask = 0x0101; mt76x0_set_tx_power_per_rate(dev, eeprom); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h index dd9cb0d2de41..55e624cf7f2a 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h @@ -31,11 +31,12 @@ struct reg_channel_bounds { struct mt76x0_caldata { s8 rssi_offset[2]; s8 lna_gain; + + s16 temp_offset; }; struct mt76x0_eeprom_params { u8 rf_freq_off; - s16 temp_off; /* TX_PWR_CFG_* values from EEPROM for 20 and 40 Mhz bandwidths. */ u32 tx_pwr_cfg_2g[5][2]; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index 72d0ddc381b9..dbe9e2ee5def 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -836,7 +836,7 @@ static void mt76x0_temp_sensor(struct mt76x0_dev *dev) else sval |= 0xffffff00; /* Negative */ - temp = (35 * (sval - dev->ee->temp_off))/ 10 + 25; + temp = (35 * (sval - dev->caldata.temp_offset)) / 10 + 25; done: rf_wr(dev, MT_RF(7, 73), rf_b7_73); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h index c22ca507b418..2132af9f8c94 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h @@ -72,6 +72,7 @@ enum mt76x02_eeprom_field { MT_EE_TX_POWER_VHT_MCS4 = 0x0bc, MT_EE_TX_POWER_VHT_MCS8 = 0x0be, + MT_EE_2G_TARGET_POWER = 0x0d0, MT_EE_TEMP_OFFSET = 0x0d1, MT_EE_FREQ_OFFSET_COMPENSATION = 0x0db, MT_EE_TX_POWER_BYRATE_BASE = 0x0de, From patchwork Thu Sep 20 09:12:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607193 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 F3D6C1508 for ; Thu, 20 Sep 2018 09:12:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E34EC2CC13 for ; Thu, 20 Sep 2018 09:12:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7A6D2CC43; Thu, 20 Sep 2018 09:12:43 +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 6D3B02CC26 for ; Thu, 20 Sep 2018 09:12:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387502AbeITOzK (ORCPT ); Thu, 20 Sep 2018 10:55:10 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:53758 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387433AbeITOzK (ORCPT ); Thu, 20 Sep 2018 10:55:10 -0400 Received: by mail-wm1-f65.google.com with SMTP id b19-v6so9132098wme.3 for ; Thu, 20 Sep 2018 02:12: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=qo7k4hwHwFwOYMUvB/PIIoVeigg2yZLY0qQdoaw2f2Y=; b=VnmlD509O0nh8ybsvIRm3yjB1lczRuidT4Ryxsci3xjtemnLNVKRXJN28wcNKqgAf+ gHUHCtU5MBOPVvzUFirU76oaV5NP6YcJJwU7UK+4xFZR3zfElgYQRi76HMsM9P6KHBYi iNs4onvk+G6S0qGIoAXVP7LBx9dUMYqkU/ZTYWUmLZ9EQwy3s/cgZ2AvQKZTiSN+OXpp 6ERkyYpOoqooasHoT3hPauolHBgmcE7U/awEJJ29haJVMjzIvTnuyz6ytvmROE8J353/ TlXm0xJtTov2NoF1C4Zztdszje9qdmLCsgRBbsTy/iPvUX3F0kDJI10l3uQbDdAqIZGa zJQQ== X-Gm-Message-State: APzg51Cqzc/b+82tHmnFEMUkgPyx+y8mpvSfeWaZKBM2eFeasmFVXDvI c0AIB9nwj4j0TqjZtxgk5PT95w== X-Google-Smtp-Source: ANB0VdZYURs3f0+5FS/RJTuRsy8bi2mqtsO+U9OCfbtw3Y+I9u+tKaKJS5g1hoNGY6irXXhelUd/1A== X-Received: by 2002:a1c:60d5:: with SMTP id u204-v6mr1603842wmb.88.1537434758655; Thu, 20 Sep 2018 02:12:38 -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.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:38 -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 14/20] mt76x0: unify freq offset parsing Date: Thu, 20 Sep 2018 11:12:01 +0200 Message-Id: <3a1d075efd810e114233f941b7b15b3c88955c8f.1537433365.git.lorenzo.bianconi@redhat.com> 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 Unify frequency offset parsing with mt76x2 driver using eeprom utility routines available in mt76x02-lib module Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/debugfs.c | 3 ++- .../wireless/mediatek/mt76/mt76x0/eeprom.c | 26 +++++++++---------- .../wireless/mediatek/mt76/mt76x0/eeprom.h | 3 +-- .../net/wireless/mediatek/mt76/mt76x0/phy.c | 3 ++- .../wireless/mediatek/mt76/mt76x02_eeprom.h | 5 ++++ 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c index d138ed3bda17..39c2c846f808 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c @@ -102,7 +102,8 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data) u16 val; int i; - seq_printf(file, "RF freq offset: %hhx\n", dev->ee->rf_freq_off); + seq_printf(file, "RF freq offset: %hhx\n", + dev->caldata.freq_offset); seq_printf(file, "RSSI offset: %hhx %hhx\n", dev->caldata.rssi_offset[0], dev->caldata.rssi_offset[1]); seq_printf(file, "Temperature offset: %hhx\n", diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index ae7c11519b0a..70dd96051e77 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -103,23 +103,21 @@ static void mt76x0_set_temp_offset(struct mt76x0_dev *dev) dev->caldata.temp_offset = -10; } -static void -mt76x0_set_rf_freq_off(struct mt76x0_dev *dev, u8 *eeprom) +static void mt76x0_set_freq_offset(struct mt76x0_dev *dev) { - u8 comp; + struct mt76x0_caldata *caldata = &dev->caldata; + u8 val; - comp = eeprom[MT_EE_FREQ_OFFSET_COMPENSATION]; - if (!mt76x02_field_valid(comp)) - comp = 0; + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_FREQ_OFFSET); + if (!mt76x02_field_valid(val)) + val = 0; + caldata->freq_offset = val; - 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; + val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TSSI_BOUND4) >> 8; + if (!mt76x02_field_valid(val)) + val = 0; - if (comp & BIT(7)) - dev->ee->rf_freq_off -= comp & 0x7f; - else - dev->ee->rf_freq_off += comp; + caldata->freq_offset -= mt76x02_sign_extend(val, 8); } void mt76x0_read_rx_gain(struct mt76x0_dev *dev) @@ -286,7 +284,7 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev) mt76x02_mac_setaddr(&dev->mt76, eeprom + MT_EE_MAC_ADDR); mt76x0_set_chip_cap(dev, eeprom); - mt76x0_set_rf_freq_off(dev, eeprom); + mt76x0_set_freq_offset(dev); mt76x0_set_temp_offset(dev); dev->chainmask = 0x0101; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h index 55e624cf7f2a..8006d08cba45 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h @@ -33,11 +33,10 @@ struct mt76x0_caldata { s8 lna_gain; s16 temp_offset; + u8 freq_offset; }; struct mt76x0_eeprom_params { - u8 rf_freq_off; - /* TX_PWR_CFG_* values from EEPROM for 20 and 40 Mhz bandwidths. */ u32 tx_pwr_cfg_2g[5][2]; u32 tx_pwr_cfg_5g[5][2]; diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index dbe9e2ee5def..c3db4c1cd4fe 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -942,7 +942,8 @@ mt76x0_rf_init(struct mt76x0_dev *dev) E1: B0.R22<6:0>: xo_cxo<6:0> E2: B0.R21<0>: xo_cxo<0>, B0.R22<7:0>: xo_cxo<8:1> */ - rf_wr(dev, MT_RF(0, 22), min_t(u8, dev->ee->rf_freq_off, 0xBF)); + rf_wr(dev, MT_RF(0, 22), + min_t(u8, dev->caldata.freq_offset, 0xbf)); val = rf_rr(dev, MT_RF(0, 22)); /* diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h index 2132af9f8c94..995aebbcc194 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h @@ -74,7 +74,12 @@ enum mt76x02_eeprom_field { MT_EE_2G_TARGET_POWER = 0x0d0, MT_EE_TEMP_OFFSET = 0x0d1, + MT_EE_TSSI_BOUND1 = 0x0d4, + MT_EE_TSSI_BOUND2 = 0x0d6, + MT_EE_TSSI_BOUND3 = 0x0d8, + MT_EE_TSSI_BOUND4 = 0x0da, MT_EE_FREQ_OFFSET_COMPENSATION = 0x0db, + MT_EE_TSSI_BOUND5 = 0x0dc, MT_EE_TX_POWER_BYRATE_BASE = 0x0de, MT_EE_RF_TEMP_COMP_SLOPE_5G = 0x0f2, From patchwork Thu Sep 20 09:12:02 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607195 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 D4E3E1390 for ; Thu, 20 Sep 2018 09:12:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C23822CC13 for ; Thu, 20 Sep 2018 09:12:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B6DAC2CC43; Thu, 20 Sep 2018 09:12:44 +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 3F5042CC13 for ; Thu, 20 Sep 2018 09:12:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387511AbeITOzL (ORCPT ); Thu, 20 Sep 2018 10:55:11 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:34197 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387441AbeITOzK (ORCPT ); Thu, 20 Sep 2018 10:55:10 -0400 Received: by mail-wm1-f65.google.com with SMTP id j25-v6so978445wmc.1 for ; Thu, 20 Sep 2018 02:12:40 -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=7KpDwG+vWE84QFfJYnuonNhTtb3mxZ77JJEnfef+qdw=; b=FPPDpgNikBlS3mg8ptiWBmDkP/LsGP4kRj8gsGm7Tx9Vr+WwKNmFOkBjzNO+9q4yvc SZc1KTwY+lGuOuGualge0woX+TfXoazAF4tD5T6V++DpE/17HrgjhangKn0pfCqa1WhW qANf6ZMUJFNPUwbJ/lT3Jm4jlOwB4o83+jGUGsfVnImyLr2tRhOtvdSVdIwSwIVFdVWd gh+Q2YOxfGYWjG5WjKxLW4uOQOja/G753yiM10R6IZAy4zRYlCQE2YVXtEtMc+MDjFIJ BCGwQuRSFkmrbMNTIaa/rmFoHDywzk8zeIvgnYohO/nWrpTV59kEq/Re5AeTZT/kS87U c3GA== X-Gm-Message-State: APzg51D7gg618OaN9YVHRfe8084vXfrlmvXnPrjC3aNilvlz0qrGDJfy KX2QE6SEKIktqVDaUlf7m5BJQA== X-Google-Smtp-Source: ANB0VdYTHDstPTwVg0GEDszlRbEeV5W/8OLoBDz2PFDor3VM9+Y4XiuPh57i0C1EC03WyOLpGt2+mw== X-Received: by 2002:a1c:c501:: with SMTP id v1-v6mr1601869wmf.115.1537434759907; Thu, 20 Sep 2018 02:12: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 34-v6sm35501691wra.20.2018.09.20.02.12.38 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:39 -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 15/20] mt76: move mt76x02_eeprom_parse_hw_cap in mt76x02-lib module Date: Thu, 20 Sep 2018 11:12:02 +0200 Message-Id: <47b4bab5725f91f5c689fb079912a5435971eb62.1537433365.git.lorenzo.bianconi@redhat.com> 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 mt76x02_eeprom_parse_hw_cap utility routine in mt76x02-lib module in order to be reused in mt76x0 driver Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x02_eeprom.c | 19 +++++++++++++++++ .../wireless/mediatek/mt76/mt76x02_eeprom.h | 6 ++++++ .../wireless/mediatek/mt76/mt76x2_eeprom.c | 21 +------------------ .../wireless/mediatek/mt76/mt76x2_eeprom.h | 6 ------ .../net/wireless/mediatek/mt76/mt76x2u_init.c | 2 +- 5 files changed, 27 insertions(+), 27 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c index 2377c758da5d..d3efeb8a72b7 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.c @@ -71,6 +71,25 @@ int mt76x02_get_efuse_data(struct mt76_dev *dev, u16 base, void *buf, } EXPORT_SYMBOL_GPL(mt76x02_get_efuse_data); +void mt76x02_eeprom_parse_hw_cap(struct mt76_dev *dev) +{ + u16 val = mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_0); + + switch (FIELD_GET(MT_EE_NIC_CONF_0_BOARD_TYPE, val)) { + case BOARD_TYPE_5GHZ: + dev->cap.has_5ghz = true; + break; + case BOARD_TYPE_2GHZ: + dev->cap.has_2ghz = true; + break; + default: + dev->cap.has_2ghz = true; + dev->cap.has_5ghz = true; + break; + } +} +EXPORT_SYMBOL_GPL(mt76x02_eeprom_parse_hw_cap); + bool mt76x02_ext_pa_enabled(struct mt76_dev *dev, enum nl80211_band band) { u16 conf0 = mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_0); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h index 995aebbcc194..119813960fe7 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h @@ -132,6 +132,11 @@ enum mt76x02_eeprom_modes { MT_EE_PHYSICAL_READ, }; +enum mt76x02_board_type { + BOARD_TYPE_2GHZ = 1, + BOARD_TYPE_5GHZ = 2, +}; + static inline bool mt76x02_field_valid(u8 val) { return val != 0 && val != 0xff; @@ -165,5 +170,6 @@ void mt76x02_get_rx_gain(struct mt76_dev *dev, enum nl80211_band band, u8 mt76x02_get_lna_gain(struct mt76_dev *dev, s8 *lna_2g, s8 *lna_5g, struct ieee80211_channel *chan); +void mt76x02_eeprom_parse_hw_cap(struct mt76_dev *dev); #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 b9641e2408ee..d295851cf2f9 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c @@ -40,25 +40,6 @@ mt76x2_eeprom_get_macaddr(struct mt76x2_dev *dev) return 0; } -void mt76x2_eeprom_parse_hw_cap(struct mt76x2_dev *dev) -{ - u16 val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_0); - - switch (FIELD_GET(MT_EE_NIC_CONF_0_BOARD_TYPE, val)) { - case BOARD_TYPE_5GHZ: - dev->mt76.cap.has_5ghz = true; - break; - case BOARD_TYPE_2GHZ: - dev->mt76.cap.has_2ghz = true; - break; - default: - dev->mt76.cap.has_2ghz = true; - dev->mt76.cap.has_5ghz = true; - break; - } -} -EXPORT_SYMBOL_GPL(mt76x2_eeprom_parse_hw_cap); - static bool mt76x2_has_cal_free_data(struct mt76x2_dev *dev, u8 *efuse) { @@ -563,7 +544,7 @@ int mt76x2_eeprom_init(struct mt76x2_dev *dev) if (ret) return ret; - mt76x2_eeprom_parse_hw_cap(dev); + mt76x02_eeprom_parse_hw_cap(&dev->mt76); mt76x2_eeprom_get_macaddr(dev); mt76_eeprom_override(&dev->mt76); dev->mt76.macaddr[0] &= ~BIT(1); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h index da476aad65fb..ad98a52ec69f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h @@ -19,11 +19,6 @@ #include "mt76x02_eeprom.h" -enum mt76x2_board_type { - BOARD_TYPE_2GHZ = 1, - BOARD_TYPE_5GHZ = 2, -}; - enum mt76x2_cal_channel_group { MT_CH_5G_JAPAN, MT_CH_5G_UNII_1, @@ -64,7 +59,6 @@ void mt76x2_get_power_info(struct mt76x2_dev *dev, struct ieee80211_channel *chan); int mt76x2_get_temp_comp(struct mt76x2_dev *dev, struct mt76x2_temp_comp *t); void mt76x2_read_rx_gain(struct mt76x2_dev *dev); -void mt76x2_eeprom_parse_hw_cap(struct mt76x2_dev *dev); static inline bool mt76x2_temp_tx_alc_enabled(struct mt76x2_dev *dev) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2u_init.c b/drivers/net/wireless/mediatek/mt76/mt76x2u_init.c index 89cfacfb276c..7a9ebc8985f2 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2u_init.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2u_init.c @@ -129,7 +129,7 @@ static int mt76x2u_init_eeprom(struct mt76x2_dev *dev) put_unaligned_le32(val, dev->mt76.eeprom.data + i); } - mt76x2_eeprom_parse_hw_cap(dev); + mt76x02_eeprom_parse_hw_cap(&dev->mt76); return 0; } From patchwork Thu Sep 20 09:12:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607191 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 C51A86CB for ; Thu, 20 Sep 2018 09:12:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B37BF2CC13 for ; Thu, 20 Sep 2018 09:12:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A798D2CC70; Thu, 20 Sep 2018 09:12:43 +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 4CB792CC13 for ; Thu, 20 Sep 2018 09:12:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387507AbeITOzL (ORCPT ); Thu, 20 Sep 2018 10:55:11 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36438 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387496AbeITOzK (ORCPT ); Thu, 20 Sep 2018 10:55:10 -0400 Received: by mail-wr1-f68.google.com with SMTP id e1-v6so8601585wrt.3 for ; Thu, 20 Sep 2018 02:12:41 -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=0kU0C8Nhicf7sIvQrWYxoE3jPGvMrT4w6oq8fTSSyIM=; b=MqPCHV9+wWiUgv3UqQV2xFxrFD0/7tPID/ZnvmTts2sJq8WEN/0srTbRKfmBbmYBnH 4fjw9wYypdg2acd/FinfyKYUWC9OJDyHb/4n+VClb12F+YLTkhgu70C10J2qVmmfvoec mYuH58q76+bo+ytEQJrZNHTNNnXA8wAPTtlyXisOFUUJA4TiiyqYMEQYi59+JD1CkEFh MpRl6Wy7y5uhqEVG+smt9GIqK2wvlSPb90iJaFc5/btm1vOD2mvKsj+FO7I9m9rP3+QW rd2FT3RuIkeORuSE4gtJWChmhbJhRXcNEtYojheZ+ElATQE80t1TYjEepZDqN3421e8K MJBw== X-Gm-Message-State: APzg51Cb5ugCY8lFIgdr03c8EVDboJjt8Vu5JPMQKmc77GRAaiFHwvLZ XKXN5GrwYKD/a82rjb1oXX8hgA== X-Google-Smtp-Source: ANB0VdacWWHyevzcubtSte2ozcPHgQUDdys5/xNTxwHdazDQF1N03HKfe+AogcqAi1USyzS3d1wsjw== X-Received: by 2002:a5d:528f:: with SMTP id c15-v6mr32913915wrv.102.1537434761014; Thu, 20 Sep 2018 02:12:41 -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.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:40 -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 16/20] mt76x0: unify parse hw capabilities Date: Thu, 20 Sep 2018 11:12:03 +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 Unify parse hw capabilities with mt76x2 driver using mt76x02_eeprom_parse_hw_cap utility routine available in mt76x02-lib module Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/eeprom.c | 33 +++++-------------- 1 file changed, 8 insertions(+), 25 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index 70dd96051e77..f9d917a7f3f5 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -51,29 +51,13 @@ mt76x0_efuse_physical_size_check(struct mt76x0_dev *dev) return 0; } -static void -mt76x0_set_chip_cap(struct mt76x0_dev *dev, u8 *eeprom) +static void mt76x0_set_chip_cap(struct mt76x0_dev *dev) { - enum mt76x2_board_type { BOARD_TYPE_2GHZ = 1, BOARD_TYPE_5GHZ = 2 }; - u16 nic_conf0 = get_unaligned_le16(eeprom + MT_EE_NIC_CONF_0); - u16 nic_conf1 = get_unaligned_le16(eeprom + MT_EE_NIC_CONF_1); - - dev_dbg(dev->mt76.dev, "NIC_CONF0: %04x NIC_CONF1: %04x\n", nic_conf0, nic_conf1); - - switch (FIELD_GET(MT_EE_NIC_CONF_0_BOARD_TYPE, nic_conf0)) { - case BOARD_TYPE_5GHZ: - dev->mt76.cap.has_5ghz = true; - break; - case BOARD_TYPE_2GHZ: - dev->mt76.cap.has_2ghz = true; - break; - default: - dev->mt76.cap.has_2ghz = true; - dev->mt76.cap.has_5ghz = true; - break; - } + u16 nic_conf0 = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_0); + u16 nic_conf1 = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_1); - dev_dbg(dev->mt76.dev, "Has 2GHZ %d 5GHZ %d\n", + mt76x02_eeprom_parse_hw_cap(&dev->mt76); + dev_dbg(dev->mt76.dev, "2GHz %d 5GHz %d\n", dev->mt76.cap.has_2ghz, dev->mt76.cap.has_5ghz); if (!mt76x02_field_valid(nic_conf1 & 0xff)) @@ -81,15 +65,14 @@ mt76x0_set_chip_cap(struct mt76x0_dev *dev, u8 *eeprom) 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"); + "driver does not support HW RF ctrl\n"); if (!mt76x02_field_valid(nic_conf0 >> 8)) return; if (FIELD_GET(MT_EE_NIC_CONF_0_RX_PATH, nic_conf0) > 1 || FIELD_GET(MT_EE_NIC_CONF_0_TX_PATH, nic_conf0) > 1) - dev_err(dev->mt76.dev, - "Error: device has more than 1 RX/TX stream!\n"); + dev_err(dev->mt76.dev, "invalid tx-rx stream\n"); } static void mt76x0_set_temp_offset(struct mt76x0_dev *dev) @@ -283,7 +266,7 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev) eeprom[MT_EE_VERSION + 1], eeprom[MT_EE_VERSION]); mt76x02_mac_setaddr(&dev->mt76, eeprom + MT_EE_MAC_ADDR); - mt76x0_set_chip_cap(dev, eeprom); + mt76x0_set_chip_cap(dev); mt76x0_set_freq_offset(dev); mt76x0_set_temp_offset(dev); dev->chainmask = 0x0101; From patchwork Thu Sep 20 09:12:04 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607197 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 8589E6CB for ; Thu, 20 Sep 2018 09:12:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 756D32CC13 for ; Thu, 20 Sep 2018 09:12:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 69C9E2CC43; Thu, 20 Sep 2018 09:12:46 +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 EF5952CC13 for ; Thu, 20 Sep 2018 09:12:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387519AbeITOzN (ORCPT ); Thu, 20 Sep 2018 10:55:13 -0400 Received: from mail-wm1-f68.google.com ([209.85.128.68]:37811 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387433AbeITOzM (ORCPT ); Thu, 20 Sep 2018 10:55:12 -0400 Received: by mail-wm1-f68.google.com with SMTP id n11-v6so10014957wmc.2 for ; Thu, 20 Sep 2018 02:12:42 -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=vuFTv6Z/gVltTgGVz4g7Vc02rw0v8o+mwmyzPfTpoPw=; b=khwloalXxmkbAGuS3zkeycCVLbSqFep7ZtGOBVhb9+WJttrUYdXS9DJuVP5YacRLl3 CYRx3LlBD3kNnFdMEBdMlXBDLumV/1/6mIRnZPfR9NiskBe3eVVg+NLGTGRV5h9QQV+G 32hH+hR/kAGJhSVoi8O/NdUEUabLGl5kAfClNMarCQ3PUpJQ0Nsot6tXM1ISG7Rcg3he pMh21LQSqKaDcqv/ZsOjVaTC5KzFxfdNwxmAb4+7PhjY10pJn4fqsVBtVg5OaKtgBrzv MS0NKKoTr7G53YI0tx2DjJ4i+eeOQ4L0uqRjJsXkIJZnd6QQE2xdMsN1AF5aFe3Yc6av Kx6A== X-Gm-Message-State: APzg51DNUgeTyQiKYsQ1dUvjFY/S0WmlTKb79qj31IGjo7S+7kzojamm grZokPdXZ2Be9UC0LDtUcbL2vA== X-Google-Smtp-Source: ANB0VdbiDz50DtNhgsdUUpkhsCRmaMGx+V0xa3FBWBs0CcHhky3kRnDk+XhvTqIRQ15Qt8MnZy/sUQ== X-Received: by 2002:a1c:a8d0:: with SMTP id r199-v6mr1561968wme.97.1537434762256; Thu, 20 Sep 2018 02:12:42 -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.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:41 -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 17/20] mt76: move mt76x2_tssi_enabled in mt76x02_eeprom.h Date: Thu, 20 Sep 2018 11:12:04 +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 mt76x2_tssi_enabled and mt76x02_temp_tx_alc_enabled in mt76x02_eeprom.h in order to be reused in mt76x0 driver Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x02_eeprom.h | 21 +++++++++++++++++++ .../wireless/mediatek/mt76/mt76x2_eeprom.c | 4 ++-- .../wireless/mediatek/mt76/mt76x2_eeprom.h | 21 ------------------- .../net/wireless/mediatek/mt76/mt76x2_phy.c | 4 ++-- .../net/wireless/mediatek/mt76/mt76x2u_phy.c | 2 +- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h index 119813960fe7..9339514fb073 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h @@ -162,6 +162,27 @@ mt76x02_eeprom_get(struct mt76_dev *dev, return get_unaligned_le16(dev->eeprom.data + field); } +static inline bool +mt76x02_temp_tx_alc_enabled(struct mt76_dev *dev) +{ + u16 val; + + val = mt76x02_eeprom_get(dev, MT_EE_TX_POWER_EXT_PA_5G); + if (!(val & BIT(15))) + return false; + + return mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1) & + MT_EE_NIC_CONF_1_TEMP_TX_ALC; +} + +static inline bool +mt76x02_tssi_enabled(struct mt76_dev *dev) +{ + return !mt76x02_temp_tx_alc_enabled(dev) && + (mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1) & + MT_EE_NIC_CONF_1_TX_ALC_EN); +} + bool mt76x02_ext_pa_enabled(struct mt76_dev *dev, enum nl80211_band band); int mt76x02_get_efuse_data(struct mt76_dev *dev, u16 base, void *buf, int len, enum mt76x02_eeprom_modes mode); diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c index d295851cf2f9..21b8fb2e0e28 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.c @@ -490,7 +490,7 @@ void mt76x2_get_power_info(struct mt76x2_dev *dev, MT_EE_TX_POWER_1_START_2G); } - if (mt76x2_tssi_enabled(dev) || + if (mt76x02_tssi_enabled(&dev->mt76) || !mt76x02_field_valid(t->target_power)) t->target_power = t->chain[0].target_power; @@ -507,7 +507,7 @@ int mt76x2_get_temp_comp(struct mt76x2_dev *dev, struct mt76x2_temp_comp *t) memset(t, 0, sizeof(*t)); - if (!mt76x2_temp_tx_alc_enabled(dev)) + if (!mt76x02_temp_tx_alc_enabled(&dev->mt76)) return -EINVAL; if (!mt76x02_ext_pa_enabled(&dev->mt76, band)) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h index ad98a52ec69f..650f9564f0f4 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_eeprom.h @@ -60,27 +60,6 @@ void mt76x2_get_power_info(struct mt76x2_dev *dev, int mt76x2_get_temp_comp(struct mt76x2_dev *dev, struct mt76x2_temp_comp *t); void mt76x2_read_rx_gain(struct mt76x2_dev *dev); -static inline bool -mt76x2_temp_tx_alc_enabled(struct mt76x2_dev *dev) -{ - u16 val; - - val = mt76x02_eeprom_get(&dev->mt76, MT_EE_TX_POWER_EXT_PA_5G); - if (!(val & BIT(15))) - return false; - - return mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_1) & - MT_EE_NIC_CONF_1_TEMP_TX_ALC; -} - -static inline bool -mt76x2_tssi_enabled(struct mt76x2_dev *dev) -{ - return !mt76x2_temp_tx_alc_enabled(dev) && - (mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_1) & - MT_EE_NIC_CONF_1_TX_ALC_EN); -} - static inline bool mt76x2_has_ext_lna(struct mt76x2_dev *dev) { diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x2_phy.c index 3f786596e586..22e66006a5f8 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2_phy.c @@ -25,7 +25,7 @@ mt76x2_phy_tssi_init_cal(struct mt76x2_dev *dev) struct ieee80211_channel *chan = dev->mt76.chandef.chan; u32 flag = 0; - if (!mt76x2_tssi_enabled(dev)) + if (!mt76x02_tssi_enabled(&dev->mt76)) return false; if (mt76x2_channel_silent(dev)) @@ -390,7 +390,7 @@ int mt76x2_phy_set_channel(struct mt76x2_dev *dev, sizeof(dev->cal.agc_gain_cur)); /* init default values for temp compensation */ - if (mt76x2_tssi_enabled(dev)) { + if (mt76x02_tssi_enabled(&dev->mt76)) { mt76_rmw_field(dev, MT_TX_ALC_CFG_1, MT_TX_ALC_CFG_1_TEMP_COMP, 0x38); mt76_rmw_field(dev, MT_TX_ALC_CFG_2, MT_TX_ALC_CFG_2_TEMP_COMP, diff --git a/drivers/net/wireless/mediatek/mt76/mt76x2u_phy.c b/drivers/net/wireless/mediatek/mt76/mt76x2u_phy.c index 1cd9b2468ef0..b3ec56d35e7f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x2u_phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x2u_phy.c @@ -235,7 +235,7 @@ int mt76x2u_phy_set_channel(struct mt76x2_dev *dev, if (scan) return 0; - if (mt76x2_tssi_enabled(dev)) { + if (mt76x02_tssi_enabled(&dev->mt76)) { /* init default values for temp compensation */ mt76_rmw_field(dev, MT_TX_ALC_CFG_1, MT_TX_ALC_CFG_1_TEMP_COMP, 0x38); From patchwork Thu Sep 20 09:12:05 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607203 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 5B50C1390 for ; Thu, 20 Sep 2018 09:12:50 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B9D32CBE7 for ; Thu, 20 Sep 2018 09:12:50 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 404892CC26; Thu, 20 Sep 2018 09:12:50 +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 70B442CBE7 for ; Thu, 20 Sep 2018 09:12:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731305AbeITOzQ (ORCPT ); Thu, 20 Sep 2018 10:55:16 -0400 Received: from mail-wm1-f67.google.com ([209.85.128.67]:39019 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387441AbeITOzP (ORCPT ); Thu, 20 Sep 2018 10:55:15 -0400 Received: by mail-wm1-f67.google.com with SMTP id q8-v6so10069941wmq.4 for ; Thu, 20 Sep 2018 02:12:44 -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=IJ/oGSKytm8qujUyWhwLMUPsyGrE7MS2gSZ2bSUeNwI=; b=MlS8o78NgbHVZJ7zRwjNPvRv59qOAaKI6XL7fIhleKaVQtq89iAVRgpFTK+BZmDRZH ldps4VsEjux5YAtA2n6ICcjt0fSkeDuO7xE77Wz1mNCDns+h9Bpz3kANVKXj6uJY4qp/ pJpUXK2AXu/GLfusyB026yOxRMQNOOVyFM8pjdSvsC/gnaOh7r7mB6E/gtwYsTDT8IrE 4d9g6VGzI81MR4ro0+0o578YsfFgwUzVY/d9tNWgKl047Uw9xR1XUJTnjHA8XFGlc84Q 8wld6vFxZZ0BBnfBZ90AxmzDULqlH6bbUd9CCAGXKNVnZazLRU8L0d2LY3z3maj9uYV3 LjUw== X-Gm-Message-State: APzg51DnkF+2WZTPmaBY3YTVs7nVSJ2DGUCduhQucXLUzX7GwqBqPaQQ Db4Wr+JgW0YNj7z/3bwWhHIZNA== X-Google-Smtp-Source: ANB0VdbedbiLL111H8elHRxd4de1sfcZlCYRZh62fSppUhyejgfyJ6TAKSrSalHrCjeBTWjp7oFWOA== X-Received: by 2002:a1c:7dc7:: with SMTP id y190-v6mr1553915wmc.62.1537434763512; Thu, 20 Sep 2018 02:12:43 -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.42 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:42 -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 18/20] mt76x0: remove eeprom dependency from mt76x0_set_tx_power_per_rate Date: Thu, 20 Sep 2018 11:12:05 +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 In order to unify eeprom parsing between mt76x0 and mt76x2 drivers, remove eeprom pointer dependency from mt76x0_set_tx_power_per_rate. Moreover use mt76_rate_power to store power vs rate calibration data. Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/debugfs.c | 32 ++-- .../wireless/mediatek/mt76/mt76x0/eeprom.c | 144 ++++++++++-------- .../wireless/mediatek/mt76/mt76x0/eeprom.h | 25 ++- .../net/wireless/mediatek/mt76/mt76x0/phy.c | 16 +- .../wireless/mediatek/mt76/mt76x02_eeprom.h | 4 +- 5 files changed, 117 insertions(+), 104 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c index 39c2c846f808..46327cc90797 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c @@ -118,19 +118,6 @@ mt76x0_eeprom_param_read(struct seq_file *file, void *data) for (i = 0; i < 58; i++) seq_printf(file, "\t%d chan:%d pwr:%d\n", i, i, dev->ee->tx_pwr_per_chan[i]); - - seq_puts(file, "Per rate power 2GHz:\n"); - for (i = 0; i < 5; i++) - seq_printf(file, "\t %d bw20:%d bw40:%d\n", - i, dev->ee->tx_pwr_cfg_2g[i][0], - dev->ee->tx_pwr_cfg_5g[i][1]); - - seq_puts(file, "Per rate power 5GHz:\n"); - for (i = 0; i < 5; i++) - seq_printf(file, "\t %d bw20:%d bw40:%d\n", - i, dev->ee->tx_pwr_cfg_5g[i][0], - dev->ee->tx_pwr_cfg_5g[i][1]); - return 0; } @@ -147,6 +134,23 @@ static const struct file_operations fops_eeprom_param = { .release = single_release, }; +static int mt76x0_read_txpower(struct seq_file *file, void *data) +{ + struct mt76x0_dev *dev = dev_get_drvdata(file->private); + + mt76_seq_puts_array(file, "CCK", dev->caldata.rate_power.cck, + ARRAY_SIZE(dev->caldata.rate_power.cck)); + mt76_seq_puts_array(file, "OFDM", dev->caldata.rate_power.ofdm, + ARRAY_SIZE(dev->caldata.rate_power.ofdm)); + mt76_seq_puts_array(file, "STBC", dev->caldata.rate_power.stbc, + ARRAY_SIZE(dev->caldata.rate_power.stbc)); + mt76_seq_puts_array(file, "HT", dev->caldata.rate_power.ht, + ARRAY_SIZE(dev->caldata.rate_power.ht)); + mt76_seq_puts_array(file, "VHT", dev->caldata.rate_power.vht, + ARRAY_SIZE(dev->caldata.rate_power.vht)); + return 0; +} + void mt76x0_init_debugfs(struct mt76x0_dev *dev) { struct dentry *dir; @@ -161,4 +165,6 @@ void mt76x0_init_debugfs(struct mt76x0_dev *dev) debugfs_create_file("ampdu_stat", S_IRUSR, dir, dev, &fops_ampdu_stat); debugfs_create_file("eeprom_param", S_IRUSR, dir, dev, &fops_eeprom_param); + debugfs_create_devm_seqfile(dev->mt76.dev, "txpower", dir, + mt76x0_read_txpower); } diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c index f9d917a7f3f5..1406e88141de 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.c @@ -125,82 +125,103 @@ void mt76x0_read_rx_gain(struct mt76x0_dev *dev) } } -static u32 -calc_bw40_power_rate(u32 value, int delta) +static s8 mt76x0_get_power_rate(u8 val, s8 delta) { - u32 ret = 0; - int i, tmp; - - for (i = 0; i < 4; i++) { - tmp = s6_to_int((value >> i*8) & 0xff) + delta; - ret |= (u32)(int_to_s6(tmp)) << i*8; - } - - return ret; + return s6_to_s8(val) + delta; } -static s8 -get_delta(u8 val) +static s8 mt76x0_get_delta(struct mt76_dev *dev, + struct cfg80211_chan_def *chandef) { + u8 val; s8 ret; + if (mt76x02_tssi_enabled(dev)) + return 0; + + if (chandef->width == NL80211_CHAN_WIDTH_80) { + val = mt76x02_eeprom_get(dev, MT_EE_5G_TARGET_POWER) >> 8; + } else if (chandef->width == NL80211_CHAN_WIDTH_40) { + u16 data; + + data = mt76x02_eeprom_get(dev, MT_EE_TX_POWER_DELTA_BW40); + if (chandef->chan->band == NL80211_BAND_5GHZ) + val = data >> 8; + else + val = data; + } else { + return 0; + } + if (!mt76x02_field_valid(val) || !(val & BIT(7))) return 0; ret = val & 0x1f; if (ret > 8) - ret = 8; - if (val & BIT(6)) - ret = -ret; + return 8; - return ret; + return (val & BIT(6)) ? -ret : ret; } -static void -mt76x0_set_tx_power_per_rate(struct mt76x0_dev *dev, u8 *eeprom) +void mt76x0_set_tx_power_per_rate(struct mt76x0_dev *dev, + struct cfg80211_chan_def *chandef) { - s8 bw40_delta_2g, bw40_delta_5g; - u32 val; - int i; - - bw40_delta_2g = get_delta(eeprom[MT_EE_TX_POWER_DELTA_BW40]); - bw40_delta_5g = get_delta(eeprom[MT_EE_TX_POWER_DELTA_BW40 + 1]); - - for (i = 0; i < 5; i++) { - val = get_unaligned_le32(eeprom + MT_EE_TX_POWER_BYRATE(i)); - - /* Skip last 16 bits. */ - if (i == 4) - val &= 0x0000ffff; - - dev->ee->tx_pwr_cfg_2g[i][0] = val; - dev->ee->tx_pwr_cfg_2g[i][1] = calc_bw40_power_rate(val, bw40_delta_2g); - } - - /* Reading per rate tx power for 5 GHz band is a bit more complex. Note - * we mix 16 bit and 32 bit reads and sometimes do shifts. - */ - val = get_unaligned_le16(eeprom + 0x120); - val <<= 16; - dev->ee->tx_pwr_cfg_5g[0][0] = val; - dev->ee->tx_pwr_cfg_5g[0][1] = calc_bw40_power_rate(val, bw40_delta_5g); - - val = get_unaligned_le32(eeprom + 0x122); - dev->ee->tx_pwr_cfg_5g[1][0] = val; - dev->ee->tx_pwr_cfg_5g[1][1] = calc_bw40_power_rate(val, bw40_delta_5g); - - val = get_unaligned_le16(eeprom + 0x126); - dev->ee->tx_pwr_cfg_5g[2][0] = val; - dev->ee->tx_pwr_cfg_5g[2][1] = calc_bw40_power_rate(val, bw40_delta_5g); - - val = get_unaligned_le16(eeprom + 0xec); - val <<= 16; - dev->ee->tx_pwr_cfg_5g[3][0] = val; - dev->ee->tx_pwr_cfg_5g[3][1] = calc_bw40_power_rate(val, bw40_delta_5g); - - val = get_unaligned_le16(eeprom + 0xee); - dev->ee->tx_pwr_cfg_5g[4][0] = val; - dev->ee->tx_pwr_cfg_5g[4][1] = calc_bw40_power_rate(val, bw40_delta_5g); + bool is_2ghz = chandef->chan->band == NL80211_BAND_2GHZ; + s8 data, delta = mt76x0_get_delta(&dev->mt76, chandef); + struct mt76_rate_power *t = &dev->caldata.rate_power; + struct mt76_dev *mdev = &dev->mt76; + u16 val, addr; + + memset(t, 0, sizeof(*t)); + + /* cck 1M, 2M, 5.5M, 11M */ + val = mt76x02_eeprom_get(mdev, MT_EE_TX_POWER_BYRATE_BASE); + t->cck[0] = t->cck[1] = mt76x0_get_power_rate(val, delta); + t->cck[2] = t->cck[3] = mt76x0_get_power_rate(val >> 8, delta); + + /* ofdm 6M, 9M, 12M, 18M */ + addr = is_2ghz ? MT_EE_TX_POWER_BYRATE_BASE + 2 : 0x120; + val = mt76x02_eeprom_get(mdev, addr); + t->ofdm[0] = t->ofdm[1] = mt76x0_get_power_rate(val, delta); + t->ofdm[2] = t->ofdm[3] = mt76x0_get_power_rate(val >> 8, delta); + + /* ofdm 24M, 36M, 48M, 54M */ + addr = is_2ghz ? MT_EE_TX_POWER_BYRATE_BASE + 4 : 0x122; + val = mt76x02_eeprom_get(mdev, addr); + t->ofdm[4] = t->ofdm[5] = mt76x0_get_power_rate(val, delta); + t->ofdm[6] = t->ofdm[7] = mt76x0_get_power_rate(val >> 8, delta); + + /* ht-vht mcs 1ss 0, 1, 2, 3 */ + addr = is_2ghz ? MT_EE_TX_POWER_BYRATE_BASE + 6 : 0x124; + val = mt76x02_eeprom_get(mdev, addr); + data = mt76x0_get_power_rate(val, delta); + t->ht[0] = t->ht[1] = t->vht[0] = t->vht[1] = data; + data = mt76x0_get_power_rate(val >> 8, delta); + t->ht[2] = t->ht[3] = t->vht[2] = t->vht[3] = data; + + /* ht-vht mcs 1ss 4, 5, 6 */ + addr = is_2ghz ? MT_EE_TX_POWER_BYRATE_BASE + 8 : 0x126; + val = mt76x02_eeprom_get(mdev, addr); + data = mt76x0_get_power_rate(val, delta); + t->ht[4] = t->ht[5] = t->vht[4] = t->vht[5] = data; + t->ht[6] = t->vht[6] = mt76x0_get_power_rate(val >> 8, delta); + + /* ht-vht mcs 1ss 0, 1, 2, 3 stbc */ + addr = is_2ghz ? MT_EE_TX_POWER_BYRATE_BASE + 14 : 0xec; + val = mt76x02_eeprom_get(mdev, addr); + t->stbc[0] = t->stbc[1] = mt76x0_get_power_rate(val, delta); + t->stbc[2] = t->stbc[3] = mt76x0_get_power_rate(val >> 8, delta); + + /* ht-vht mcs 1ss 4, 5, 6 stbc */ + addr = is_2ghz ? MT_EE_TX_POWER_BYRATE_BASE + 16 : 0xee; + val = mt76x02_eeprom_get(mdev, addr); + t->stbc[4] = t->stbc[5] = mt76x0_get_power_rate(val, delta); + t->stbc[6] = t->stbc[7] = mt76x0_get_power_rate(val >> 8, delta); + + /* vht mcs 8, 9 5GHz */ + val = mt76x02_eeprom_get(mdev, 0x132); + t->vht[7] = mt76x0_get_power_rate(val, delta); + t->vht[8] = mt76x0_get_power_rate(val >> 8, delta); } static void @@ -271,7 +292,6 @@ mt76x0_eeprom_init(struct mt76x0_dev *dev) mt76x0_set_temp_offset(dev); dev->chainmask = 0x0101; - mt76x0_set_tx_power_per_rate(dev, eeprom); mt76x0_set_tx_power_per_chan(dev, eeprom); out: diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h index 8006d08cba45..88e31186c317 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/eeprom.h @@ -34,34 +34,27 @@ struct mt76x0_caldata { s16 temp_offset; u8 freq_offset; + + struct mt76_rate_power rate_power; }; struct mt76x0_eeprom_params { - /* TX_PWR_CFG_* values from EEPROM for 20 and 40 Mhz bandwidths. */ - u32 tx_pwr_cfg_2g[5][2]; - u32 tx_pwr_cfg_5g[5][2]; 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, + struct cfg80211_chan_def *chandef); -static inline u32 s6_validate(u32 reg) +static inline s8 s6_to_s8(u32 val) { - WARN_ON(reg & ~GENMASK(5, 0)); - return reg & GENMASK(5, 0); -} - -static inline int s6_to_int(u32 reg) -{ - int s6; - - s6 = s6_validate(reg); - if (s6 & BIT(5)) - s6 -= BIT(6); + s8 ret = val & GENMASK(5, 0); - return s6; + if (ret & BIT(5)) + ret -= BIT(6); + return ret; } static inline u32 int_to_s6(int val) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c index c3db4c1cd4fe..52cd39fbfd49 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/phy.c @@ -566,21 +566,16 @@ mt76x0_extra_power_over_mac(struct mt76x0_dev *dev) } static void -mt76x0_phy_set_tx_power(struct mt76x0_dev *dev, u8 channel, u8 rf_bw_band) +mt76x0_phy_set_tx_power(struct mt76x0_dev *dev, u8 rf_bw_band) { + struct mt76x0_caldata *caldata = &dev->caldata; + int i, bw = (rf_bw_band & RF_BW_20) ? 0 : 1; u32 val; - int i; - int bw = (rf_bw_band & RF_BW_20) ? 0 : 1; for (i = 0; i < 4; i++) { - if (channel <= 14) - val = dev->ee->tx_pwr_cfg_2g[i][bw]; - else - val = dev->ee->tx_pwr_cfg_5g[i][bw]; - - mt76_wr(dev, MT_TX_PWR_CFG_0 + 4*i, val); + val = caldata->tx_pwr_cfg[i][bw]; + mt76_wr(dev, MT_TX_PWR_CFG_0 + 4 * i, val); } - mt76x0_extra_power_over_mac(dev); } #endif @@ -716,6 +711,7 @@ __mt76x0_phy_set_channel(struct mt76x0_dev *dev, mt76x0_phy_set_band(dev, chandef->chan->band); mt76x0_phy_set_chan_rf_params(dev, channel, rf_bw_band); + mt76x0_set_tx_power_per_rate(dev, chandef); mt76x0_read_rx_gain(dev); /* set Japan Tx filter at channel 14 */ diff --git a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h index 9339514fb073..ca9554ac8f26 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x02_eeprom.h @@ -74,6 +74,7 @@ enum mt76x02_eeprom_field { MT_EE_2G_TARGET_POWER = 0x0d0, MT_EE_TEMP_OFFSET = 0x0d1, + MT_EE_5G_TARGET_POWER = 0x0d2, MT_EE_TSSI_BOUND1 = 0x0d4, MT_EE_TSSI_BOUND2 = 0x0d6, MT_EE_TSSI_BOUND3 = 0x0d8, @@ -121,9 +122,6 @@ enum mt76x02_eeprom_field { #define MT_EE_NIC_CONF_2_TEMP_DISABLE BIT(11) #define MT_EE_NIC_CONF_2_COEX_METHOD GENMASK(15, 13) -#define MT_EE_TX_POWER_BYRATE(x) (MT_EE_TX_POWER_BYRATE_BASE + \ - (x) * 4) - #define MT_EFUSE_USAGE_MAP_SIZE (MT_EE_USAGE_MAP_END - \ MT_EE_USAGE_MAP_START + 1) 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: 10607199 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 B2E386CB for ; Thu, 20 Sep 2018 09:12:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A071C2CBE7 for ; Thu, 20 Sep 2018 09:12:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 941482CC26; Thu, 20 Sep 2018 09:12:48 +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 F0C7B2CBE7 for ; Thu, 20 Sep 2018 09:12:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387528AbeITOzP (ORCPT ); Thu, 20 Sep 2018 10:55:15 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:39019 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387433AbeITOzP (ORCPT ); Thu, 20 Sep 2018 10:55:15 -0400 Received: by mail-wm1-f66.google.com with SMTP id q8-v6so10069987wmq.4 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=DfYKMws24a7g7kKR49N+J3C6+w1RfYgg5rk2HRodZReQYLMoZBXbMLe0nV38yyRGAj oc7Yg9HHZqh0N4+sGH+LEAh5CIcbix17SMnho40E+GasBHCHugO7dQmPoV31NUsu/cyg ocoAvEHZdm2pwUzXphfQgsi/sXYTeJS4doKy09wWW3s72ThmUMJvJS91H030XgPfnTBk 5zcN7SO0HEyTwKrXy5BuDRGDyii1RU7B0aqW36hJcqi1G3OVSHZ+ELPkjFC0kq5dEpxO +Y43sqWueI+EYsEiuCBpz6k8PKoWnUXGHNPMkL2s0f2RbOQ6JMSXLKVNPVXCGgJS0T8Q Tl5Q== X-Gm-Message-State: APzg51AxjGqHMZyQxcU7ZHCaKHUbzHrbzCCszgnznFsgeDZlGB9mT4jT Ox28r5eLJmlyhWacOJOU7Vb5Cw== 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 Cc: linux-wireless@vger.kernel.org, sgruszka@redhat.com, linux-mediatek@lists.infradead.org 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: 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 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); } From patchwork Thu Sep 20 09:12:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 10607201 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 48DE31390 for ; Thu, 20 Sep 2018 09:12:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 38A5D2CBE7 for ; Thu, 20 Sep 2018 09:12:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2BB872CC26; Thu, 20 Sep 2018 09:12:49 +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 B8E8C2CBE7 for ; Thu, 20 Sep 2018 09:12:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387525AbeITOzP (ORCPT ); Thu, 20 Sep 2018 10:55:15 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:38417 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387520AbeITOzO (ORCPT ); Thu, 20 Sep 2018 10:55:14 -0400 Received: by mail-wr1-f68.google.com with SMTP id j8-v6so4850255wrw.5 for ; Thu, 20 Sep 2018 02:12:46 -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=yLoxZlVgr8kr0UlHvn0zstixBJYl32WUX+Q9JPkJvmc=; b=W7bJfyEORmPwjUwrpc/mNbh/JNdIIqbVeLyjRQXVQ2ibsjxE5rHHJPLTt5UosC9FF8 YOgXY6dLdOzLmdTYX56bSutVDBGZN61FdPy38KEXjkgvlcrap+ki4BLXgjtbf30vP18q D7gYrGiHvmqoNaHyFzGprNyD3JUZ2Sl4zGJ+W1yy17Z+nfNpx7MhyLsb/5c7GKx7mNbn 3J5XnAhg3mjxxA/DkNMzFj8z8Vk8e4c9az5l0kZQ9Q/C5TOZXeC1qhFHT6ldNTCl65yl QWiwC+1Pu7BGDZzeunhfw7smmx80l0BImSsy93PvXzohW8tDtvIGHvD9X3u2dkZcH2vM y9pQ== X-Gm-Message-State: APzg51AZIkfSKj/Wsh8HpCFdXCvWlF1bE5BN2tLrav96dyVRMljOsZiG 6PHoCKd+oE3vN2NzsHbPkj/tnw== X-Google-Smtp-Source: ANB0VdYdlZi43C3mGVhIQjRQm1+5IiuN6mAxvDSj2AHKFnxzV4IuMpOcUQjJBn1JUZ/GuyC6O81lUw== X-Received: by 2002:adf:a35e:: with SMTP id d30-v6mr5764173wrb.31.1537434765443; Thu, 20 Sep 2018 02:12:45 -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.44 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 20 Sep 2018 02:12:44 -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 20/20] mt76x0: use shared debugfs implementation Date: Thu, 20 Sep 2018 11:12:07 +0200 Message-Id: <91751ba6b25f23a8da693d237282988057f1a60a.1537433365.git.lorenzo.bianconi@redhat.com> 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 Use mt76 shared debugfs implementation and remove duplicated code Signed-off-by: Lorenzo Bianconi --- .../wireless/mediatek/mt76/mt76x0/debugfs.c | 66 +------------------ .../wireless/mediatek/mt76/mt76x0/mt76x0.h | 2 - 2 files changed, 1 insertion(+), 67 deletions(-) diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c index a34feead2cc4..5fc68bd81d3f 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/debugfs.c @@ -18,26 +18,6 @@ #include "mt76x0.h" #include "eeprom.h" -static int -mt76_reg_set(void *data, u64 val) -{ - struct mt76x0_dev *dev = data; - - mt76_wr(dev, dev->debugfs_reg, val); - return 0; -} - -static int -mt76_reg_get(void *data, u64 *val) -{ - struct mt76x0_dev *dev = data; - - *val = mt76_rr(dev, dev->debugfs_reg); - return 0; -} - -DEFINE_SIMPLE_ATTRIBUTE(fops_regval, mt76_reg_get, mt76_reg_set, "0x%08llx\n"); - static int mt76x0_ampdu_stat_read(struct seq_file *file, void *data) { @@ -95,45 +75,6 @@ static const struct file_operations fops_ampdu_stat = { .release = single_release, }; -static int -mt76x0_eeprom_param_read(struct seq_file *file, void *data) -{ - struct mt76x0_dev *dev = file->private; - u16 val; - int i; - - seq_printf(file, "RF freq offset: %hhx\n", - dev->caldata.freq_offset); - seq_printf(file, "RSSI offset: %hhx %hhx\n", - dev->caldata.rssi_offset[0], dev->caldata.rssi_offset[1]); - seq_printf(file, "Temperature offset: %hhx\n", - dev->caldata.temp_offset); - seq_printf(file, "LNA gain: %x\n", dev->caldata.lna_gain); - - val = mt76x02_eeprom_get(&dev->mt76, MT_EE_NIC_CONF_0); - seq_printf(file, "Power Amplifier type %lx\n", - val & MT_EE_NIC_CONF_0_PA_TYPE); - - seq_puts(file, "Per channel power:\n"); - for (i = 0; i < MT76X0_NUM_CHANS; i++) - seq_printf(file, "\t%d chan:%d pwr:%d\n", i, i, - dev->caldata.tx_pwr_per_chan[i]); - return 0; -} - -static int -mt76x0_eeprom_param_open(struct inode *inode, struct file *f) -{ - return single_open(f, mt76x0_eeprom_param_read, inode->i_private); -} - -static const struct file_operations fops_eeprom_param = { - .open = mt76x0_eeprom_param_open, - .read = seq_read, - .llseek = seq_lseek, - .release = single_release, -}; - static int mt76x0_read_txpower(struct seq_file *file, void *data) { struct mt76x0_dev *dev = dev_get_drvdata(file->private); @@ -155,16 +96,11 @@ void mt76x0_init_debugfs(struct mt76x0_dev *dev) { struct dentry *dir; - dir = debugfs_create_dir("mt76x0", dev->mt76.hw->wiphy->debugfsdir); + dir = mt76_register_debugfs(&dev->mt76); if (!dir) return; - debugfs_create_u32("regidx", S_IRUSR | S_IWUSR, dir, &dev->debugfs_reg); - debugfs_create_file("regval", S_IRUSR | S_IWUSR, dir, dev, - &fops_regval); debugfs_create_file("ampdu_stat", S_IRUSR, dir, dev, &fops_ampdu_stat); - debugfs_create_file("eeprom_param", S_IRUSR, dir, dev, - &fops_eeprom_param); debugfs_create_devm_seqfile(dev->mt76.dev, "txpower", dir, mt76x0_read_txpower); } diff --git a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h index 101332a35f40..e0b349c921b1 100644 --- a/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h +++ b/drivers/net/wireless/mediatek/mt76/mt76x0/mt76x0.h @@ -94,8 +94,6 @@ struct mt76x0_dev { struct mutex reg_atomic_mutex; struct mutex hw_atomic_mutex; - u32 debugfs_reg; - atomic_t avg_ampdu_len; /* Connection monitoring things */