Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * AMD MP2 1.1 communication interfaces
0004  *
0005  * Copyright (c) 2022, Advanced Micro Devices, Inc.
0006  * All Rights Reserved.
0007  *
0008  * Author: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
0009  */
0010 #include <linux/io-64-nonatomic-lo-hi.h>
0011 #include <linux/iopoll.h>
0012 
0013 #include "amd_sfh_interface.h"
0014 
0015 static int amd_sfh_wait_response(struct amd_mp2_dev *mp2, u8 sid, u32 cmd_id)
0016 {
0017     struct sfh_cmd_response cmd_resp;
0018 
0019     /* Get response with status within a max of 1600 ms timeout */
0020     if (!readl_poll_timeout(mp2->mmio + AMD_P2C_MSG(0), cmd_resp.resp,
0021                 (cmd_resp.response.response == 0 &&
0022                 cmd_resp.response.cmd_id == cmd_id && (sid == 0xff ||
0023                 cmd_resp.response.sensor_id == sid)), 500, 1600000))
0024         return cmd_resp.response.response;
0025 
0026     return -1;
0027 }
0028 
0029 static void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info)
0030 {
0031     struct sfh_cmd_base cmd_base;
0032 
0033     cmd_base.ul = 0;
0034     cmd_base.cmd.cmd_id = ENABLE_SENSOR;
0035     cmd_base.cmd.intr_disable = 0;
0036     cmd_base.cmd.sensor_id = info.sensor_idx;
0037 
0038     writel(cmd_base.ul, privdata->mmio + AMD_C2P_MSG(0));
0039 }
0040 
0041 static void amd_stop_sensor(struct amd_mp2_dev *privdata, u16 sensor_idx)
0042 {
0043     struct sfh_cmd_base cmd_base;
0044 
0045     cmd_base.ul = 0;
0046     cmd_base.cmd.cmd_id = DISABLE_SENSOR;
0047     cmd_base.cmd.intr_disable = 0;
0048     cmd_base.cmd.sensor_id = sensor_idx;
0049 
0050     writeq(0x0, privdata->mmio + AMD_C2P_MSG(1));
0051     writel(cmd_base.ul, privdata->mmio + AMD_C2P_MSG(0));
0052 }
0053 
0054 static void amd_stop_all_sensor(struct amd_mp2_dev *privdata)
0055 {
0056     struct sfh_cmd_base cmd_base;
0057 
0058     cmd_base.ul = 0;
0059     cmd_base.cmd.cmd_id = STOP_ALL_SENSORS;
0060     cmd_base.cmd.intr_disable = 0;
0061 
0062     writel(cmd_base.ul, privdata->mmio + AMD_C2P_MSG(0));
0063 }
0064 
0065 static struct amd_mp2_ops amd_sfh_ops = {
0066     .start = amd_start_sensor,
0067     .stop = amd_stop_sensor,
0068     .stop_all = amd_stop_all_sensor,
0069     .response = amd_sfh_wait_response,
0070 };
0071 
0072 void sfh_interface_init(struct amd_mp2_dev *mp2)
0073 {
0074     mp2->mp2_ops = &amd_sfh_ops;
0075 }