move eeprom related code to common

Signed-off-by: Felix Fietkau <[email protected]>
This commit is contained in:
Felix Fietkau
2015-12-16 02:09:26 +01:00
parent ad22cd2d22
commit 239b67204c
13 changed files with 99 additions and 106 deletions
+1 -3
View File
@@ -3,7 +3,7 @@ EXTRA_CFLAGS += -Werror
obj-m := mt76.o mt76x2e.o mt7603e.o
mt76-y := \
mmio.o util.o trace.o dma.o mac80211.o debugfs.o
mmio.o util.o trace.o dma.o mac80211.o debugfs.o eeprom.o
mt76x2e-y := \
mt76x2_pci.o mt76x2_dma.o \
@@ -11,8 +11,6 @@ mt76x2e-y := \
mt76x2_core.o mt76x2_mac.o mt76x2_eeprom.o mt76x2_mcu.o mt76x2_phy.o \
mt76x2_trace.o
mt76x2e-$(CONFIG_OF) += mt76x2_of.o
mt7603e-y := \
mt7603_pci.o mt7603_main.o mt7603_init.o mt7603_mcu.o \
mt7603_core.o mt7603_dma.o mt7603_mac.o
+1
View File
@@ -43,6 +43,7 @@ struct dentry *mt76_register_debugfs(struct mt76_dev *dev)
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_blob("eeprom", S_IRUSR, dir, &dev->eeprom);
return dir;
}
+27 -24
View File
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2014 Felix Fietkau <nbd@openwrt.org>
* Copyright (C) 2015 Felix Fietkau <nbd@openwrt.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
@@ -10,31 +10,16 @@
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#include <linux/of.h>
#include <linux/mtd/mtd.h>
#include <linux/mtd/partitions.h>
#include "mt76x2.h"
#include "mt76x2_eeprom.h"
#include "mt76x2_of.h"
#include "mt76.h"
static int mt76x2_check_eeprom(struct mt76x2_dev *dev, const char *type)
static int
mt76_get_of_eeprom(struct mt76_dev *dev, int len)
{
u16 val = get_unaligned_le16(dev->eeprom.data);
switch (val) {
case 0x7662:
case 0x7612:
return 0;
default:
printk("%s EEPROM data check failed: %04x\n", type, val);
return -EINVAL;
}
}
int
mt76x2_get_of_eeprom(struct mt76x2_dev *dev, int len)
{
struct device_node *np = dev->mt76.dev->of_node;
#ifdef CONFIG_OF
struct device_node *np = dev->dev->of_node;
struct mtd_info *mtd;
const __be32 *list;
const char *part;
@@ -79,13 +64,17 @@ mt76x2_get_of_eeprom(struct mt76x2_dev *dev, int len)
if (retlen < len)
return -EINVAL;
return mt76x2_check_eeprom(dev, "Flash");
return 0;
#else
return -ENOENT;
#endif
}
#ifdef CONFIG_OF
void
mt76x2_get_of_overrides(struct mt76x2_dev *dev)
mt76_eeprom_override(struct mt76_dev *dev)
{
struct device_node *np = dev->mt76.dev->of_node;
struct device_node *np = dev->dev->of_node;
const __be32 *val;
int size;
@@ -100,3 +89,17 @@ mt76x2_get_of_overrides(struct mt76x2_dev *dev)
if (val)
dev->cap.has_5ghz = be32_to_cpup(val);
}
EXPORT_SYMBOL_GPL(mt76_eeprom_override);
#endif
int
mt76_eeprom_init(struct mt76_dev *dev, int len)
{
dev->eeprom.size = len;
dev->eeprom.data = devm_kzalloc(dev->dev, len, GFP_KERNEL);
if (!dev->eeprom.data)
return -ENOMEM;
return !mt76_get_of_eeprom(dev, len);
}
EXPORT_SYMBOL_GPL(mt76_eeprom_init);
+3 -3
View File
@@ -183,7 +183,7 @@ static const struct ieee80211_iface_combination if_comb[] = {
}
};
int mt76_register_device(struct mt76_dev *dev, int bands, bool vht,
int mt76_register_device(struct mt76_dev *dev, bool vht,
struct ieee80211_rate *rates, int n_rates)
{
struct ieee80211_hw *hw = dev->hw;
@@ -213,13 +213,13 @@ int mt76_register_device(struct mt76_dev *dev, int bands, bool vht,
ieee80211_hw_set(hw, SUPPORTS_RC_TABLE);
ieee80211_hw_set(hw, SUPPORT_FAST_XMIT);
if (bands & BIT(IEEE80211_BAND_2GHZ)) {
if (dev->cap.has_2ghz) {
ret = mt76_init_sband_2g(dev, rates, n_rates);
if (ret)
return ret;
}
if (bands & BIT(IEEE80211_BAND_5GHZ)) {
if (dev->cap.has_5ghz) {
ret = mt76_init_sband_5g(dev, rates + 4, n_rates - 4, vht);
if (ret)
return ret;
+19 -1
View File
@@ -92,6 +92,11 @@ enum {
MT76_SCANNING,
};
struct mt76_hw_cap {
bool has_2ghz;
bool has_5ghz;
};
struct mt76_dev {
struct ieee80211_hw *hw;
@@ -106,6 +111,8 @@ struct mt76_dev {
struct ieee80211_supported_band sband_2g;
struct ieee80211_supported_band sband_5g;
struct debugfs_blob_wrapper eeprom;
struct mt76_hw_cap cap;
u32 debugfs_reg;
};
@@ -159,9 +166,20 @@ static inline u16 mt76_rev(struct mt76_dev *dev)
#define mt76_queue_cleanup(dev, ...) (dev)->mt76.queue_ops->cleanup(&((dev)->mt76), __VA_ARGS__)
#define mt76_queue_kick(dev, ...) (dev)->mt76.queue_ops->kick(&((dev)->mt76), __VA_ARGS__)
int mt76_register_device(struct mt76_dev *dev, int bands, bool vht,
int mt76_register_device(struct mt76_dev *dev, bool vht,
struct ieee80211_rate *rates, int n_rates);
struct dentry *mt76_register_debugfs(struct mt76_dev *dev);
#ifdef CONFIG_OF
void mt76_eeprom_override(struct mt76_dev *dev);
#else
static inline void mt76_eeprom_override(struct mt76_dev *dev)
{
}
#endif
int mt76_eeprom_init(struct mt76_dev *dev, int len);
#endif
+2
View File
@@ -23,6 +23,8 @@
#define MT7603_FIRMWARE_E1 "mt7603_e1.bin"
#define MT7603_FIRMWARE_E2 "mt7603_e2.bin"
#define MT7603_EEPROM_SIZE 1024
enum {
MT7603_REV_E1 = 0x00,
MT7603_REV_E2 = 0x10
+8 -2
View File
@@ -218,6 +218,12 @@ mt7603_init_hardware(struct mt7603_dev *dev)
mt76_wr(dev, MT_INT_SOURCE_CSR, ~0);
ret = mt76_eeprom_init(&dev->mt76, MT7603_EEPROM_SIZE);
if (ret < 0)
return ret;
dev->mt76.cap.has_2ghz = true;
ret = mt7603_dma_init(dev);
if (ret)
return ret;
@@ -294,8 +300,8 @@ int mt7603_register_device(struct mt7603_dev *dev)
SET_IEEE80211_PERM_ADDR(hw, macaddr);
ret = mt76_register_device(&dev->mt76, BIT(IEEE80211_BAND_2GHZ), true,
mt76x2_rates, ARRAY_SIZE(mt76x2_rates));
ret = mt76_register_device(&dev->mt76, true, mt76x2_rates,
ARRAY_SIZE(mt76x2_rates));
if (ret)
return ret;
-7
View File
@@ -93,11 +93,6 @@ struct mt76x2_wcid {
u8 tx_rate_nss;
};
struct mt76x2_hw_cap {
bool has_2ghz;
bool has_5ghz;
};
struct mt76x2_rate_power {
union {
struct {
@@ -160,9 +155,7 @@ struct mt76x2_dev {
u16 chainmask;
struct mt76x2_calibration cal;
struct debugfs_blob_wrapper eeprom;
struct debugfs_blob_wrapper otp;
struct mt76x2_hw_cap cap;
s8 target_power;
s8 target_power_delta[2];
-1
View File
@@ -89,7 +89,6 @@ void mt76x2_init_debugfs(struct mt76x2_dev *dev)
if (!dir)
return;
debugfs_create_blob("eeprom", S_IRUSR, dir, &dev->eeprom);
debugfs_create_blob("otp", S_IRUSR, dir, &dev->otp);
debugfs_create_u8("temperature", S_IRUSR, dir, &dev->cal.temp);
+34 -18
View File
@@ -15,7 +15,6 @@
#include <asm/unaligned.h>
#include "mt76x2.h"
#include "mt76x2_eeprom.h"
#include "mt76x2_of.h"
#define EE_FIELD(_name, _value) [MT_EE_##_name] = (_value) | 1
@@ -23,17 +22,17 @@ static int
mt76x2_eeprom_copy(struct mt76x2_dev *dev, enum mt76x2_eeprom_field field,
void *dest, int len)
{
if (field + len > dev->eeprom.size)
if (field + len > dev->mt76.eeprom.size)
return -1;
memcpy(dest, dev->eeprom.data + field, len);
memcpy(dest, dev->mt76.eeprom.data + field, len);
return 0;
}
static int
mt76x2_eeprom_get_macaddr(struct mt76x2_dev *dev)
{
void *src = dev->eeprom.data + MT_EE_MAC_ADDR;
void *src = dev->mt76.eeprom.data + MT_EE_MAC_ADDR;
memcpy(dev->macaddr, src, ETH_ALEN);
return 0;
@@ -46,14 +45,14 @@ mt76x2_eeprom_parse_hw_cap(struct mt76x2_dev *dev)
switch (MT76_GET(MT_EE_NIC_CONF_0_BOARD_TYPE, val)) {
case BOARD_TYPE_5GHZ:
dev->cap.has_5ghz = true;
dev->mt76.cap.has_5ghz = true;
break;
case BOARD_TYPE_2GHZ:
dev->cap.has_2ghz = true;
dev->mt76.cap.has_2ghz = true;
break;
default:
dev->cap.has_2ghz = true;
dev->cap.has_5ghz = true;
dev->mt76.cap.has_2ghz = true;
dev->mt76.cap.has_5ghz = true;
break;
}
}
@@ -160,7 +159,7 @@ mt76x2_apply_cal_free_data(struct mt76x2_dev *dev, u8 *efuse)
MT_EE_RF_5G_GRP4_5_RX_HIGH_GAIN,
MT_EE_RF_5G_GRP4_5_RX_HIGH_GAIN + 1,
};
u8 *eeprom = dev->eeprom.data;
u8 *eeprom = dev->mt76.eeprom.data;
u8 prev_grp0[4] = {
eeprom[MT_EE_TX_POWER_0_START_5G],
eeprom[MT_EE_TX_POWER_0_START_5G + 1],
@@ -196,22 +195,39 @@ mt76x2_apply_cal_free_data(struct mt76x2_dev *dev, u8 *efuse)
eeprom[MT_EE_BT_PMUCFG] = val & 0xff;
}
static int mt76x2_check_eeprom(struct mt76x2_dev *dev)
{
u16 val = get_unaligned_le16(dev->mt76.eeprom.data);
switch (val) {
case 0x7662:
case 0x7612:
return 0;
default:
printk("EEPROM data check failed: %04x\n", val);
return -EINVAL;
}
}
static int
mt76x2_eeprom_load(struct mt76x2_dev *dev)
{
void *efuse;
int len = MT7662_EEPROM_SIZE;
bool found;
int ret;
dev->eeprom.size = len;
dev->eeprom.data = devm_kzalloc(dev->mt76.dev, len * 2, GFP_KERNEL);
if (!dev->eeprom.data)
return -ENOMEM;
ret = mt76_eeprom_init(&dev->mt76, len);
if (ret < 0)
return ret;
found = ret;
if (found)
found = !mt76x2_check_eeprom(dev);
dev->otp.data = devm_kzalloc(dev->mt76.dev, len, GFP_KERNEL);
dev->otp.size = len;
dev->otp.data = dev->eeprom.data + len;
found = !mt76x2_get_of_eeprom(dev, len);
if (!dev->otp.data)
return -ENOMEM;
efuse = dev->otp.data;
@@ -223,7 +239,7 @@ mt76x2_eeprom_load(struct mt76x2_dev *dev)
} else {
/* FIXME: check if efuse data is complete */
found = true;
memcpy(dev->eeprom.data, efuse, len);
memcpy(dev->mt76.eeprom.data, efuse, len);
}
out:
@@ -601,7 +617,7 @@ int mt76x2_eeprom_init(struct mt76x2_dev *dev)
return ret;
mt76x2_eeprom_parse_hw_cap(dev);
mt76x2_get_of_overrides(dev);
mt76_eeprom_override(&dev->mt76);
mt76x2_eeprom_get_macaddr(dev);
if (!is_valid_ether_addr(dev->macaddr)) {
+1 -1
View File
@@ -140,7 +140,7 @@ mt76x2_eeprom_get(struct mt76x2_dev *dev, enum mt76x2_eeprom_field field)
if ((field & 1) || field >= __MT_EE_MAX)
return -1;
return get_unaligned_le16(dev->eeprom.data + field);
return get_unaligned_le16(dev->mt76.eeprom.data + field);
}
void mt76x2_get_rate_power(struct mt76x2_dev *dev, struct mt76x2_rate_power *t);
+3 -7
View File
@@ -613,7 +613,6 @@ int mt76x2_register_device(struct mt76x2_dev *dev)
void *status_fifo;
int fifo_size;
int i, ret;
int bands;
fifo_size = roundup_pow_of_two(32 * sizeof(struct mt76x2_tx_status));
status_fifo = devm_kzalloc(dev->mt76.dev, fifo_size, GFP_KERNEL);
@@ -656,15 +655,12 @@ int mt76x2_register_device(struct mt76x2_dev *dev)
INIT_DELAYED_WORK(&dev->cal_work, mt76x2_phy_calibrate);
INIT_DELAYED_WORK(&dev->mac_work, mt76x2_mac_work);
bands = (!!dev->cap.has_2ghz * BIT(IEEE80211_BAND_2GHZ)) |
(!!dev->cap.has_5ghz * BIT(IEEE80211_BAND_5GHZ));
ret = mt76_register_device(&dev->mt76, bands, true,
mt76x2_rates, ARRAY_SIZE(mt76x2_rates));
ret = mt76_register_device(&dev->mt76, true, mt76x2_rates,
ARRAY_SIZE(mt76x2_rates));
if (ret)
goto fail;
sband = wiphy->bands[dev->cap.has_5ghz ? IEEE80211_BAND_5GHZ :
sband = wiphy->bands[dev->mt76.cap.has_5ghz ? IEEE80211_BAND_5GHZ :
IEEE80211_BAND_2GHZ];
dev->chandef.chan = &sband->channels[0];
-39
View File
@@ -1,39 +0,0 @@
/*
* Copyright (C) 2014 Felix Fietkau <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef __MT76x2_OF_H
#define __MT76x2_OF_H
#include "mt76x2.h"
#ifdef CONFIG_OF
int mt76x2_get_of_eeprom(struct mt76x2_dev *dev, int len);
void mt76x2_get_of_overrides(struct mt76x2_dev *dev);
#else
static inline int
mt76x2_get_of_eeprom(struct mt76x2_dev *dev, int len)
{
return -ENOENT;
}
static inline void
mt76x2_get_of_overrides(struct mt76x2_dev *dev)
{
}
#endif /* CONFIG_OF */
#endif