18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later
28c2ecf20Sopenharmony_ci/*	Copyright (C) 2009 - 2010 Ivo van Doorn <IvDoorn@gmail.com>
38c2ecf20Sopenharmony_ci *	Copyright (C) 2009 Alban Browaeys <prahal@yahoo.com>
48c2ecf20Sopenharmony_ci *	Copyright (C) 2009 Felix Fietkau <nbd@openwrt.org>
58c2ecf20Sopenharmony_ci *	Copyright (C) 2009 Luis Correia <luis.f.correia@gmail.com>
68c2ecf20Sopenharmony_ci *	Copyright (C) 2009 Mattias Nissler <mattias.nissler@gmx.de>
78c2ecf20Sopenharmony_ci *	Copyright (C) 2009 Mark Asselstine <asselsm@gmail.com>
88c2ecf20Sopenharmony_ci *	Copyright (C) 2009 Xose Vazquez Perez <xose.vazquez@gmail.com>
98c2ecf20Sopenharmony_ci *	Copyright (C) 2009 Bart Zolnierkiewicz <bzolnier@gmail.com>
108c2ecf20Sopenharmony_ci *	<http://rt2x00.serialmonkey.com>
118c2ecf20Sopenharmony_ci */
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci/*	Module: rt2800soc
148c2ecf20Sopenharmony_ci *	Abstract: rt2800 WiSoC specific routines.
158c2ecf20Sopenharmony_ci */
168c2ecf20Sopenharmony_ci
178c2ecf20Sopenharmony_ci#include <linux/etherdevice.h>
188c2ecf20Sopenharmony_ci#include <linux/init.h>
198c2ecf20Sopenharmony_ci#include <linux/kernel.h>
208c2ecf20Sopenharmony_ci#include <linux/module.h>
218c2ecf20Sopenharmony_ci#include <linux/platform_device.h>
228c2ecf20Sopenharmony_ci
238c2ecf20Sopenharmony_ci#include "rt2x00.h"
248c2ecf20Sopenharmony_ci#include "rt2x00mmio.h"
258c2ecf20Sopenharmony_ci#include "rt2x00soc.h"
268c2ecf20Sopenharmony_ci#include "rt2800.h"
278c2ecf20Sopenharmony_ci#include "rt2800lib.h"
288c2ecf20Sopenharmony_ci#include "rt2800mmio.h"
298c2ecf20Sopenharmony_ci
308c2ecf20Sopenharmony_ci/* Allow hardware encryption to be disabled. */
318c2ecf20Sopenharmony_cistatic bool modparam_nohwcrypt;
328c2ecf20Sopenharmony_cimodule_param_named(nohwcrypt, modparam_nohwcrypt, bool, 0444);
338c2ecf20Sopenharmony_ciMODULE_PARM_DESC(nohwcrypt, "Disable hardware encryption.");
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_cistatic bool rt2800soc_hwcrypt_disabled(struct rt2x00_dev *rt2x00dev)
368c2ecf20Sopenharmony_ci{
378c2ecf20Sopenharmony_ci	return modparam_nohwcrypt;
388c2ecf20Sopenharmony_ci}
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_cistatic void rt2800soc_disable_radio(struct rt2x00_dev *rt2x00dev)
418c2ecf20Sopenharmony_ci{
428c2ecf20Sopenharmony_ci	u32 reg;
438c2ecf20Sopenharmony_ci
448c2ecf20Sopenharmony_ci	rt2800_disable_radio(rt2x00dev);
458c2ecf20Sopenharmony_ci	rt2x00mmio_register_write(rt2x00dev, PWR_PIN_CFG, 0);
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ci	reg = 0;
488c2ecf20Sopenharmony_ci	if (rt2x00_rt(rt2x00dev, RT3883))
498c2ecf20Sopenharmony_ci		rt2x00_set_field32(&reg, TX_PIN_CFG_RFTR_EN, 1);
508c2ecf20Sopenharmony_ci
518c2ecf20Sopenharmony_ci	rt2x00mmio_register_write(rt2x00dev, TX_PIN_CFG, reg);
528c2ecf20Sopenharmony_ci}
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_cistatic int rt2800soc_set_device_state(struct rt2x00_dev *rt2x00dev,
558c2ecf20Sopenharmony_ci				      enum dev_state state)
568c2ecf20Sopenharmony_ci{
578c2ecf20Sopenharmony_ci	int retval = 0;
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci	switch (state) {
608c2ecf20Sopenharmony_ci	case STATE_RADIO_ON:
618c2ecf20Sopenharmony_ci		retval = rt2800mmio_enable_radio(rt2x00dev);
628c2ecf20Sopenharmony_ci		break;
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci	case STATE_RADIO_OFF:
658c2ecf20Sopenharmony_ci		rt2800soc_disable_radio(rt2x00dev);
668c2ecf20Sopenharmony_ci		break;
678c2ecf20Sopenharmony_ci
688c2ecf20Sopenharmony_ci	case STATE_RADIO_IRQ_ON:
698c2ecf20Sopenharmony_ci	case STATE_RADIO_IRQ_OFF:
708c2ecf20Sopenharmony_ci		rt2800mmio_toggle_irq(rt2x00dev, state);
718c2ecf20Sopenharmony_ci		break;
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci	case STATE_DEEP_SLEEP:
748c2ecf20Sopenharmony_ci	case STATE_SLEEP:
758c2ecf20Sopenharmony_ci	case STATE_STANDBY:
768c2ecf20Sopenharmony_ci	case STATE_AWAKE:
778c2ecf20Sopenharmony_ci		/* These states are not supported, but don't report an error */
788c2ecf20Sopenharmony_ci		retval = 0;
798c2ecf20Sopenharmony_ci		break;
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	default:
828c2ecf20Sopenharmony_ci		retval = -ENOTSUPP;
838c2ecf20Sopenharmony_ci		break;
848c2ecf20Sopenharmony_ci	}
858c2ecf20Sopenharmony_ci
868c2ecf20Sopenharmony_ci	if (unlikely(retval))
878c2ecf20Sopenharmony_ci		rt2x00_err(rt2x00dev, "Device failed to enter state %d (%d)\n",
888c2ecf20Sopenharmony_ci			   state, retval);
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_ci	return retval;
918c2ecf20Sopenharmony_ci}
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_cistatic int rt2800soc_read_eeprom(struct rt2x00_dev *rt2x00dev)
948c2ecf20Sopenharmony_ci{
958c2ecf20Sopenharmony_ci	void __iomem *base_addr = ioremap(0x1F040000, EEPROM_SIZE);
968c2ecf20Sopenharmony_ci
978c2ecf20Sopenharmony_ci	if (!base_addr)
988c2ecf20Sopenharmony_ci		return -ENOMEM;
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	memcpy_fromio(rt2x00dev->eeprom, base_addr, EEPROM_SIZE);
1018c2ecf20Sopenharmony_ci
1028c2ecf20Sopenharmony_ci	iounmap(base_addr);
1038c2ecf20Sopenharmony_ci	return 0;
1048c2ecf20Sopenharmony_ci}
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ci/* Firmware functions */
1078c2ecf20Sopenharmony_cistatic char *rt2800soc_get_firmware_name(struct rt2x00_dev *rt2x00dev)
1088c2ecf20Sopenharmony_ci{
1098c2ecf20Sopenharmony_ci	WARN_ON_ONCE(1);
1108c2ecf20Sopenharmony_ci	return NULL;
1118c2ecf20Sopenharmony_ci}
1128c2ecf20Sopenharmony_ci
1138c2ecf20Sopenharmony_cistatic int rt2800soc_load_firmware(struct rt2x00_dev *rt2x00dev,
1148c2ecf20Sopenharmony_ci				   const u8 *data, const size_t len)
1158c2ecf20Sopenharmony_ci{
1168c2ecf20Sopenharmony_ci	WARN_ON_ONCE(1);
1178c2ecf20Sopenharmony_ci	return 0;
1188c2ecf20Sopenharmony_ci}
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_cistatic int rt2800soc_check_firmware(struct rt2x00_dev *rt2x00dev,
1218c2ecf20Sopenharmony_ci				    const u8 *data, const size_t len)
1228c2ecf20Sopenharmony_ci{
1238c2ecf20Sopenharmony_ci	WARN_ON_ONCE(1);
1248c2ecf20Sopenharmony_ci	return 0;
1258c2ecf20Sopenharmony_ci}
1268c2ecf20Sopenharmony_ci
1278c2ecf20Sopenharmony_cistatic int rt2800soc_write_firmware(struct rt2x00_dev *rt2x00dev,
1288c2ecf20Sopenharmony_ci				    const u8 *data, const size_t len)
1298c2ecf20Sopenharmony_ci{
1308c2ecf20Sopenharmony_ci	WARN_ON_ONCE(1);
1318c2ecf20Sopenharmony_ci	return 0;
1328c2ecf20Sopenharmony_ci}
1338c2ecf20Sopenharmony_ci
1348c2ecf20Sopenharmony_cistatic const struct ieee80211_ops rt2800soc_mac80211_ops = {
1358c2ecf20Sopenharmony_ci	.tx			= rt2x00mac_tx,
1368c2ecf20Sopenharmony_ci	.start			= rt2x00mac_start,
1378c2ecf20Sopenharmony_ci	.stop			= rt2x00mac_stop,
1388c2ecf20Sopenharmony_ci	.add_interface		= rt2x00mac_add_interface,
1398c2ecf20Sopenharmony_ci	.remove_interface	= rt2x00mac_remove_interface,
1408c2ecf20Sopenharmony_ci	.config			= rt2x00mac_config,
1418c2ecf20Sopenharmony_ci	.configure_filter	= rt2x00mac_configure_filter,
1428c2ecf20Sopenharmony_ci	.set_key		= rt2x00mac_set_key,
1438c2ecf20Sopenharmony_ci	.sw_scan_start		= rt2x00mac_sw_scan_start,
1448c2ecf20Sopenharmony_ci	.sw_scan_complete	= rt2x00mac_sw_scan_complete,
1458c2ecf20Sopenharmony_ci	.get_stats		= rt2x00mac_get_stats,
1468c2ecf20Sopenharmony_ci	.get_key_seq		= rt2800_get_key_seq,
1478c2ecf20Sopenharmony_ci	.set_rts_threshold	= rt2800_set_rts_threshold,
1488c2ecf20Sopenharmony_ci	.sta_add		= rt2800_sta_add,
1498c2ecf20Sopenharmony_ci	.sta_remove		= rt2800_sta_remove,
1508c2ecf20Sopenharmony_ci	.bss_info_changed	= rt2x00mac_bss_info_changed,
1518c2ecf20Sopenharmony_ci	.conf_tx		= rt2800_conf_tx,
1528c2ecf20Sopenharmony_ci	.get_tsf		= rt2800_get_tsf,
1538c2ecf20Sopenharmony_ci	.rfkill_poll		= rt2x00mac_rfkill_poll,
1548c2ecf20Sopenharmony_ci	.ampdu_action		= rt2800_ampdu_action,
1558c2ecf20Sopenharmony_ci	.flush			= rt2x00mac_flush,
1568c2ecf20Sopenharmony_ci	.get_survey		= rt2800_get_survey,
1578c2ecf20Sopenharmony_ci	.get_ringparam		= rt2x00mac_get_ringparam,
1588c2ecf20Sopenharmony_ci	.tx_frames_pending	= rt2x00mac_tx_frames_pending,
1598c2ecf20Sopenharmony_ci	.reconfig_complete	= rt2x00mac_reconfig_complete,
1608c2ecf20Sopenharmony_ci};
1618c2ecf20Sopenharmony_ci
1628c2ecf20Sopenharmony_cistatic const struct rt2800_ops rt2800soc_rt2800_ops = {
1638c2ecf20Sopenharmony_ci	.register_read		= rt2x00mmio_register_read,
1648c2ecf20Sopenharmony_ci	.register_read_lock	= rt2x00mmio_register_read, /* same for SoCs */
1658c2ecf20Sopenharmony_ci	.register_write		= rt2x00mmio_register_write,
1668c2ecf20Sopenharmony_ci	.register_write_lock	= rt2x00mmio_register_write, /* same for SoCs */
1678c2ecf20Sopenharmony_ci	.register_multiread	= rt2x00mmio_register_multiread,
1688c2ecf20Sopenharmony_ci	.register_multiwrite	= rt2x00mmio_register_multiwrite,
1698c2ecf20Sopenharmony_ci	.regbusy_read		= rt2x00mmio_regbusy_read,
1708c2ecf20Sopenharmony_ci	.read_eeprom		= rt2800soc_read_eeprom,
1718c2ecf20Sopenharmony_ci	.hwcrypt_disabled	= rt2800soc_hwcrypt_disabled,
1728c2ecf20Sopenharmony_ci	.drv_write_firmware	= rt2800soc_write_firmware,
1738c2ecf20Sopenharmony_ci	.drv_init_registers	= rt2800mmio_init_registers,
1748c2ecf20Sopenharmony_ci	.drv_get_txwi		= rt2800mmio_get_txwi,
1758c2ecf20Sopenharmony_ci	.drv_get_dma_done	= rt2800mmio_get_dma_done,
1768c2ecf20Sopenharmony_ci};
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_cistatic const struct rt2x00lib_ops rt2800soc_rt2x00_ops = {
1798c2ecf20Sopenharmony_ci	.irq_handler		= rt2800mmio_interrupt,
1808c2ecf20Sopenharmony_ci	.txstatus_tasklet	= rt2800mmio_txstatus_tasklet,
1818c2ecf20Sopenharmony_ci	.pretbtt_tasklet	= rt2800mmio_pretbtt_tasklet,
1828c2ecf20Sopenharmony_ci	.tbtt_tasklet		= rt2800mmio_tbtt_tasklet,
1838c2ecf20Sopenharmony_ci	.rxdone_tasklet		= rt2800mmio_rxdone_tasklet,
1848c2ecf20Sopenharmony_ci	.autowake_tasklet	= rt2800mmio_autowake_tasklet,
1858c2ecf20Sopenharmony_ci	.probe_hw		= rt2800mmio_probe_hw,
1868c2ecf20Sopenharmony_ci	.get_firmware_name	= rt2800soc_get_firmware_name,
1878c2ecf20Sopenharmony_ci	.check_firmware		= rt2800soc_check_firmware,
1888c2ecf20Sopenharmony_ci	.load_firmware		= rt2800soc_load_firmware,
1898c2ecf20Sopenharmony_ci	.initialize		= rt2x00mmio_initialize,
1908c2ecf20Sopenharmony_ci	.uninitialize		= rt2x00mmio_uninitialize,
1918c2ecf20Sopenharmony_ci	.get_entry_state	= rt2800mmio_get_entry_state,
1928c2ecf20Sopenharmony_ci	.clear_entry		= rt2800mmio_clear_entry,
1938c2ecf20Sopenharmony_ci	.set_device_state	= rt2800soc_set_device_state,
1948c2ecf20Sopenharmony_ci	.rfkill_poll		= rt2800_rfkill_poll,
1958c2ecf20Sopenharmony_ci	.link_stats		= rt2800_link_stats,
1968c2ecf20Sopenharmony_ci	.reset_tuner		= rt2800_reset_tuner,
1978c2ecf20Sopenharmony_ci	.link_tuner		= rt2800_link_tuner,
1988c2ecf20Sopenharmony_ci	.gain_calibration	= rt2800_gain_calibration,
1998c2ecf20Sopenharmony_ci	.vco_calibration	= rt2800_vco_calibration,
2008c2ecf20Sopenharmony_ci	.watchdog		= rt2800_watchdog,
2018c2ecf20Sopenharmony_ci	.start_queue		= rt2800mmio_start_queue,
2028c2ecf20Sopenharmony_ci	.kick_queue		= rt2800mmio_kick_queue,
2038c2ecf20Sopenharmony_ci	.stop_queue		= rt2800mmio_stop_queue,
2048c2ecf20Sopenharmony_ci	.flush_queue		= rt2800mmio_flush_queue,
2058c2ecf20Sopenharmony_ci	.write_tx_desc		= rt2800mmio_write_tx_desc,
2068c2ecf20Sopenharmony_ci	.write_tx_data		= rt2800_write_tx_data,
2078c2ecf20Sopenharmony_ci	.write_beacon		= rt2800_write_beacon,
2088c2ecf20Sopenharmony_ci	.clear_beacon		= rt2800_clear_beacon,
2098c2ecf20Sopenharmony_ci	.fill_rxdone		= rt2800mmio_fill_rxdone,
2108c2ecf20Sopenharmony_ci	.config_shared_key	= rt2800_config_shared_key,
2118c2ecf20Sopenharmony_ci	.config_pairwise_key	= rt2800_config_pairwise_key,
2128c2ecf20Sopenharmony_ci	.config_filter		= rt2800_config_filter,
2138c2ecf20Sopenharmony_ci	.config_intf		= rt2800_config_intf,
2148c2ecf20Sopenharmony_ci	.config_erp		= rt2800_config_erp,
2158c2ecf20Sopenharmony_ci	.config_ant		= rt2800_config_ant,
2168c2ecf20Sopenharmony_ci	.config			= rt2800_config,
2178c2ecf20Sopenharmony_ci	.pre_reset_hw		= rt2800_pre_reset_hw,
2188c2ecf20Sopenharmony_ci};
2198c2ecf20Sopenharmony_ci
2208c2ecf20Sopenharmony_cistatic const struct rt2x00_ops rt2800soc_ops = {
2218c2ecf20Sopenharmony_ci	.name			= KBUILD_MODNAME,
2228c2ecf20Sopenharmony_ci	.drv_data_size		= sizeof(struct rt2800_drv_data),
2238c2ecf20Sopenharmony_ci	.max_ap_intf		= 8,
2248c2ecf20Sopenharmony_ci	.eeprom_size		= EEPROM_SIZE,
2258c2ecf20Sopenharmony_ci	.rf_size		= RF_SIZE,
2268c2ecf20Sopenharmony_ci	.tx_queues		= NUM_TX_QUEUES,
2278c2ecf20Sopenharmony_ci	.queue_init		= rt2800mmio_queue_init,
2288c2ecf20Sopenharmony_ci	.lib			= &rt2800soc_rt2x00_ops,
2298c2ecf20Sopenharmony_ci	.drv			= &rt2800soc_rt2800_ops,
2308c2ecf20Sopenharmony_ci	.hw			= &rt2800soc_mac80211_ops,
2318c2ecf20Sopenharmony_ci#ifdef CONFIG_RT2X00_LIB_DEBUGFS
2328c2ecf20Sopenharmony_ci	.debugfs		= &rt2800_rt2x00debug,
2338c2ecf20Sopenharmony_ci#endif /* CONFIG_RT2X00_LIB_DEBUGFS */
2348c2ecf20Sopenharmony_ci};
2358c2ecf20Sopenharmony_ci
2368c2ecf20Sopenharmony_cistatic int rt2800soc_probe(struct platform_device *pdev)
2378c2ecf20Sopenharmony_ci{
2388c2ecf20Sopenharmony_ci	return rt2x00soc_probe(pdev, &rt2800soc_ops);
2398c2ecf20Sopenharmony_ci}
2408c2ecf20Sopenharmony_ci
2418c2ecf20Sopenharmony_cistatic struct platform_driver rt2800soc_driver = {
2428c2ecf20Sopenharmony_ci	.driver		= {
2438c2ecf20Sopenharmony_ci		.name		= "rt2800_wmac",
2448c2ecf20Sopenharmony_ci		.mod_name	= KBUILD_MODNAME,
2458c2ecf20Sopenharmony_ci	},
2468c2ecf20Sopenharmony_ci	.probe		= rt2800soc_probe,
2478c2ecf20Sopenharmony_ci	.remove		= rt2x00soc_remove,
2488c2ecf20Sopenharmony_ci	.suspend	= rt2x00soc_suspend,
2498c2ecf20Sopenharmony_ci	.resume		= rt2x00soc_resume,
2508c2ecf20Sopenharmony_ci};
2518c2ecf20Sopenharmony_ci
2528c2ecf20Sopenharmony_cimodule_platform_driver(rt2800soc_driver);
2538c2ecf20Sopenharmony_ci
2548c2ecf20Sopenharmony_ciMODULE_AUTHOR(DRV_PROJECT);
2558c2ecf20Sopenharmony_ciMODULE_VERSION(DRV_VERSION);
2568c2ecf20Sopenharmony_ciMODULE_DESCRIPTION("Ralink WiSoC Wireless LAN driver.");
2578c2ecf20Sopenharmony_ciMODULE_LICENSE("GPL");
258