2020-10-10 04:01:36 +08:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
/*
|
|
|
|
* AMD MP2 PCIe communication driver
|
2021-09-23 20:29:30 +08:00
|
|
|
* Copyright 2020-2021 Advanced Micro Devices, Inc.
|
2020-10-10 04:01:36 +08:00
|
|
|
* Authors: Shyam Sundar S K <Shyam-sundar.S-k@amd.com>
|
|
|
|
* Sandeep Singh <Sandeep.singh@amd.com>
|
2021-09-23 20:29:30 +08:00
|
|
|
* Basavaraj Natikar <Basavaraj.Natikar@amd.com>
|
2020-10-10 04:01:36 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef PCIE_MP2_AMD_H
|
|
|
|
#define PCIE_MP2_AMD_H
|
|
|
|
|
|
|
|
#include <linux/pci.h>
|
2021-06-18 16:18:37 +08:00
|
|
|
#include "amd_sfh_hid.h"
|
2020-10-10 04:01:36 +08:00
|
|
|
|
|
|
|
#define PCI_DEVICE_ID_AMD_MP2 0x15E4
|
|
|
|
|
|
|
|
#define ENABLE_SENSOR 1
|
|
|
|
#define DISABLE_SENSOR 2
|
|
|
|
#define STOP_ALL_SENSORS 8
|
|
|
|
|
|
|
|
/* MP2 C2P Message Registers */
|
|
|
|
#define AMD_C2P_MSG0 0x10500
|
|
|
|
#define AMD_C2P_MSG1 0x10504
|
|
|
|
#define AMD_C2P_MSG2 0x10508
|
|
|
|
|
2021-06-18 16:18:36 +08:00
|
|
|
#define AMD_C2P_MSG(regno) (0x10500 + ((regno) * 4))
|
2021-08-02 22:03:38 +08:00
|
|
|
#define AMD_P2C_MSG(regno) (0x10680 + ((regno) * 4))
|
2021-06-18 16:18:36 +08:00
|
|
|
|
2020-10-10 04:01:36 +08:00
|
|
|
/* MP2 P2C Message Registers */
|
|
|
|
#define AMD_P2C_MSG3 0x1068C /* Supported Sensors info */
|
|
|
|
|
2021-06-18 16:18:36 +08:00
|
|
|
#define V2_STATUS 0x2
|
|
|
|
|
2021-08-02 22:03:38 +08:00
|
|
|
#define SENSOR_ENABLED 4
|
|
|
|
#define SENSOR_DISABLED 5
|
|
|
|
|
2021-06-18 16:18:38 +08:00
|
|
|
#define HPD_IDX 16
|
|
|
|
|
2021-08-02 22:03:40 +08:00
|
|
|
#define AMD_SFH_IDLE_LOOP 200
|
|
|
|
|
2020-10-10 04:01:36 +08:00
|
|
|
/* SFH Command register */
|
|
|
|
union sfh_cmd_base {
|
|
|
|
u32 ul;
|
|
|
|
struct {
|
|
|
|
u32 cmd_id : 8;
|
|
|
|
u32 sensor_id : 8;
|
|
|
|
u32 period : 16;
|
|
|
|
} s;
|
2021-06-18 16:18:36 +08:00
|
|
|
struct {
|
|
|
|
u32 cmd_id : 4;
|
2022-02-08 20:21:09 +08:00
|
|
|
u32 intr_disable : 1;
|
2021-06-18 16:18:36 +08:00
|
|
|
u32 rsvd1 : 3;
|
|
|
|
u32 length : 7;
|
|
|
|
u32 mem_type : 1;
|
|
|
|
u32 sensor_id : 8;
|
|
|
|
u32 period : 8;
|
|
|
|
} cmd_v2;
|
2020-10-10 04:01:36 +08:00
|
|
|
};
|
|
|
|
|
2021-08-02 22:03:38 +08:00
|
|
|
union cmd_response {
|
|
|
|
u32 resp;
|
|
|
|
struct {
|
|
|
|
u32 status : 2;
|
|
|
|
u32 out_in_c2p : 1;
|
|
|
|
u32 rsvd1 : 1;
|
|
|
|
u32 response : 4;
|
|
|
|
u32 sub_cmd : 8;
|
|
|
|
u32 sensor_id : 6;
|
|
|
|
u32 rsvd2 : 10;
|
|
|
|
} response_v2;
|
|
|
|
};
|
|
|
|
|
2020-10-10 04:01:36 +08:00
|
|
|
union sfh_cmd_param {
|
|
|
|
u32 ul;
|
|
|
|
struct {
|
|
|
|
u32 buf_layout : 2;
|
|
|
|
u32 buf_length : 6;
|
|
|
|
u32 rsvd : 24;
|
|
|
|
} s;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct sfh_cmd_reg {
|
|
|
|
union sfh_cmd_base cmd_base;
|
|
|
|
union sfh_cmd_param cmd_param;
|
|
|
|
phys_addr_t phys_addr;
|
|
|
|
};
|
|
|
|
|
|
|
|
enum sensor_idx {
|
|
|
|
accel_idx = 0,
|
|
|
|
gyro_idx = 1,
|
|
|
|
mag_idx = 2,
|
|
|
|
als_idx = 19
|
|
|
|
};
|
|
|
|
|
|
|
|
struct amd_mp2_dev {
|
|
|
|
struct pci_dev *pdev;
|
|
|
|
struct amdtp_cl_data *cl_data;
|
|
|
|
void __iomem *mmio;
|
2021-06-18 16:18:36 +08:00
|
|
|
const struct amd_mp2_ops *mp2_ops;
|
2021-06-18 16:18:37 +08:00
|
|
|
struct amd_input_data in_data;
|
2021-06-18 16:18:36 +08:00
|
|
|
/* mp2 active control status */
|
|
|
|
u32 mp2_acs;
|
2020-10-10 04:01:36 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct amd_mp2_sensor_info {
|
|
|
|
u8 sensor_idx;
|
|
|
|
u32 period;
|
2021-01-03 21:53:55 +08:00
|
|
|
dma_addr_t dma_address;
|
2020-10-10 04:01:36 +08:00
|
|
|
};
|
|
|
|
|
2021-06-18 16:18:36 +08:00
|
|
|
enum mem_use_type {
|
|
|
|
USE_DRAM,
|
|
|
|
USE_C2P_REG,
|
|
|
|
};
|
|
|
|
|
2021-06-18 16:18:38 +08:00
|
|
|
struct hpd_status {
|
|
|
|
union {
|
|
|
|
struct {
|
|
|
|
u32 human_presence_report : 4;
|
|
|
|
u32 human_presence_actual : 4;
|
|
|
|
u32 probablity : 8;
|
|
|
|
u32 object_distance : 16;
|
|
|
|
} shpd;
|
|
|
|
u32 val;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2020-10-10 04:01:36 +08:00
|
|
|
void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info);
|
|
|
|
void amd_stop_sensor(struct amd_mp2_dev *privdata, u16 sensor_idx);
|
|
|
|
void amd_stop_all_sensors(struct amd_mp2_dev *privdata);
|
|
|
|
int amd_mp2_get_sensor_num(struct amd_mp2_dev *privdata, u8 *sensor_id);
|
|
|
|
int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata);
|
|
|
|
int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata);
|
2021-08-02 22:03:40 +08:00
|
|
|
u32 amd_sfh_wait_for_response(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts);
|
|
|
|
void amd_mp2_suspend(struct amd_mp2_dev *mp2);
|
|
|
|
void amd_mp2_resume(struct amd_mp2_dev *mp2);
|
2021-06-18 16:18:36 +08:00
|
|
|
|
|
|
|
struct amd_mp2_ops {
|
|
|
|
void (*start)(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info);
|
|
|
|
void (*stop)(struct amd_mp2_dev *privdata, u16 sensor_idx);
|
|
|
|
void (*stop_all)(struct amd_mp2_dev *privdata);
|
2021-08-02 22:03:38 +08:00
|
|
|
int (*response)(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts);
|
2022-02-08 20:21:11 +08:00
|
|
|
void (*clear_intr)(struct amd_mp2_dev *privdata);
|
2022-02-08 20:21:12 +08:00
|
|
|
int (*init_intr)(struct amd_mp2_dev *privdata);
|
2021-06-18 16:18:36 +08:00
|
|
|
};
|
2020-10-10 04:01:36 +08:00
|
|
|
#endif
|