xref: /linux/drivers/net/wireless/ralink/rt2x00/rt2800soc.c (revision e6a901a00822659181c93c86d8bbc2a17779fddc)
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*	Copyright (C) 2009 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
3  *	Copyright (C) 2009 Alban Browaeys <prahal@yahoo.com>
4  *	Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
5  *	Copyright (C) 2009 Luis Correia <luis.f.correia@gmail.com>
6  *	Copyright (C) 2009 Mattias Nissler <mattias.nissler@gmx.de>
7  *	Copyright (C) 2009 Mark Asselstine <asselsm@gmail.com>
8  *	Copyright (C) 2009 Xose Vazquez Perez <xose.vazquez@gmail.com>
9  *	Copyright (C) 2009 Bart Zolnierkiewicz <bzolnier@gmail.com>
10  *	<http://rt2x00.serialmonkey.com>
11  */
12 
13 /*	Module: rt2800soc
14  *	Abstract: rt2800 WiSoC specific routines.
15  */
16 
17 #include <linux/etherdevice.h>
18 #include <linux/init.h>
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/platform_device.h>
22 
23 #include "rt2x00.h"
24 #include "rt2x00mmio.h"
25 #include "rt2x00soc.h"
26 #include "rt2800.h"
27 #include "rt2800lib.h"
28 #include "rt2800mmio.h"
29 
30 /* Allow hardware encryption to be disabled. */
31 static bool modparam_nohwcrypt;
32 module_param_named(nohwcrypt, modparam_nohwcrypt, bool, 0444);
33 MODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
34 
35 static bool rt2800soc_hwcrypt_disabled(struct rt2x00_dev *rt2x00dev)
36 {
37 	return modparam_nohwcrypt;
38 }
39 
40 static void rt2800soc_disable_radio(struct rt2x00_dev *rt2x00dev)
41 {
42 	u32 reg;
43 
44 	rt2800_disable_radio(rt2x00dev);
45 	rt2x00mmio_register_write(rt2x00dev, PWR_PIN_CFG, 0);
46 
47 	reg = 0;
48 	if (rt2x00_rt(rt2x00dev, RT3883))
49 		rt2x00_set_field32(&reg, TX_PIN_CFG_RFTR_EN, 1);
50 
51 	rt2x00mmio_register_write(rt2x00dev, TX_PIN_CFG, reg);
52 }
53 
54 static int rt2800soc_set_device_state(struct rt2x00_dev *rt2x00dev,
55 				      enum dev_state state)
56 {
57 	int retval = 0;
58 
59 	switch (state) {
60 	case STATE_RADIO_ON:
61 		retval = rt2800mmio_enable_radio(rt2x00dev);
62 		break;
63 
64 	case STATE_RADIO_OFF:
65 		rt2800soc_disable_radio(rt2x00dev);
66 		break;
67 
68 	case STATE_RADIO_IRQ_ON:
69 	case STATE_RADIO_IRQ_OFF:
70 		rt2800mmio_toggle_irq(rt2x00dev, state);
71 		break;
72 
73 	case STATE_DEEP_SLEEP:
74 	case STATE_SLEEP:
75 	case STATE_STANDBY:
76 	case STATE_AWAKE:
77 		/* These states are not supported, but don't report an error */
78 		retval = 0;
79 		break;
80 
81 	default:
82 		retval = -ENOTSUPP;
83 		break;
84 	}
85 
86 	if (unlikely(retval))
87 		rt2x00_err(rt2x00dev, "Device failed to enter state %d (%d)\n",
88 			   state, retval);
89 
90 	return retval;
91 }
92 
93 static int rt2800soc_read_eeprom(struct rt2x00_dev *rt2x00dev)
94 {
95 	void __iomem *base_addr = ioremap(0x1F040000, EEPROM_SIZE);
96 
97 	if (!base_addr)
98 		return -ENOMEM;
99 
100 	memcpy_fromio(rt2x00dev->eeprom, base_addr, EEPROM_SIZE);
101 
102 	iounmap(base_addr);
103 	return 0;
104 }
105 
106 /* Firmware functions */
107 static char *rt2800soc_get_firmware_name(struct rt2x00_dev *rt2x00dev)
108 {
109 	WARN_ON_ONCE(1);
110 	return NULL;
111 }
112 
113 static int rt2800soc_load_firmware(struct rt2x00_dev *rt2x00dev,
114 				   const u8 *data, const size_t len)
115 {
116 	WARN_ON_ONCE(1);
117 	return 0;
118 }
119 
120 static int rt2800soc_check_firmware(struct rt2x00_dev *rt2x00dev,
121 				    const u8 *data, const size_t len)
122 {
123 	WARN_ON_ONCE(1);
124 	return 0;
125 }
126 
127 static int rt2800soc_write_firmware(struct rt2x00_dev *rt2x00dev,
128 				    const u8 *data, const size_t len)
129 {
130 	WARN_ON_ONCE(1);
131 	return 0;
132 }
133 
134 static const struct ieee80211_ops rt2800soc_mac80211_ops = {
135 	.add_chanctx = ieee80211_emulate_add_chanctx,
136 	.remove_chanctx = ieee80211_emulate_remove_chanctx,
137 	.change_chanctx = ieee80211_emulate_change_chanctx,
138 	.switch_vif_chanctx = ieee80211_emulate_switch_vif_chanctx,
139 	.tx			= rt2x00mac_tx,
140 	.wake_tx_queue		= ieee80211_handle_wake_tx_queue,
141 	.start			= rt2x00mac_start,
142 	.stop			= rt2x00mac_stop,
143 	.add_interface		= rt2x00mac_add_interface,
144 	.remove_interface	= rt2x00mac_remove_interface,
145 	.config			= rt2x00mac_config,
146 	.configure_filter	= rt2x00mac_configure_filter,
147 	.set_key		= rt2x00mac_set_key,
148 	.sw_scan_start		= rt2x00mac_sw_scan_start,
149 	.sw_scan_complete	= rt2x00mac_sw_scan_complete,
150 	.get_stats		= rt2x00mac_get_stats,
151 	.get_key_seq		= rt2800_get_key_seq,
152 	.set_rts_threshold	= rt2800_set_rts_threshold,
153 	.sta_add		= rt2800_sta_add,
154 	.sta_remove		= rt2800_sta_remove,
155 	.bss_info_changed	= rt2x00mac_bss_info_changed,
156 	.conf_tx		= rt2800_conf_tx,
157 	.get_tsf		= rt2800_get_tsf,
158 	.rfkill_poll		= rt2x00mac_rfkill_poll,
159 	.ampdu_action		= rt2800_ampdu_action,
160 	.flush			= rt2x00mac_flush,
161 	.get_survey		= rt2800_get_survey,
162 	.get_ringparam		= rt2x00mac_get_ringparam,
163 	.tx_frames_pending	= rt2x00mac_tx_frames_pending,
164 	.reconfig_complete	= rt2x00mac_reconfig_complete,
165 };
166 
167 static const struct rt2800_ops rt2800soc_rt2800_ops = {
168 	.register_read		= rt2x00mmio_register_read,
169 	.register_read_lock	= rt2x00mmio_register_read, /* same for SoCs */
170 	.register_write		= rt2x00mmio_register_write,
171 	.register_write_lock	= rt2x00mmio_register_write, /* same for SoCs */
172 	.register_multiread	= rt2x00mmio_register_multiread,
173 	.register_multiwrite	= rt2x00mmio_register_multiwrite,
174 	.regbusy_read		= rt2x00mmio_regbusy_read,
175 	.read_eeprom		= rt2800soc_read_eeprom,
176 	.hwcrypt_disabled	= rt2800soc_hwcrypt_disabled,
177 	.drv_write_firmware	= rt2800soc_write_firmware,
178 	.drv_init_registers	= rt2800mmio_init_registers,
179 	.drv_get_txwi		= rt2800mmio_get_txwi,
180 	.drv_get_dma_done	= rt2800mmio_get_dma_done,
181 };
182 
183 static const struct rt2x00lib_ops rt2800soc_rt2x00_ops = {
184 	.irq_handler		= rt2800mmio_interrupt,
185 	.txstatus_tasklet	= rt2800mmio_txstatus_tasklet,
186 	.pretbtt_tasklet	= rt2800mmio_pretbtt_tasklet,
187 	.tbtt_tasklet		= rt2800mmio_tbtt_tasklet,
188 	.rxdone_tasklet		= rt2800mmio_rxdone_tasklet,
189 	.autowake_tasklet	= rt2800mmio_autowake_tasklet,
190 	.probe_hw		= rt2800mmio_probe_hw,
191 	.get_firmware_name	= rt2800soc_get_firmware_name,
192 	.check_firmware		= rt2800soc_check_firmware,
193 	.load_firmware		= rt2800soc_load_firmware,
194 	.initialize		= rt2x00mmio_initialize,
195 	.uninitialize		= rt2x00mmio_uninitialize,
196 	.get_entry_state	= rt2800mmio_get_entry_state,
197 	.clear_entry		= rt2800mmio_clear_entry,
198 	.set_device_state	= rt2800soc_set_device_state,
199 	.rfkill_poll		= rt2800_rfkill_poll,
200 	.link_stats		= rt2800_link_stats,
201 	.reset_tuner		= rt2800_reset_tuner,
202 	.link_tuner		= rt2800_link_tuner,
203 	.gain_calibration	= rt2800_gain_calibration,
204 	.vco_calibration	= rt2800_vco_calibration,
205 	.watchdog		= rt2800_watchdog,
206 	.start_queue		= rt2800mmio_start_queue,
207 	.kick_queue		= rt2800mmio_kick_queue,
208 	.stop_queue		= rt2800mmio_stop_queue,
209 	.flush_queue		= rt2800mmio_flush_queue,
210 	.write_tx_desc		= rt2800mmio_write_tx_desc,
211 	.write_tx_data		= rt2800_write_tx_data,
212 	.write_beacon		= rt2800_write_beacon,
213 	.clear_beacon		= rt2800_clear_beacon,
214 	.fill_rxdone		= rt2800mmio_fill_rxdone,
215 	.config_shared_key	= rt2800_config_shared_key,
216 	.config_pairwise_key	= rt2800_config_pairwise_key,
217 	.config_filter		= rt2800_config_filter,
218 	.config_intf		= rt2800_config_intf,
219 	.config_erp		= rt2800_config_erp,
220 	.config_ant		= rt2800_config_ant,
221 	.config			= rt2800_config,
222 	.pre_reset_hw		= rt2800_pre_reset_hw,
223 };
224 
225 static const struct rt2x00_ops rt2800soc_ops = {
226 	.name			= KBUILD_MODNAME,
227 	.drv_data_size		= sizeof(struct rt2800_drv_data),
228 	.max_ap_intf		= 8,
229 	.eeprom_size		= EEPROM_SIZE,
230 	.rf_size		= RF_SIZE,
231 	.tx_queues		= NUM_TX_QUEUES,
232 	.queue_init		= rt2800mmio_queue_init,
233 	.lib			= &rt2800soc_rt2x00_ops,
234 	.drv			= &rt2800soc_rt2800_ops,
235 	.hw			= &rt2800soc_mac80211_ops,
236 #ifdef CONFIG_RT2X00_LIB_DEBUGFS
237 	.debugfs		= &rt2800_rt2x00debug,
238 #endif /* CONFIG_RT2X00_LIB_DEBUGFS */
239 };
240 
241 static int rt2800soc_probe(struct platform_device *pdev)
242 {
243 	return rt2x00soc_probe(pdev, &rt2800soc_ops);
244 }
245 
246 static struct platform_driver rt2800soc_driver = {
247 	.driver		= {
248 		.name		= "rt2800_wmac",
249 		.mod_name	= KBUILD_MODNAME,
250 	},
251 	.probe		= rt2800soc_probe,
252 	.remove		= rt2x00soc_remove,
253 	.suspend	= rt2x00soc_suspend,
254 	.resume		= rt2x00soc_resume,
255 };
256 
257 module_platform_driver(rt2800soc_driver);
258 
259 MODULE_AUTHOR(DRV_PROJECT);
260 MODULE_VERSION(DRV_VERSION);
261 MODULE_DESCRIPTION("Ralink WiSoC Wireless LAN driver.");
262 MODULE_LICENSE("GPL");
263