Commit 0e6a29e4 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau

mt76: mt7615: add support to read temperature from mcu

Introduce debugfs entry to read device temperature and related cmu
command. Introduce mt7615_mcu_parse_response to parse mcu response
messages and refactor mt7615_mcu_msg_send routine
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent 373a9a13
...@@ -49,6 +49,18 @@ mt7615_radio_read(struct seq_file *s, void *data) ...@@ -49,6 +49,18 @@ mt7615_radio_read(struct seq_file *s, void *data)
return 0; return 0;
} }
static int mt7615_read_temperature(struct seq_file *s, void *data)
{
struct mt7615_dev *dev = dev_get_drvdata(s->private);
int temp;
/* cpu */
temp = mt7615_mcu_get_temperature(dev, 0);
seq_printf(s, "Temperature: %d\n", temp);
return 0;
}
int mt7615_init_debugfs(struct mt7615_dev *dev) int mt7615_init_debugfs(struct mt7615_dev *dev)
{ {
struct dentry *dir; struct dentry *dir;
...@@ -72,6 +84,8 @@ int mt7615_init_debugfs(struct mt7615_dev *dev) ...@@ -72,6 +84,8 @@ int mt7615_init_debugfs(struct mt7615_dev *dev)
&dev->radar_pattern.power); &dev->radar_pattern.power);
debugfs_create_file("radar_trigger", 0200, dir, dev, debugfs_create_file("radar_trigger", 0200, dir, dev,
&fops_radar_pattern); &fops_radar_pattern);
debugfs_create_devm_seqfile(dev->mt76.dev, "temperature", dir,
mt7615_read_temperature);
return 0; return 0;
} }
...@@ -112,13 +112,39 @@ static int __mt7615_mcu_msg_send(struct mt7615_dev *dev, struct sk_buff *skb, ...@@ -112,13 +112,39 @@ static int __mt7615_mcu_msg_send(struct mt7615_dev *dev, struct sk_buff *skb,
return mt76_tx_queue_skb_raw(dev, qid, skb, 0); return mt76_tx_queue_skb_raw(dev, qid, skb, 0);
} }
static int
mt7615_mcu_parse_response(struct mt7615_dev *dev, int cmd,
struct sk_buff *skb, int seq)
{
struct mt7615_mcu_rxd *rxd = (struct mt7615_mcu_rxd *)skb->data;
int ret = 0;
if (seq != rxd->seq)
return -EAGAIN;
switch (cmd) {
case -MCU_CMD_PATCH_SEM_CONTROL:
skb_pull(skb, sizeof(*rxd) - 4);
ret = *skb->data;
break;
case MCU_EXT_CMD_GET_TEMP:
skb_pull(skb, sizeof(*rxd));
ret = le32_to_cpu(*(__le32 *)skb->data);
break;
default:
break;
}
dev_kfree_skb(skb);
return ret;
}
static int static int
mt7615_mcu_msg_send(struct mt76_dev *mdev, int cmd, const void *data, mt7615_mcu_msg_send(struct mt76_dev *mdev, int cmd, const void *data,
int len, bool wait_resp) int len, bool wait_resp)
{ {
struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76); struct mt7615_dev *dev = container_of(mdev, struct mt7615_dev, mt76);
unsigned long expires = jiffies + 10 * HZ; unsigned long expires = jiffies + 10 * HZ;
struct mt7615_mcu_rxd *rxd;
struct sk_buff *skb; struct sk_buff *skb;
int ret, seq; int ret, seq;
...@@ -141,16 +167,9 @@ mt7615_mcu_msg_send(struct mt76_dev *mdev, int cmd, const void *data, ...@@ -141,16 +167,9 @@ mt7615_mcu_msg_send(struct mt76_dev *mdev, int cmd, const void *data,
break; break;
} }
rxd = (struct mt7615_mcu_rxd *)skb->data; ret = mt7615_mcu_parse_response(dev, cmd, skb, seq);
if (seq != rxd->seq) if (ret != -EAGAIN)
continue; break;
if (cmd == -MCU_CMD_PATCH_SEM_CONTROL) {
skb_pull(skb, sizeof(*rxd) - 4);
ret = *skb->data;
}
dev_kfree_skb(skb);
break;
} }
out: out:
...@@ -1574,3 +1593,16 @@ int mt7615_mcu_set_rx_ba(struct mt7615_dev *dev, ...@@ -1574,3 +1593,16 @@ int mt7615_mcu_set_rx_ba(struct mt7615_dev *dev,
return __mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD_WTBL_UPDATE, return __mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD_WTBL_UPDATE,
&wtbl_req, sizeof(wtbl_req), true); &wtbl_req, sizeof(wtbl_req), true);
} }
int mt7615_mcu_get_temperature(struct mt7615_dev *dev, int index)
{
struct {
u8 action;
u8 rsv[3];
} req = {
.action = index,
};
return __mt76_mcu_send_msg(&dev->mt76, MCU_EXT_CMD_GET_TEMP, &req,
sizeof(req), true);
}
...@@ -98,6 +98,7 @@ enum { ...@@ -98,6 +98,7 @@ enum {
MCU_EXT_CMD_BSS_INFO_UPDATE = 0x26, MCU_EXT_CMD_BSS_INFO_UPDATE = 0x26,
MCU_EXT_CMD_EDCA_UPDATE = 0x27, MCU_EXT_CMD_EDCA_UPDATE = 0x27,
MCU_EXT_CMD_DEV_INFO_UPDATE = 0x2A, MCU_EXT_CMD_DEV_INFO_UPDATE = 0x2A,
MCU_EXT_CMD_GET_TEMP = 0x2c,
MCU_EXT_CMD_WTBL_UPDATE = 0x32, MCU_EXT_CMD_WTBL_UPDATE = 0x32,
MCU_EXT_CMD_SET_RDD_CTRL = 0x3a, MCU_EXT_CMD_SET_RDD_CTRL = 0x3a,
MCU_EXT_CMD_PROTECT_CTRL = 0x3e, MCU_EXT_CMD_PROTECT_CTRL = 0x3e,
......
...@@ -246,6 +246,7 @@ int mt7615_mcu_set_eeprom(struct mt7615_dev *dev); ...@@ -246,6 +246,7 @@ int mt7615_mcu_set_eeprom(struct mt7615_dev *dev);
int mt7615_mcu_init_mac(struct mt7615_dev *dev); int mt7615_mcu_init_mac(struct mt7615_dev *dev);
int mt7615_mcu_set_rts_thresh(struct mt7615_dev *dev, u32 val); int mt7615_mcu_set_rts_thresh(struct mt7615_dev *dev, u32 val);
int mt7615_mcu_ctrl_pm_state(struct mt7615_dev *dev, int enter); int mt7615_mcu_ctrl_pm_state(struct mt7615_dev *dev, int enter);
int mt7615_mcu_get_temperature(struct mt7615_dev *dev, int index);
int mt7615_mcu_set_tx_power(struct mt7615_dev *dev); int mt7615_mcu_set_tx_power(struct mt7615_dev *dev);
void mt7615_mcu_exit(struct mt7615_dev *dev); void mt7615_mcu_exit(struct mt7615_dev *dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment