1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * AMD MP2 1.1 communication interfaces
5 * Copyright (c) 2022, Advanced Micro Devices, Inc.
8 * Author: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
10 #include <linux/io-64-nonatomic-lo-hi.h>
11 #include <linux/iopoll.h>
13 #include "amd_sfh_interface.h"
15 static int amd_sfh_wait_response(struct amd_mp2_dev *mp2, u8 sid, u32 cmd_id)
17 struct sfh_cmd_response cmd_resp;
19 /* Get response with status within a max of 10000 ms timeout */
20 if (!readl_poll_timeout(mp2->mmio + AMD_P2C_MSG(0), cmd_resp.resp,
21 (cmd_resp.response.response == 0 &&
22 cmd_resp.response.cmd_id == cmd_id && (sid == 0xff ||
23 cmd_resp.response.sensor_id == sid)), 500, 10000000))
24 return cmd_resp.response.response;
29 static void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info)
31 struct sfh_cmd_base cmd_base;
34 cmd_base.cmd.cmd_id = ENABLE_SENSOR;
35 cmd_base.cmd.intr_disable = 0;
36 cmd_base.cmd.sub_cmd_value = 1;
37 cmd_base.cmd.sensor_id = info.sensor_idx;
39 writel(cmd_base.ul, privdata->mmio + AMD_C2P_MSG(0));
42 static void amd_stop_sensor(struct amd_mp2_dev *privdata, u16 sensor_idx)
44 struct sfh_cmd_base cmd_base;
47 cmd_base.cmd.cmd_id = DISABLE_SENSOR;
48 cmd_base.cmd.intr_disable = 0;
49 cmd_base.cmd.sub_cmd_value = 1;
50 cmd_base.cmd.sensor_id = sensor_idx;
52 writeq(0x0, privdata->mmio + AMD_C2P_MSG(1));
53 writel(cmd_base.ul, privdata->mmio + AMD_C2P_MSG(0));
56 static void amd_stop_all_sensor(struct amd_mp2_dev *privdata)
58 struct sfh_cmd_base cmd_base;
61 cmd_base.cmd.cmd_id = DISABLE_SENSOR;
62 cmd_base.cmd.intr_disable = 0;
63 /* 0xf indicates all sensors */
64 cmd_base.cmd.sensor_id = 0xf;
66 writel(cmd_base.ul, privdata->mmio + AMD_C2P_MSG(0));
69 static struct amd_mp2_ops amd_sfh_ops = {
70 .start = amd_start_sensor,
71 .stop = amd_stop_sensor,
72 .stop_all = amd_stop_all_sensor,
73 .response = amd_sfh_wait_response,
76 void sfh_interface_init(struct amd_mp2_dev *mp2)
78 mp2->mp2_ops = &amd_sfh_ops;