Path: blob/main/sys/contrib/dev/mediatek/mt76/mt76x2/mcu.c
48524 views
// SPDX-License-Identifier: ISC1/*2* Copyright (C) 2016 Felix Fietkau <[email protected]>3* Copyright (C) 2018 Lorenzo Bianconi <[email protected]>4*/56#include <linux/kernel.h>7#include <linux/firmware.h>8#include <linux/delay.h>910#include "mt76x2.h"11#include "mcu.h"12#include "eeprom.h"1314int mt76x2_mcu_set_channel(struct mt76x02_dev *dev, u8 channel, u8 bw,15u8 bw_index, bool scan)16{17struct {18u8 idx;19u8 scan;20u8 bw;21u8 _pad0;2223__le16 chainmask;24u8 ext_chan;25u8 _pad1;2627} __packed __aligned(4) msg = {28.idx = channel,29.scan = scan,30.bw = bw,31.chainmask = cpu_to_le16(dev->mphy.chainmask),32};3334/* first set the channel without the extension channel info */35mt76_mcu_send_msg(&dev->mt76, CMD_SWITCH_CHANNEL_OP, &msg,36sizeof(msg), true);3738usleep_range(5000, 10000);3940msg.ext_chan = 0xe0 + bw_index;41return mt76_mcu_send_msg(&dev->mt76, CMD_SWITCH_CHANNEL_OP, &msg,42sizeof(msg), true);43}44EXPORT_SYMBOL_GPL(mt76x2_mcu_set_channel);4546int mt76x2_mcu_load_cr(struct mt76x02_dev *dev, u8 type, u8 temp_level,47u8 channel)48{49struct {50u8 cr_mode;51u8 temp;52u8 ch;53u8 _pad0;5455__le32 cfg;56} __packed __aligned(4) msg = {57.cr_mode = type,58.temp = temp_level,59.ch = channel,60};61u32 val;6263val = BIT(31);64val |= (mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_0) >> 8) & 0x00ff;65val |= (mt76x02_eeprom_get(dev, MT_EE_NIC_CONF_1) << 8) & 0xff00;66msg.cfg = cpu_to_le32(val);6768/* first set the channel without the extension channel info */69return mt76_mcu_send_msg(&dev->mt76, CMD_LOAD_CR, &msg, sizeof(msg),70true);71}72EXPORT_SYMBOL_GPL(mt76x2_mcu_load_cr);7374int mt76x2_mcu_init_gain(struct mt76x02_dev *dev, u8 channel, u32 gain,75bool force)76{77struct {78__le32 channel;79__le32 gain_val;80} __packed __aligned(4) msg = {81.channel = cpu_to_le32(channel),82.gain_val = cpu_to_le32(gain),83};8485if (force)86msg.channel |= cpu_to_le32(BIT(31));8788return mt76_mcu_send_msg(&dev->mt76, CMD_INIT_GAIN_OP, &msg,89sizeof(msg), true);90}91EXPORT_SYMBOL_GPL(mt76x2_mcu_init_gain);9293int mt76x2_mcu_tssi_comp(struct mt76x02_dev *dev,94struct mt76x2_tssi_comp *tssi_data)95{96struct {97__le32 id;98struct mt76x2_tssi_comp data;99} __packed __aligned(4) msg = {100.id = cpu_to_le32(MCU_CAL_TSSI_COMP),101.data = *tssi_data,102};103104return mt76_mcu_send_msg(&dev->mt76, CMD_CALIBRATION_OP, &msg,105sizeof(msg), true);106}107EXPORT_SYMBOL_GPL(mt76x2_mcu_tssi_comp);108109110