1 /*
2  * Copyright (C) 2016 Felix Fietkau <nbd@nbd.name>
3  *
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.
7  *
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.
15  */
16 
17 #ifndef __MT76x2_H
18 #define __MT76x2_H
19 
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>
29 
30 #define MT7662_FIRMWARE		"mt7662.bin"
31 #define MT7662_ROM_PATCH	"mt7662_rom_patch.bin"
32 #define MT7662_EEPROM_SIZE	512
33 
34 #include "../mt76x02.h"
35 #include "mac.h"
36 
37 static inline bool is_mt7612(struct mt76x02_dev *dev)
38 {
39 	return mt76_chip(&dev->mt76) == 0x7612;
40 }
41 
42 static inline bool mt76x2_channel_silent(struct mt76x02_dev *dev)
43 {
44 	struct ieee80211_channel *chan = dev->mt76.chandef.chan;
45 
46 	return ((chan->flags & IEEE80211_CHAN_RADAR) &&
47 		chan->dfs_state != NL80211_DFS_AVAILABLE);
48 }
49 
50 extern const struct ieee80211_ops mt76x2_ops;
51 
52 int mt76x2_register_device(struct mt76x02_dev *dev);
53 
54 void mt76x2_phy_power_on(struct mt76x02_dev *dev);
55 void mt76x2_stop_hardware(struct mt76x02_dev *dev);
56 int mt76x2_eeprom_init(struct mt76x02_dev *dev);
57 int mt76x2_apply_calibration_data(struct mt76x02_dev *dev, int channel);
58 
59 void mt76x2_phy_set_antenna(struct mt76x02_dev *dev);
60 int mt76x2_phy_start(struct mt76x02_dev *dev);
61 int mt76x2_phy_set_channel(struct mt76x02_dev *dev,
62 			   struct cfg80211_chan_def *chandef);
63 void mt76x2_phy_calibrate(struct work_struct *work);
64 void mt76x2_phy_set_txpower(struct mt76x02_dev *dev);
65 
66 int mt76x2_mcu_init(struct mt76x02_dev *dev);
67 int mt76x2_mcu_set_channel(struct mt76x02_dev *dev, u8 channel, u8 bw,
68 			   u8 bw_index, bool scan);
69 int mt76x2_mcu_load_cr(struct mt76x02_dev *dev, u8 type, u8 temp_level,
70 		       u8 channel);
71 
72 void mt76x2_cleanup(struct mt76x02_dev *dev);
73 
74 void mt76x2_reset_wlan(struct mt76x02_dev *dev, bool enable);
75 void mt76x2_init_txpower(struct mt76x02_dev *dev,
76 			 struct ieee80211_supported_band *sband);
77 void mt76_write_mac_initvals(struct mt76x02_dev *dev);
78 
79 void mt76x2_phy_tssi_compensate(struct mt76x02_dev *dev);
80 void mt76x2_phy_set_txpower_regs(struct mt76x02_dev *dev,
81 				 enum nl80211_band band);
82 void mt76x2_configure_tx_delay(struct mt76x02_dev *dev,
83 			       enum nl80211_band band, u8 bw);
84 void mt76x2_apply_gain_adj(struct mt76x02_dev *dev);
85 void mt76x2_phy_update_channel_gain(struct mt76x02_dev *dev);
86 
87 #endif
88