2 * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
4 * Permission to use, copy, modify, and/or distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include <linux/device.h>
21 #include <linux/dma-mapping.h>
22 #include <linux/spinlock.h>
23 #include <linux/skbuff.h>
24 #include <linux/netdevice.h>
25 #include <linux/irq.h>
26 #include <linux/interrupt.h>
27 #include <linux/mutex.h>
28 #include <linux/bitops.h>
30 #define MT7662_FIRMWARE "mt7662.bin"
31 #define MT7662_ROM_PATCH "mt7662_rom_patch.bin"
32 #define MT7662_EEPROM_SIZE 512
34 #define MT7662U_FIRMWARE "mediatek/mt7662u.bin"
35 #define MT7662U_ROM_PATCH "mediatek/mt7662u_rom_patch.bin"
37 #define MT_CALIBRATE_INTERVAL HZ
39 #include "../mt76x02.h"
43 static inline bool is_mt7612(struct mt76x02_dev *dev)
45 return mt76_chip(&dev->mt76) == 0x7612;
48 static inline bool mt76x2_channel_silent(struct mt76x02_dev *dev)
50 struct ieee80211_channel *chan = dev->mt76.chandef.chan;
52 return ((chan->flags & IEEE80211_CHAN_RADAR) &&
53 chan->dfs_state != NL80211_DFS_AVAILABLE);
56 extern const struct ieee80211_ops mt76x2_ops;
58 struct mt76x02_dev *mt76x2_alloc_device(struct device *pdev);
59 int mt76x2_register_device(struct mt76x02_dev *dev);
60 void mt76x2_init_debugfs(struct mt76x02_dev *dev);
61 void mt76x2_init_device(struct mt76x02_dev *dev);
63 irqreturn_t mt76x2_irq_handler(int irq, void *dev_instance);
64 void mt76x2_phy_power_on(struct mt76x02_dev *dev);
65 int mt76x2_init_hardware(struct mt76x02_dev *dev);
66 void mt76x2_stop_hardware(struct mt76x02_dev *dev);
67 int mt76x2_eeprom_init(struct mt76x02_dev *dev);
68 int mt76x2_apply_calibration_data(struct mt76x02_dev *dev, int channel);
69 void mt76x2_set_tx_ackto(struct mt76x02_dev *dev);
71 void mt76x2_phy_set_antenna(struct mt76x02_dev *dev);
72 int mt76x2_phy_start(struct mt76x02_dev *dev);
73 int mt76x2_phy_set_channel(struct mt76x02_dev *dev,
74 struct cfg80211_chan_def *chandef);
75 void mt76x2_phy_calibrate(struct work_struct *work);
76 void mt76x2_phy_set_txpower(struct mt76x02_dev *dev);
78 int mt76x2_mcu_init(struct mt76x02_dev *dev);
79 int mt76x2_mcu_set_channel(struct mt76x02_dev *dev, u8 channel, u8 bw,
80 u8 bw_index, bool scan);
81 int mt76x2_mcu_load_cr(struct mt76x02_dev *dev, u8 type, u8 temp_level,
84 void mt76x2_tx_tasklet(unsigned long data);
85 void mt76x2_dma_cleanup(struct mt76x02_dev *dev);
87 void mt76x2_cleanup(struct mt76x02_dev *dev);
89 void mt76x2_mac_set_tx_protection(struct mt76x02_dev *dev, u32 val);
91 void mt76x2_pre_tbtt_tasklet(unsigned long arg);
93 void mt76x2_rx_poll_complete(struct mt76_dev *mdev, enum mt76_rxq_id q);
95 void mt76x2_sta_ps(struct mt76_dev *dev, struct ieee80211_sta *sta, bool ps);
97 void mt76x2_update_channel(struct mt76_dev *mdev);
99 void mt76x2_reset_wlan(struct mt76x02_dev *dev, bool enable);
100 void mt76x2_init_txpower(struct mt76x02_dev *dev,
101 struct ieee80211_supported_band *sband);
102 void mt76_write_mac_initvals(struct mt76x02_dev *dev);
104 void mt76x2_phy_tssi_compensate(struct mt76x02_dev *dev, bool wait);
105 void mt76x2_phy_set_txpower_regs(struct mt76x02_dev *dev,
106 enum nl80211_band band);
107 void mt76x2_configure_tx_delay(struct mt76x02_dev *dev,
108 enum nl80211_band band, u8 bw);
109 void mt76x2_phy_set_bw(struct mt76x02_dev *dev, int width, u8 ctrl);
110 void mt76x2_phy_set_band(struct mt76x02_dev *dev, int band, bool primary_upper);
111 void mt76x2_apply_gain_adj(struct mt76x02_dev *dev);