Commit c5567175 authored by Jiri Kosina's avatar Jiri Kosina

Merge branch 'for-5.20/amd-sfh' into for-linus

- support for AMD SOCs using SFH1.1 memory access (Basavaraj Natikar)
parents 1117d182 5d4d0f15
...@@ -9,5 +9,8 @@ amd_sfh-objs := amd_sfh_hid.o ...@@ -9,5 +9,8 @@ amd_sfh-objs := amd_sfh_hid.o
amd_sfh-objs += amd_sfh_client.o amd_sfh-objs += amd_sfh_client.o
amd_sfh-objs += amd_sfh_pcie.o amd_sfh-objs += amd_sfh_pcie.o
amd_sfh-objs += hid_descriptor/amd_sfh_hid_desc.o amd_sfh-objs += hid_descriptor/amd_sfh_hid_desc.o
amd_sfh-objs += sfh1_1/amd_sfh_init.o
amd_sfh-objs += sfh1_1/amd_sfh_interface.o
amd_sfh-objs += sfh1_1/amd_sfh_desc.o
ccflags-y += -I $(srctree)/$(src)/ ccflags-y += -I $(srctree)/$(src)/
...@@ -18,18 +18,6 @@ ...@@ -18,18 +18,6 @@
#include "amd_sfh_pcie.h" #include "amd_sfh_pcie.h"
#include "amd_sfh_hid.h" #include "amd_sfh_hid.h"
struct request_list {
struct hid_device *hid;
struct list_head list;
u8 report_id;
u8 sensor_idx;
u8 report_type;
u8 current_index;
};
static struct request_list req_list;
void amd_sfh_set_report(struct hid_device *hid, int report_id, void amd_sfh_set_report(struct hid_device *hid, int report_id,
int report_type) int report_type)
{ {
...@@ -50,6 +38,7 @@ int amd_sfh_get_report(struct hid_device *hid, int report_id, int report_type) ...@@ -50,6 +38,7 @@ int amd_sfh_get_report(struct hid_device *hid, int report_id, int report_type)
{ {
struct amdtp_hid_data *hid_data = hid->driver_data; struct amdtp_hid_data *hid_data = hid->driver_data;
struct amdtp_cl_data *cli_data = hid_data->cli_data; struct amdtp_cl_data *cli_data = hid_data->cli_data;
struct request_list *req_list = &cli_data->req_list;
int i; int i;
for (i = 0; i < cli_data->num_hid_devices; i++) { for (i = 0; i < cli_data->num_hid_devices; i++) {
...@@ -66,7 +55,7 @@ int amd_sfh_get_report(struct hid_device *hid, int report_id, int report_type) ...@@ -66,7 +55,7 @@ int amd_sfh_get_report(struct hid_device *hid, int report_id, int report_type)
new->report_id = report_id; new->report_id = report_id;
cli_data->report_id[i] = report_id; cli_data->report_id[i] = report_id;
cli_data->request_done[i] = false; cli_data->request_done[i] = false;
list_add(&new->list, &req_list.list); list_add(&new->list, &req_list->list);
break; break;
} }
} }
...@@ -74,16 +63,19 @@ int amd_sfh_get_report(struct hid_device *hid, int report_id, int report_type) ...@@ -74,16 +63,19 @@ int amd_sfh_get_report(struct hid_device *hid, int report_id, int report_type)
return 0; return 0;
} }
static void amd_sfh_work(struct work_struct *work) void amd_sfh_work(struct work_struct *work)
{ {
struct amdtp_cl_data *cli_data = container_of(work, struct amdtp_cl_data, work.work); struct amdtp_cl_data *cli_data = container_of(work, struct amdtp_cl_data, work.work);
struct request_list *req_list = &cli_data->req_list;
struct amd_input_data *in_data = cli_data->in_data; struct amd_input_data *in_data = cli_data->in_data;
struct request_list *req_node; struct request_list *req_node;
u8 current_index, sensor_index; u8 current_index, sensor_index;
struct amd_mp2_ops *mp2_ops;
struct amd_mp2_dev *mp2;
u8 report_id, node_type; u8 report_id, node_type;
u8 report_size = 0; u8 report_size = 0;
req_node = list_last_entry(&req_list.list, struct request_list, list); req_node = list_last_entry(&req_list->list, struct request_list, list);
list_del(&req_node->list); list_del(&req_node->list);
current_index = req_node->current_index; current_index = req_node->current_index;
sensor_index = req_node->sensor_idx; sensor_index = req_node->sensor_idx;
...@@ -91,9 +83,11 @@ static void amd_sfh_work(struct work_struct *work) ...@@ -91,9 +83,11 @@ static void amd_sfh_work(struct work_struct *work)
node_type = req_node->report_type; node_type = req_node->report_type;
kfree(req_node); kfree(req_node);
mp2 = container_of(in_data, struct amd_mp2_dev, in_data);
mp2_ops = mp2->mp2_ops;
if (node_type == HID_FEATURE_REPORT) { if (node_type == HID_FEATURE_REPORT) {
report_size = get_feature_report(sensor_index, report_id, report_size = mp2_ops->get_feat_rep(sensor_index, report_id,
cli_data->feature_report[current_index]); cli_data->feature_report[current_index]);
if (report_size) if (report_size)
hid_input_report(cli_data->hid_sensor_hubs[current_index], hid_input_report(cli_data->hid_sensor_hubs[current_index],
cli_data->report_type[current_index], cli_data->report_type[current_index],
...@@ -102,7 +96,7 @@ static void amd_sfh_work(struct work_struct *work) ...@@ -102,7 +96,7 @@ static void amd_sfh_work(struct work_struct *work)
pr_err("AMDSFH: Invalid report size\n"); pr_err("AMDSFH: Invalid report size\n");
} else if (node_type == HID_INPUT_REPORT) { } else if (node_type == HID_INPUT_REPORT) {
report_size = get_input_report(current_index, sensor_index, report_id, in_data); report_size = mp2_ops->get_in_rep(current_index, sensor_index, report_id, in_data);
if (report_size) if (report_size)
hid_input_report(cli_data->hid_sensor_hubs[current_index], hid_input_report(cli_data->hid_sensor_hubs[current_index],
cli_data->report_type[current_index], cli_data->report_type[current_index],
...@@ -115,17 +109,19 @@ static void amd_sfh_work(struct work_struct *work) ...@@ -115,17 +109,19 @@ static void amd_sfh_work(struct work_struct *work)
amdtp_hid_wakeup(cli_data->hid_sensor_hubs[current_index]); amdtp_hid_wakeup(cli_data->hid_sensor_hubs[current_index]);
} }
static void amd_sfh_work_buffer(struct work_struct *work) void amd_sfh_work_buffer(struct work_struct *work)
{ {
struct amdtp_cl_data *cli_data = container_of(work, struct amdtp_cl_data, work_buffer.work); struct amdtp_cl_data *cli_data = container_of(work, struct amdtp_cl_data, work_buffer.work);
struct amd_input_data *in_data = cli_data->in_data; struct amd_input_data *in_data = cli_data->in_data;
struct amd_mp2_dev *mp2;
u8 report_size; u8 report_size;
int i; int i;
for (i = 0; i < cli_data->num_hid_devices; i++) { for (i = 0; i < cli_data->num_hid_devices; i++) {
if (cli_data->sensor_sts[i] == SENSOR_ENABLED) { if (cli_data->sensor_sts[i] == SENSOR_ENABLED) {
report_size = get_input_report mp2 = container_of(in_data, struct amd_mp2_dev, in_data);
(i, cli_data->sensor_idx[i], cli_data->report_id[i], in_data); report_size = mp2->mp2_ops->get_in_rep(i, cli_data->sensor_idx[i],
cli_data->report_id[i], in_data);
hid_input_report(cli_data->hid_sensor_hubs[i], HID_INPUT_REPORT, hid_input_report(cli_data->hid_sensor_hubs[i], HID_INPUT_REPORT,
in_data->input_report[i], report_size, 0); in_data->input_report[i], report_size, 0);
} }
...@@ -133,7 +129,7 @@ static void amd_sfh_work_buffer(struct work_struct *work) ...@@ -133,7 +129,7 @@ static void amd_sfh_work_buffer(struct work_struct *work)
schedule_delayed_work(&cli_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP)); schedule_delayed_work(&cli_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP));
} }
u32 amd_sfh_wait_for_response(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts) static u32 amd_sfh_wait_for_response(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts)
{ {
if (mp2->mp2_ops->response) if (mp2->mp2_ops->response)
sensor_sts = mp2->mp2_ops->response(mp2, sid, sensor_sts); sensor_sts = mp2->mp2_ops->response(mp2, sid, sensor_sts);
...@@ -141,7 +137,7 @@ u32 amd_sfh_wait_for_response(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts) ...@@ -141,7 +137,7 @@ u32 amd_sfh_wait_for_response(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts)
return sensor_sts; return sensor_sts;
} }
const char *get_sensor_name(int idx) static const char *get_sensor_name(int idx)
{ {
switch (idx) { switch (idx) {
case accel_idx: case accel_idx:
...@@ -159,24 +155,82 @@ const char *get_sensor_name(int idx) ...@@ -159,24 +155,82 @@ const char *get_sensor_name(int idx)
} }
} }
static void amd_sfh_resume(struct amd_mp2_dev *mp2)
{
struct amdtp_cl_data *cl_data = mp2->cl_data;
struct amd_mp2_sensor_info info;
int i, status;
for (i = 0; i < cl_data->num_hid_devices; i++) {
if (cl_data->sensor_sts[i] == SENSOR_DISABLED) {
info.period = AMD_SFH_IDLE_LOOP;
info.sensor_idx = cl_data->sensor_idx[i];
info.dma_address = cl_data->sensor_dma_addr[i];
mp2->mp2_ops->start(mp2, info);
status = amd_sfh_wait_for_response
(mp2, cl_data->sensor_idx[i], SENSOR_ENABLED);
if (status == SENSOR_ENABLED)
cl_data->sensor_sts[i] = SENSOR_ENABLED;
dev_dbg(&mp2->pdev->dev, "resume sid 0x%x (%s) status 0x%x\n",
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
cl_data->sensor_sts[i]);
}
}
schedule_delayed_work(&cl_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP));
amd_sfh_clear_intr(mp2);
}
static void amd_sfh_suspend(struct amd_mp2_dev *mp2)
{
struct amdtp_cl_data *cl_data = mp2->cl_data;
int i, status;
for (i = 0; i < cl_data->num_hid_devices; i++) {
if (cl_data->sensor_idx[i] != HPD_IDX &&
cl_data->sensor_sts[i] == SENSOR_ENABLED) {
mp2->mp2_ops->stop(mp2, cl_data->sensor_idx[i]);
status = amd_sfh_wait_for_response
(mp2, cl_data->sensor_idx[i], SENSOR_DISABLED);
if (status != SENSOR_ENABLED)
cl_data->sensor_sts[i] = SENSOR_DISABLED;
dev_dbg(&mp2->pdev->dev, "suspend sid 0x%x (%s) status 0x%x\n",
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
cl_data->sensor_sts[i]);
}
}
cancel_delayed_work_sync(&cl_data->work_buffer);
amd_sfh_clear_intr(mp2);
}
int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
{ {
struct amd_input_data *in_data = &privdata->in_data; struct amd_input_data *in_data = &privdata->in_data;
struct amdtp_cl_data *cl_data = privdata->cl_data; struct amdtp_cl_data *cl_data = privdata->cl_data;
struct amd_mp2_ops *mp2_ops = privdata->mp2_ops;
struct amd_mp2_sensor_info info; struct amd_mp2_sensor_info info;
struct request_list *req_list;
struct device *dev; struct device *dev;
u32 feature_report_size; u32 feature_report_size;
u32 input_report_size; u32 input_report_size;
int rc, i, status; int rc, i, status;
u8 cl_idx; u8 cl_idx;
req_list = &cl_data->req_list;
dev = &privdata->pdev->dev; dev = &privdata->pdev->dev;
amd_sfh_set_desc_ops(mp2_ops);
mp2_ops->suspend = amd_sfh_suspend;
mp2_ops->resume = amd_sfh_resume;
cl_data->num_hid_devices = amd_mp2_get_sensor_num(privdata, &cl_data->sensor_idx[0]); cl_data->num_hid_devices = amd_mp2_get_sensor_num(privdata, &cl_data->sensor_idx[0]);
if (cl_data->num_hid_devices == 0)
return -ENODEV;
INIT_DELAYED_WORK(&cl_data->work, amd_sfh_work); INIT_DELAYED_WORK(&cl_data->work, amd_sfh_work);
INIT_DELAYED_WORK(&cl_data->work_buffer, amd_sfh_work_buffer); INIT_DELAYED_WORK(&cl_data->work_buffer, amd_sfh_work_buffer);
INIT_LIST_HEAD(&req_list.list); INIT_LIST_HEAD(&req_list->list);
cl_data->in_data = in_data; cl_data->in_data = in_data;
for (i = 0; i < cl_data->num_hid_devices; i++) { for (i = 0; i < cl_data->num_hid_devices; i++) {
...@@ -187,17 +241,17 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) ...@@ -187,17 +241,17 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
cl_data->sensor_requested_cnt[i] = 0; cl_data->sensor_requested_cnt[i] = 0;
cl_data->cur_hid_dev = i; cl_data->cur_hid_dev = i;
cl_idx = cl_data->sensor_idx[i]; cl_idx = cl_data->sensor_idx[i];
cl_data->report_descr_sz[i] = get_descr_sz(cl_idx, descr_size); cl_data->report_descr_sz[i] = mp2_ops->get_desc_sz(cl_idx, descr_size);
if (!cl_data->report_descr_sz[i]) { if (!cl_data->report_descr_sz[i]) {
rc = -EINVAL; rc = -EINVAL;
goto cleanup; goto cleanup;
} }
feature_report_size = get_descr_sz(cl_idx, feature_size); feature_report_size = mp2_ops->get_desc_sz(cl_idx, feature_size);
if (!feature_report_size) { if (!feature_report_size) {
rc = -EINVAL; rc = -EINVAL;
goto cleanup; goto cleanup;
} }
input_report_size = get_descr_sz(cl_idx, input_size); input_report_size = mp2_ops->get_desc_sz(cl_idx, input_size);
if (!input_report_size) { if (!input_report_size) {
rc = -EINVAL; rc = -EINVAL;
goto cleanup; goto cleanup;
...@@ -222,17 +276,17 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) ...@@ -222,17 +276,17 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
rc = -ENOMEM; rc = -ENOMEM;
goto cleanup; goto cleanup;
} }
rc = get_report_descriptor(cl_idx, cl_data->report_descr[i]); rc = mp2_ops->get_rep_desc(cl_idx, cl_data->report_descr[i]);
if (rc) if (rc)
return rc; return rc;
privdata->mp2_ops->start(privdata, info); mp2_ops->start(privdata, info);
status = amd_sfh_wait_for_response status = amd_sfh_wait_for_response
(privdata, cl_data->sensor_idx[i], SENSOR_ENABLED); (privdata, cl_data->sensor_idx[i], SENSOR_ENABLED);
if (status == SENSOR_ENABLED) { if (status == SENSOR_ENABLED) {
cl_data->sensor_sts[i] = SENSOR_ENABLED; cl_data->sensor_sts[i] = SENSOR_ENABLED;
rc = amdtp_hid_probe(cl_data->cur_hid_dev, cl_data); rc = amdtp_hid_probe(cl_data->cur_hid_dev, cl_data);
if (rc) { if (rc) {
privdata->mp2_ops->stop(privdata, cl_data->sensor_idx[i]); mp2_ops->stop(privdata, cl_data->sensor_idx[i]);
status = amd_sfh_wait_for_response status = amd_sfh_wait_for_response
(privdata, cl_data->sensor_idx[i], SENSOR_DISABLED); (privdata, cl_data->sensor_idx[i], SENSOR_DISABLED);
if (status != SENSOR_ENABLED) if (status != SENSOR_ENABLED)
...@@ -248,8 +302,7 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) ...@@ -248,8 +302,7 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]), cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
cl_data->sensor_sts[i]); cl_data->sensor_sts[i]);
} }
if (privdata->mp2_ops->discovery_status && if (mp2_ops->discovery_status && mp2_ops->discovery_status(privdata) == 0) {
privdata->mp2_ops->discovery_status(privdata) == 0) {
amd_sfh_hid_client_deinit(privdata); amd_sfh_hid_client_deinit(privdata);
for (i = 0; i < cl_data->num_hid_devices; i++) { for (i = 0; i < cl_data->num_hid_devices; i++) {
devm_kfree(dev, cl_data->feature_report[i]); devm_kfree(dev, cl_data->feature_report[i]);
......
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* AMD MP2 common macros and structures
*
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* All Rights Reserved.
*
* Author: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
*/
#ifndef AMD_SFH_COMMON_H
#define AMD_SFH_COMMON_H
#include <linux/pci.h>
#include "amd_sfh_hid.h"
#define PCI_DEVICE_ID_AMD_MP2 0x15E4
#define PCI_DEVICE_ID_AMD_MP2_1_1 0x164A
#define AMD_C2P_MSG(regno) (0x10500 + ((regno) * 4))
#define AMD_P2C_MSG(regno) (0x10680 + ((regno) * 4))
#define SENSOR_ENABLED 4
#define SENSOR_DISABLED 5
#define AMD_SFH_IDLE_LOOP 200
enum cmd_id {
NO_OP,
ENABLE_SENSOR,
DISABLE_SENSOR,
STOP_ALL_SENSORS = 8,
};
struct amd_mp2_sensor_info {
u8 sensor_idx;
u32 period;
dma_addr_t dma_address;
};
struct amd_mp2_dev {
struct pci_dev *pdev;
struct amdtp_cl_data *cl_data;
void __iomem *mmio;
void __iomem *vsbase;
const struct amd_sfh1_1_ops *sfh1_1_ops;
struct amd_mp2_ops *mp2_ops;
struct amd_input_data in_data;
/* mp2 active control status */
u32 mp2_acs;
};
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);
int (*response)(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts);
void (*clear_intr)(struct amd_mp2_dev *privdata);
int (*init_intr)(struct amd_mp2_dev *privdata);
int (*discovery_status)(struct amd_mp2_dev *privdata);
void (*suspend)(struct amd_mp2_dev *mp2);
void (*resume)(struct amd_mp2_dev *mp2);
void (*remove)(void *privdata);
int (*get_rep_desc)(int sensor_idx, u8 rep_desc[]);
u32 (*get_desc_sz)(int sensor_idx, int descriptor_name);
u8 (*get_feat_rep)(int sensor_idx, int report_id, u8 *feature_report);
u8 (*get_in_rep)(u8 current_index, int sensor_idx, int report_id,
struct amd_input_data *in_data);
};
void amd_sfh_work(struct work_struct *work);
void amd_sfh_work_buffer(struct work_struct *work);
void amd_sfh_clear_intr_v2(struct amd_mp2_dev *privdata);
int amd_sfh_irq_init_v2(struct amd_mp2_dev *privdata);
void amd_sfh_clear_intr(struct amd_mp2_dev *privdata);
int amd_sfh_irq_init(struct amd_mp2_dev *privdata);
#endif
...@@ -101,11 +101,15 @@ static int amdtp_wait_for_response(struct hid_device *hid) ...@@ -101,11 +101,15 @@ static int amdtp_wait_for_response(struct hid_device *hid)
void amdtp_hid_wakeup(struct hid_device *hid) void amdtp_hid_wakeup(struct hid_device *hid)
{ {
struct amdtp_hid_data *hid_data = hid->driver_data; struct amdtp_hid_data *hid_data;
struct amdtp_cl_data *cli_data = hid_data->cli_data; struct amdtp_cl_data *cli_data;
cli_data->request_done[cli_data->cur_hid_dev] = true; if (hid) {
wake_up_interruptible(&hid_data->hid_wait); hid_data = hid->driver_data;
cli_data = hid_data->cli_data;
cli_data->request_done[cli_data->cur_hid_dev] = true;
wake_up_interruptible(&hid_data->hid_wait);
}
} }
static struct hid_ll_driver amdtp_hid_ll_driver = { static struct hid_ll_driver amdtp_hid_ll_driver = {
......
...@@ -15,6 +15,15 @@ ...@@ -15,6 +15,15 @@
#define AMD_SFH_HID_VENDOR 0x1022 #define AMD_SFH_HID_VENDOR 0x1022
#define AMD_SFH_HID_PRODUCT 0x0001 #define AMD_SFH_HID_PRODUCT 0x0001
struct request_list {
struct hid_device *hid;
struct list_head list;
u8 report_id;
u8 sensor_idx;
u8 report_type;
u8 current_index;
};
struct amd_input_data { struct amd_input_data {
u32 *sensor_virt_addr[MAX_HID_DEVICES]; u32 *sensor_virt_addr[MAX_HID_DEVICES];
u8 *input_report[MAX_HID_DEVICES]; u8 *input_report[MAX_HID_DEVICES];
...@@ -43,6 +52,7 @@ struct amdtp_cl_data { ...@@ -43,6 +52,7 @@ struct amdtp_cl_data {
struct amd_input_data *in_data; struct amd_input_data *in_data;
struct delayed_work work; struct delayed_work work;
struct delayed_work work_buffer; struct delayed_work work_buffer;
struct request_list req_list;
}; };
/** /**
...@@ -69,6 +79,4 @@ void amdtp_hid_remove(struct amdtp_cl_data *cli_data); ...@@ -69,6 +79,4 @@ void amdtp_hid_remove(struct amdtp_cl_data *cli_data);
int amd_sfh_get_report(struct hid_device *hid, int report_id, int report_type); int amd_sfh_get_report(struct hid_device *hid, int report_id, int report_type);
void amd_sfh_set_report(struct hid_device *hid, int report_id, int report_type); void amd_sfh_set_report(struct hid_device *hid, int report_id, int report_type);
void amdtp_hid_wakeup(struct hid_device *hid); void amdtp_hid_wakeup(struct hid_device *hid);
u8 get_input_report(u8 current_index, int sensor_idx, int report_id,
struct amd_input_data *in_data);
#endif #endif
...@@ -19,6 +19,7 @@ ...@@ -19,6 +19,7 @@
#include <linux/slab.h> #include <linux/slab.h>
#include "amd_sfh_pcie.h" #include "amd_sfh_pcie.h"
#include "sfh1_1/amd_sfh_init.h"
#define DRIVER_NAME "pcie_mp2_amd" #define DRIVER_NAME "pcie_mp2_amd"
#define DRIVER_DESC "AMD(R) PCIe MP2 Communication Driver" #define DRIVER_DESC "AMD(R) PCIe MP2 Communication Driver"
...@@ -92,7 +93,7 @@ static void amd_stop_all_sensor_v2(struct amd_mp2_dev *privdata) ...@@ -92,7 +93,7 @@ static void amd_stop_all_sensor_v2(struct amd_mp2_dev *privdata)
writel(cmd_base.ul, privdata->mmio + AMD_C2P_MSG0); writel(cmd_base.ul, privdata->mmio + AMD_C2P_MSG0);
} }
static void amd_sfh_clear_intr_v2(struct amd_mp2_dev *privdata) void amd_sfh_clear_intr_v2(struct amd_mp2_dev *privdata)
{ {
if (readl(privdata->mmio + AMD_P2C_MSG(4))) { if (readl(privdata->mmio + AMD_P2C_MSG(4))) {
writel(0, privdata->mmio + AMD_P2C_MSG(4)); writel(0, privdata->mmio + AMD_P2C_MSG(4));
...@@ -100,7 +101,7 @@ static void amd_sfh_clear_intr_v2(struct amd_mp2_dev *privdata) ...@@ -100,7 +101,7 @@ static void amd_sfh_clear_intr_v2(struct amd_mp2_dev *privdata)
} }
} }
static void amd_sfh_clear_intr(struct amd_mp2_dev *privdata) void amd_sfh_clear_intr(struct amd_mp2_dev *privdata)
{ {
if (privdata->mp2_ops->clear_intr) if (privdata->mp2_ops->clear_intr)
privdata->mp2_ops->clear_intr(privdata); privdata->mp2_ops->clear_intr(privdata);
...@@ -113,7 +114,7 @@ static irqreturn_t amd_sfh_irq_handler(int irq, void *data) ...@@ -113,7 +114,7 @@ static irqreturn_t amd_sfh_irq_handler(int irq, void *data)
return IRQ_HANDLED; return IRQ_HANDLED;
} }
static int amd_sfh_irq_init_v2(struct amd_mp2_dev *privdata) int amd_sfh_irq_init_v2(struct amd_mp2_dev *privdata)
{ {
int rc; int rc;
...@@ -136,7 +137,7 @@ static int amd_sfh_dis_sts_v2(struct amd_mp2_dev *privdata) ...@@ -136,7 +137,7 @@ static int amd_sfh_dis_sts_v2(struct amd_mp2_dev *privdata)
SENSOR_DISCOVERY_STATUS_MASK) >> SENSOR_DISCOVERY_STATUS_SHIFT; SENSOR_DISCOVERY_STATUS_MASK) >> SENSOR_DISCOVERY_STATUS_SHIFT;
} }
void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info) static void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info)
{ {
union sfh_cmd_param cmd_param; union sfh_cmd_param cmd_param;
union sfh_cmd_base cmd_base; union sfh_cmd_base cmd_base;
...@@ -157,7 +158,7 @@ void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info i ...@@ -157,7 +158,7 @@ void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info i
writel(cmd_base.ul, privdata->mmio + AMD_C2P_MSG0); writel(cmd_base.ul, privdata->mmio + AMD_C2P_MSG0);
} }
void amd_stop_sensor(struct amd_mp2_dev *privdata, u16 sensor_idx) static void amd_stop_sensor(struct amd_mp2_dev *privdata, u16 sensor_idx)
{ {
union sfh_cmd_base cmd_base; union sfh_cmd_base cmd_base;
...@@ -171,7 +172,7 @@ void amd_stop_sensor(struct amd_mp2_dev *privdata, u16 sensor_idx) ...@@ -171,7 +172,7 @@ void amd_stop_sensor(struct amd_mp2_dev *privdata, u16 sensor_idx)
writel(cmd_base.ul, privdata->mmio + AMD_C2P_MSG0); writel(cmd_base.ul, privdata->mmio + AMD_C2P_MSG0);
} }
void amd_stop_all_sensors(struct amd_mp2_dev *privdata) static void amd_stop_all_sensors(struct amd_mp2_dev *privdata)
{ {
union sfh_cmd_base cmd_base; union sfh_cmd_base cmd_base;
...@@ -244,7 +245,7 @@ static void amd_mp2_pci_remove(void *privdata) ...@@ -244,7 +245,7 @@ static void amd_mp2_pci_remove(void *privdata)
amd_sfh_clear_intr(mp2); amd_sfh_clear_intr(mp2);
} }
static const struct amd_mp2_ops amd_sfh_ops_v2 = { static struct amd_mp2_ops amd_sfh_ops_v2 = {
.start = amd_start_sensor_v2, .start = amd_start_sensor_v2,
.stop = amd_stop_sensor_v2, .stop = amd_stop_sensor_v2,
.stop_all = amd_stop_all_sensor_v2, .stop_all = amd_stop_all_sensor_v2,
...@@ -252,12 +253,14 @@ static const struct amd_mp2_ops amd_sfh_ops_v2 = { ...@@ -252,12 +253,14 @@ static const struct amd_mp2_ops amd_sfh_ops_v2 = {
.clear_intr = amd_sfh_clear_intr_v2, .clear_intr = amd_sfh_clear_intr_v2,
.init_intr = amd_sfh_irq_init_v2, .init_intr = amd_sfh_irq_init_v2,
.discovery_status = amd_sfh_dis_sts_v2, .discovery_status = amd_sfh_dis_sts_v2,
.remove = amd_mp2_pci_remove,
}; };
static const struct amd_mp2_ops amd_sfh_ops = { static struct amd_mp2_ops amd_sfh_ops = {
.start = amd_start_sensor, .start = amd_start_sensor,
.stop = amd_stop_sensor, .stop = amd_stop_sensor,
.stop_all = amd_stop_all_sensors, .stop_all = amd_stop_all_sensors,
.remove = amd_mp2_pci_remove,
}; };
static void mp2_select_ops(struct amd_mp2_dev *privdata) static void mp2_select_ops(struct amd_mp2_dev *privdata)
...@@ -277,7 +280,7 @@ static void mp2_select_ops(struct amd_mp2_dev *privdata) ...@@ -277,7 +280,7 @@ static void mp2_select_ops(struct amd_mp2_dev *privdata)
} }
} }
static int amd_sfh_irq_init(struct amd_mp2_dev *privdata) int amd_sfh_irq_init(struct amd_mp2_dev *privdata)
{ {
if (privdata->mp2_ops->init_intr) if (privdata->mp2_ops->init_intr)
return privdata->mp2_ops->init_intr(privdata); return privdata->mp2_ops->init_intr(privdata);
...@@ -316,6 +319,14 @@ static int amd_mp2_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i ...@@ -316,6 +319,14 @@ static int amd_mp2_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i
if (!privdata->cl_data) if (!privdata->cl_data)
return -ENOMEM; return -ENOMEM;
privdata->sfh1_1_ops = (const struct amd_sfh1_1_ops *)id->driver_data;
if (privdata->sfh1_1_ops) {
rc = privdata->sfh1_1_ops->init(privdata);
if (rc)
return rc;
goto init_done;
}
mp2_select_ops(privdata); mp2_select_ops(privdata);
rc = amd_sfh_irq_init(privdata); rc = amd_sfh_irq_init(privdata);
...@@ -332,36 +343,17 @@ static int amd_mp2_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i ...@@ -332,36 +343,17 @@ static int amd_mp2_pci_probe(struct pci_dev *pdev, const struct pci_device_id *i
return rc; return rc;
} }
init_done:
amd_sfh_clear_intr(privdata); amd_sfh_clear_intr(privdata);
return devm_add_action_or_reset(&pdev->dev, amd_mp2_pci_remove, privdata); return devm_add_action_or_reset(&pdev->dev, privdata->mp2_ops->remove, privdata);
} }
static int __maybe_unused amd_mp2_pci_resume(struct device *dev) static int __maybe_unused amd_mp2_pci_resume(struct device *dev)
{ {
struct amd_mp2_dev *mp2 = dev_get_drvdata(dev); struct amd_mp2_dev *mp2 = dev_get_drvdata(dev);
struct amdtp_cl_data *cl_data = mp2->cl_data;
struct amd_mp2_sensor_info info;
int i, status;
for (i = 0; i < cl_data->num_hid_devices; i++) {
if (cl_data->sensor_sts[i] == SENSOR_DISABLED) {
info.period = AMD_SFH_IDLE_LOOP;
info.sensor_idx = cl_data->sensor_idx[i];
info.dma_address = cl_data->sensor_dma_addr[i];
mp2->mp2_ops->start(mp2, info);
status = amd_sfh_wait_for_response
(mp2, cl_data->sensor_idx[i], SENSOR_ENABLED);
if (status == SENSOR_ENABLED)
cl_data->sensor_sts[i] = SENSOR_ENABLED;
dev_dbg(dev, "suspend sid 0x%x (%s) status 0x%x\n",
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
cl_data->sensor_sts[i]);
}
}
schedule_delayed_work(&cl_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP)); mp2->mp2_ops->resume(mp2);
amd_sfh_clear_intr(mp2);
return 0; return 0;
} }
...@@ -369,25 +361,8 @@ static int __maybe_unused amd_mp2_pci_resume(struct device *dev) ...@@ -369,25 +361,8 @@ static int __maybe_unused amd_mp2_pci_resume(struct device *dev)
static int __maybe_unused amd_mp2_pci_suspend(struct device *dev) static int __maybe_unused amd_mp2_pci_suspend(struct device *dev)
{ {
struct amd_mp2_dev *mp2 = dev_get_drvdata(dev); struct amd_mp2_dev *mp2 = dev_get_drvdata(dev);
struct amdtp_cl_data *cl_data = mp2->cl_data;
int i, status;
for (i = 0; i < cl_data->num_hid_devices; i++) {
if (cl_data->sensor_idx[i] != HPD_IDX &&
cl_data->sensor_sts[i] == SENSOR_ENABLED) {
mp2->mp2_ops->stop(mp2, cl_data->sensor_idx[i]);
status = amd_sfh_wait_for_response
(mp2, cl_data->sensor_idx[i], SENSOR_DISABLED);
if (status != SENSOR_ENABLED)
cl_data->sensor_sts[i] = SENSOR_DISABLED;
dev_dbg(dev, "suspend sid 0x%x (%s) status 0x%x\n",
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
cl_data->sensor_sts[i]);
}
}
cancel_delayed_work_sync(&cl_data->work_buffer); mp2->mp2_ops->suspend(mp2);
amd_sfh_clear_intr(mp2);
return 0; return 0;
} }
...@@ -397,6 +372,8 @@ static SIMPLE_DEV_PM_OPS(amd_mp2_pm_ops, amd_mp2_pci_suspend, ...@@ -397,6 +372,8 @@ static SIMPLE_DEV_PM_OPS(amd_mp2_pm_ops, amd_mp2_pci_suspend,
static const struct pci_device_id amd_mp2_pci_tbl[] = { static const struct pci_device_id amd_mp2_pci_tbl[] = {
{ PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_MP2) }, { PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_MP2) },
{ PCI_VDEVICE(AMD, PCI_DEVICE_ID_AMD_MP2_1_1),
.driver_data = (kernel_ulong_t)&sfh1_1_ops },
{ } { }
}; };
MODULE_DEVICE_TABLE(pci, amd_mp2_pci_tbl); MODULE_DEVICE_TABLE(pci, amd_mp2_pci_tbl);
......
...@@ -10,35 +10,20 @@ ...@@ -10,35 +10,20 @@
#ifndef PCIE_MP2_AMD_H #ifndef PCIE_MP2_AMD_H
#define PCIE_MP2_AMD_H #define PCIE_MP2_AMD_H
#include <linux/pci.h> #include "amd_sfh_common.h"
#include "amd_sfh_hid.h"
#define PCI_DEVICE_ID_AMD_MP2 0x15E4
#define ENABLE_SENSOR 1
#define DISABLE_SENSOR 2
#define STOP_ALL_SENSORS 8
/* MP2 C2P Message Registers */ /* MP2 C2P Message Registers */
#define AMD_C2P_MSG0 0x10500 #define AMD_C2P_MSG0 0x10500
#define AMD_C2P_MSG1 0x10504 #define AMD_C2P_MSG1 0x10504
#define AMD_C2P_MSG2 0x10508 #define AMD_C2P_MSG2 0x10508
#define AMD_C2P_MSG(regno) (0x10500 + ((regno) * 4))
#define AMD_P2C_MSG(regno) (0x10680 + ((regno) * 4))
/* MP2 P2C Message Registers */ /* MP2 P2C Message Registers */
#define AMD_P2C_MSG3 0x1068C /* Supported Sensors info */ #define AMD_P2C_MSG3 0x1068C /* Supported Sensors info */
#define V2_STATUS 0x2 #define V2_STATUS 0x2
#define SENSOR_ENABLED 4
#define SENSOR_DISABLED 5
#define HPD_IDX 16 #define HPD_IDX 16
#define AMD_SFH_IDLE_LOOP 200
#define SENSOR_DISCOVERY_STATUS_MASK GENMASK(5, 3) #define SENSOR_DISCOVERY_STATUS_MASK GENMASK(5, 3)
#define SENSOR_DISCOVERY_STATUS_SHIFT 3 #define SENSOR_DISCOVERY_STATUS_SHIFT 3
...@@ -96,22 +81,6 @@ enum sensor_idx { ...@@ -96,22 +81,6 @@ enum sensor_idx {
als_idx = 19 als_idx = 19
}; };
struct amd_mp2_dev {
struct pci_dev *pdev;
struct amdtp_cl_data *cl_data;
void __iomem *mmio;
const struct amd_mp2_ops *mp2_ops;
struct amd_input_data in_data;
/* mp2 active control status */
u32 mp2_acs;
};
struct amd_mp2_sensor_info {
u8 sensor_idx;
u32 period;
dma_addr_t dma_address;
};
enum mem_use_type { enum mem_use_type {
USE_DRAM, USE_DRAM,
USE_C2P_REG, USE_C2P_REG,
...@@ -129,24 +98,9 @@ struct hpd_status { ...@@ -129,24 +98,9 @@ struct hpd_status {
}; };
}; };
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_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_init(struct amd_mp2_dev *privdata);
int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata); int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata);
u32 amd_sfh_wait_for_response(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts); void amd_sfh_set_desc_ops(struct amd_mp2_ops *mp2_ops);
void amd_mp2_suspend(struct amd_mp2_dev *mp2);
void amd_mp2_resume(struct amd_mp2_dev *mp2);
const char *get_sensor_name(int idx);
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);
int (*response)(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts);
void (*clear_intr)(struct amd_mp2_dev *privdata);
int (*init_intr)(struct amd_mp2_dev *privdata);
int (*discovery_status)(struct amd_mp2_dev *privdata);
};
#endif #endif
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#define HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM 0x04 #define HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM 0x04
#define ILLUMINANCE_MASK GENMASK(14, 0) #define ILLUMINANCE_MASK GENMASK(14, 0)
int get_report_descriptor(int sensor_idx, u8 *rep_desc) static int get_report_descriptor(int sensor_idx, u8 *rep_desc)
{ {
switch (sensor_idx) { switch (sensor_idx) {
case accel_idx: /* accel */ case accel_idx: /* accel */
...@@ -63,7 +63,7 @@ int get_report_descriptor(int sensor_idx, u8 *rep_desc) ...@@ -63,7 +63,7 @@ int get_report_descriptor(int sensor_idx, u8 *rep_desc)
return 0; return 0;
} }
u32 get_descr_sz(int sensor_idx, int descriptor_name) static u32 get_descr_sz(int sensor_idx, int descriptor_name)
{ {
switch (sensor_idx) { switch (sensor_idx) {
case accel_idx: case accel_idx:
...@@ -133,7 +133,7 @@ static void get_common_features(struct common_feature_property *common, int repo ...@@ -133,7 +133,7 @@ static void get_common_features(struct common_feature_property *common, int repo
common->report_interval = HID_DEFAULT_REPORT_INTERVAL; common->report_interval = HID_DEFAULT_REPORT_INTERVAL;
} }
u8 get_feature_report(int sensor_idx, int report_id, u8 *feature_report) static u8 get_feature_report(int sensor_idx, int report_id, u8 *feature_report)
{ {
struct accel3_feature_report acc_feature; struct accel3_feature_report acc_feature;
struct gyro_feature_report gyro_feature; struct gyro_feature_report gyro_feature;
...@@ -200,7 +200,8 @@ static void get_common_inputs(struct common_input_property *common, int report_i ...@@ -200,7 +200,8 @@ static void get_common_inputs(struct common_input_property *common, int report_i
common->event_type = HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM; common->event_type = HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM;
} }
u8 get_input_report(u8 current_index, int sensor_idx, int report_id, struct amd_input_data *in_data) static u8 get_input_report(u8 current_index, int sensor_idx, int report_id,
struct amd_input_data *in_data)
{ {
struct amd_mp2_dev *privdata = container_of(in_data, struct amd_mp2_dev, in_data); struct amd_mp2_dev *privdata = container_of(in_data, struct amd_mp2_dev, in_data);
u32 *sensor_virt_addr = in_data->sensor_virt_addr[current_index]; u32 *sensor_virt_addr = in_data->sensor_virt_addr[current_index];
...@@ -267,3 +268,11 @@ u8 get_input_report(u8 current_index, int sensor_idx, int report_id, struct amd_ ...@@ -267,3 +268,11 @@ u8 get_input_report(u8 current_index, int sensor_idx, int report_id, struct amd_
} }
return report_size; return report_size;
} }
void amd_sfh_set_desc_ops(struct amd_mp2_ops *mp2_ops)
{
mp2_ops->get_rep_desc = get_report_descriptor;
mp2_ops->get_feat_rep = get_feature_report;
mp2_ops->get_in_rep = get_input_report;
mp2_ops->get_desc_sz = get_descr_sz;
}
...@@ -111,7 +111,4 @@ struct hpd_input_report { ...@@ -111,7 +111,4 @@ struct hpd_input_report {
u8 human_presence; u8 human_presence;
} __packed; } __packed;
int get_report_descriptor(int sensor_idx, u8 rep_desc[]);
u32 get_descr_sz(int sensor_idx, int descriptor_name);
u8 get_feature_report(int sensor_idx, int report_id, u8 *feature_report);
#endif #endif
This diff is collapsed.
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* AMD MP2 1.1 communication driver
*
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* All Rights Reserved.
*
* Author: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
*/
#include <linux/delay.h>
#include <linux/hid.h>
#include "amd_sfh_init.h"
#include "amd_sfh_interface.h"
#include "../hid_descriptor/amd_sfh_hid_desc.h"
static int amd_sfh_get_sensor_num(struct amd_mp2_dev *mp2, u8 *sensor_id)
{
struct sfh_sensor_list *slist;
struct sfh_base_info binfo;
int num_of_sensors = 0;
int i;
memcpy_fromio(&binfo, mp2->vsbase, sizeof(struct sfh_base_info));
slist = &binfo.sbase.s_list;
for (i = 0; i < MAX_IDX; i++) {
switch (i) {
case ACCEL_IDX:
case GYRO_IDX:
case MAG_IDX:
case ALS_IDX:
case HPD_IDX:
if (BIT(i) & slist->sl.sensors)
sensor_id[num_of_sensors++] = i;
break;
}
}
return num_of_sensors;
}
static u32 amd_sfh_wait_for_response(struct amd_mp2_dev *mp2, u8 sid, u32 cmd_id)
{
if (mp2->mp2_ops->response)
return mp2->mp2_ops->response(mp2, sid, cmd_id);
return 0;
}
static const char *get_sensor_name(int idx)
{
switch (idx) {
case ACCEL_IDX:
return "accelerometer";
case GYRO_IDX:
return "gyroscope";
case MAG_IDX:
return "magnetometer";
case ALS_IDX:
return "ALS";
case HPD_IDX:
return "HPD";
default:
return "unknown sensor type";
}
}
static int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata)
{
struct amdtp_cl_data *cl_data = privdata->cl_data;
int i, status;
for (i = 0; i < cl_data->num_hid_devices; i++) {
if (cl_data->sensor_sts[i] == SENSOR_ENABLED) {
privdata->mp2_ops->stop(privdata, cl_data->sensor_idx[i]);
status = amd_sfh_wait_for_response
(privdata, cl_data->sensor_idx[i], DISABLE_SENSOR);
if (status == 0)
cl_data->sensor_sts[i] = SENSOR_DISABLED;
dev_dbg(&privdata->pdev->dev, "stopping sid 0x%x (%s) status 0x%x\n",
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
cl_data->sensor_sts[i]);
}
}
cancel_delayed_work_sync(&cl_data->work);
cancel_delayed_work_sync(&cl_data->work_buffer);
amdtp_hid_remove(cl_data);
return 0;
}
static int amd_sfh1_1_hid_client_init(struct amd_mp2_dev *privdata)
{
struct amd_input_data *in_data = &privdata->in_data;
struct amdtp_cl_data *cl_data = privdata->cl_data;
struct amd_mp2_ops *mp2_ops = privdata->mp2_ops;
struct amd_mp2_sensor_info info;
struct request_list *req_list;
u32 feature_report_size;
u32 input_report_size;
struct device *dev;
int rc, i, status;
u8 cl_idx;
req_list = &cl_data->req_list;
dev = &privdata->pdev->dev;
amd_sfh1_1_set_desc_ops(mp2_ops);
cl_data->num_hid_devices = amd_sfh_get_sensor_num(privdata, &cl_data->sensor_idx[0]);
INIT_DELAYED_WORK(&cl_data->work, amd_sfh_work);
INIT_DELAYED_WORK(&cl_data->work_buffer, amd_sfh_work_buffer);
INIT_LIST_HEAD(&req_list->list);
cl_data->in_data = in_data;
for (i = 0; i < cl_data->num_hid_devices; i++) {
cl_data->sensor_sts[i] = SENSOR_DISABLED;
cl_data->sensor_requested_cnt[i] = 0;
cl_data->cur_hid_dev = i;
cl_idx = cl_data->sensor_idx[i];
cl_data->report_descr_sz[i] = mp2_ops->get_desc_sz(cl_idx, descr_size);
if (!cl_data->report_descr_sz[i]) {
rc = -EINVAL;
goto cleanup;
}
feature_report_size = mp2_ops->get_desc_sz(cl_idx, feature_size);
if (!feature_report_size) {
rc = -EINVAL;
goto cleanup;
}
input_report_size = mp2_ops->get_desc_sz(cl_idx, input_size);
if (!input_report_size) {
rc = -EINVAL;
goto cleanup;
}
cl_data->feature_report[i] = devm_kzalloc(dev, feature_report_size, GFP_KERNEL);
if (!cl_data->feature_report[i]) {
rc = -ENOMEM;
goto cleanup;
}
in_data->input_report[i] = devm_kzalloc(dev, input_report_size, GFP_KERNEL);
if (!in_data->input_report[i]) {
rc = -ENOMEM;
goto cleanup;
}
info.sensor_idx = cl_idx;
cl_data->report_descr[i] =
devm_kzalloc(dev, cl_data->report_descr_sz[i], GFP_KERNEL);
if (!cl_data->report_descr[i]) {
rc = -ENOMEM;
goto cleanup;
}
rc = mp2_ops->get_rep_desc(cl_idx, cl_data->report_descr[i]);
if (rc)
return rc;
writel(0, privdata->mmio + AMD_P2C_MSG(0));
mp2_ops->start(privdata, info);
status = amd_sfh_wait_for_response
(privdata, cl_data->sensor_idx[i], ENABLE_SENSOR);
status = (status == 0) ? SENSOR_ENABLED : SENSOR_DISABLED;
if (status == SENSOR_ENABLED) {
cl_data->sensor_sts[i] = SENSOR_ENABLED;
rc = amdtp_hid_probe(i, cl_data);
if (rc) {
mp2_ops->stop(privdata, cl_data->sensor_idx[i]);
status = amd_sfh_wait_for_response
(privdata, cl_data->sensor_idx[i], DISABLE_SENSOR);
if (status == 0)
status = SENSOR_DISABLED;
if (status != SENSOR_ENABLED)
cl_data->sensor_sts[i] = SENSOR_DISABLED;
dev_dbg(dev, "sid 0x%x (%s) status 0x%x\n",
cl_data->sensor_idx[i],
get_sensor_name(cl_data->sensor_idx[i]),
cl_data->sensor_sts[i]);
goto cleanup;
}
}
dev_dbg(dev, "sid 0x%x (%s) status 0x%x\n",
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
cl_data->sensor_sts[i]);
}
schedule_delayed_work(&cl_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP));
return 0;
cleanup:
amd_sfh_hid_client_deinit(privdata);
for (i = 0; i < cl_data->num_hid_devices; i++) {
devm_kfree(dev, cl_data->feature_report[i]);
devm_kfree(dev, in_data->input_report[i]);
devm_kfree(dev, cl_data->report_descr[i]);
}
return rc;
}
static void amd_sfh_resume(struct amd_mp2_dev *mp2)
{
struct amdtp_cl_data *cl_data = mp2->cl_data;
struct amd_mp2_sensor_info info;
int i, status;
for (i = 0; i < cl_data->num_hid_devices; i++) {
if (cl_data->sensor_sts[i] == SENSOR_DISABLED) {
info.sensor_idx = cl_data->sensor_idx[i];
mp2->mp2_ops->start(mp2, info);
status = amd_sfh_wait_for_response
(mp2, cl_data->sensor_idx[i], ENABLE_SENSOR);
if (status == 0)
status = SENSOR_ENABLED;
if (status == SENSOR_ENABLED)
cl_data->sensor_sts[i] = SENSOR_ENABLED;
dev_dbg(&mp2->pdev->dev, "resume sid 0x%x (%s) status 0x%x\n",
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
cl_data->sensor_sts[i]);
}
}
schedule_delayed_work(&cl_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP));
amd_sfh_clear_intr(mp2);
}
static void amd_sfh_suspend(struct amd_mp2_dev *mp2)
{
struct amdtp_cl_data *cl_data = mp2->cl_data;
int i, status;
for (i = 0; i < cl_data->num_hid_devices; i++) {
if (cl_data->sensor_idx[i] != HPD_IDX &&
cl_data->sensor_sts[i] == SENSOR_ENABLED) {
mp2->mp2_ops->stop(mp2, cl_data->sensor_idx[i]);
status = amd_sfh_wait_for_response
(mp2, cl_data->sensor_idx[i], DISABLE_SENSOR);
if (status == 0)
status = SENSOR_DISABLED;
if (status != SENSOR_ENABLED)
cl_data->sensor_sts[i] = SENSOR_DISABLED;
dev_dbg(&mp2->pdev->dev, "suspend sid 0x%x (%s) status 0x%x\n",
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
cl_data->sensor_sts[i]);
}
}
cancel_delayed_work_sync(&cl_data->work_buffer);
amd_sfh_clear_intr(mp2);
}
static void amd_mp2_pci_remove(void *privdata)
{
struct amd_mp2_dev *mp2 = privdata;
amd_sfh_hid_client_deinit(privdata);
mp2->mp2_ops->stop_all(mp2);
pci_intx(mp2->pdev, false);
amd_sfh_clear_intr(mp2);
}
static void amd_sfh_set_ops(struct amd_mp2_dev *mp2)
{
struct amd_mp2_ops *mp2_ops;
sfh_interface_init(mp2);
mp2_ops = mp2->mp2_ops;
mp2_ops->clear_intr = amd_sfh_clear_intr_v2,
mp2_ops->init_intr = amd_sfh_irq_init_v2,
mp2_ops->suspend = amd_sfh_suspend;
mp2_ops->resume = amd_sfh_resume;
mp2_ops->remove = amd_mp2_pci_remove;
}
int amd_sfh1_1_init(struct amd_mp2_dev *mp2)
{
u32 phy_base = readl(mp2->mmio + AMD_C2P_MSG(22));
struct device *dev = &mp2->pdev->dev;
struct sfh_base_info binfo;
int rc;
phy_base <<= 21;
if (!devm_request_mem_region(dev, phy_base, 128 * 1024, "amd_sfh")) {
dev_err(dev, "can't reserve mmio registers\n");
return -ENOMEM;
}
mp2->vsbase = devm_ioremap(dev, phy_base, 128 * 1024);
if (!mp2->vsbase) {
dev_err(dev, "failed to remap vsbase\n");
return -ENOMEM;
}
/* Before accessing give time for SFH firmware for processing configuration */
msleep(5000);
memcpy_fromio(&binfo, mp2->vsbase, sizeof(struct sfh_base_info));
if (binfo.sbase.fw_info.fw_ver == 0 || binfo.sbase.s_list.sl.sensors == 0) {
dev_err(dev, "failed to get sensors\n");
return -EOPNOTSUPP;
}
dev_dbg(dev, "firmware version 0x%x\n", binfo.sbase.fw_info.fw_ver);
amd_sfh_set_ops(mp2);
rc = amd_sfh_irq_init(mp2);
if (rc) {
dev_err(dev, "amd_sfh_irq_init failed\n");
return rc;
}
rc = amd_sfh1_1_hid_client_init(mp2);
if (rc) {
dev_err(dev, "amd_sfh1_1_hid_client_init failed\n");
return rc;
}
return rc;
}
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* AMD MP2 1.1 initialization structures
*
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* All Rights Reserved.
*
* Author: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
*/
#ifndef AMD_SFH_INIT_H
#define AMD_SFH_INIT_H
#include "../amd_sfh_common.h"
struct amd_sfh1_1_ops {
int (*init)(struct amd_mp2_dev *mp2);
};
int amd_sfh1_1_init(struct amd_mp2_dev *mp2);
static const struct amd_sfh1_1_ops __maybe_unused sfh1_1_ops = {
.init = amd_sfh1_1_init,
};
#endif
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* AMD MP2 1.1 communication interfaces
*
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* All Rights Reserved.
*
* Author: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
*/
#include <linux/io-64-nonatomic-lo-hi.h>
#include <linux/iopoll.h>
#include "amd_sfh_interface.h"
static int amd_sfh_wait_response(struct amd_mp2_dev *mp2, u8 sid, u32 cmd_id)
{
struct sfh_cmd_response cmd_resp;
/* Get response with status within a max of 1600 ms timeout */
if (!readl_poll_timeout(mp2->mmio + AMD_P2C_MSG(0), cmd_resp.resp,
(cmd_resp.response.response == 0 &&
cmd_resp.response.cmd_id == cmd_id && (sid == 0xff ||
cmd_resp.response.sensor_id == sid)), 500, 1600000))
return cmd_resp.response.response;
return -1;
}
static void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info)
{
struct sfh_cmd_base cmd_base;
cmd_base.ul = 0;
cmd_base.cmd.cmd_id = ENABLE_SENSOR;
cmd_base.cmd.intr_disable = 0;
cmd_base.cmd.sensor_id = info.sensor_idx;
writel(cmd_base.ul, privdata->mmio + AMD_C2P_MSG(0));
}
static void amd_stop_sensor(struct amd_mp2_dev *privdata, u16 sensor_idx)
{
struct sfh_cmd_base cmd_base;
cmd_base.ul = 0;
cmd_base.cmd.cmd_id = DISABLE_SENSOR;
cmd_base.cmd.intr_disable = 0;
cmd_base.cmd.sensor_id = sensor_idx;
writeq(0x0, privdata->mmio + AMD_C2P_MSG(1));
writel(cmd_base.ul, privdata->mmio + AMD_C2P_MSG(0));
}
static void amd_stop_all_sensor(struct amd_mp2_dev *privdata)
{
struct sfh_cmd_base cmd_base;
cmd_base.ul = 0;
cmd_base.cmd.cmd_id = STOP_ALL_SENSORS;
cmd_base.cmd.intr_disable = 0;
writel(cmd_base.ul, privdata->mmio + AMD_C2P_MSG(0));
}
static struct amd_mp2_ops amd_sfh_ops = {
.start = amd_start_sensor,
.stop = amd_stop_sensor,
.stop_all = amd_stop_all_sensor,
.response = amd_sfh_wait_response,
};
void sfh_interface_init(struct amd_mp2_dev *mp2)
{
mp2->mp2_ops = &amd_sfh_ops;
}
/* SPDX-License-Identifier: GPL-2.0-or-later */
/*
* AMD MP2 1.1 communication interfaces
*
* Copyright (c) 2022, Advanced Micro Devices, Inc.
* All Rights Reserved.
*
* Author: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
*/
#ifndef AMD_SFH_INTERFACE_H
#define AMD_SFH_INTERFACE_H
#include "../amd_sfh_common.h"
#define SENSOR_DATA_MEM_SIZE_DEFAULT 256
#define TOTAL_STATIC_MEM_DEFAULT 1024
#define OFFSET_SFH_INFO_BASE_DEFAULT 0
#define OFFSET_SENSOR_DATA_DEFAULT (OFFSET_SFH_INFO_BASE_DEFAULT + \
TOTAL_STATIC_MEM_DEFAULT)
enum sensor_index {
ACCEL_IDX,
GYRO_IDX,
MAG_IDX,
ALS_IDX = 4,
HPD_IDX = 5,
MAX_IDX = 15,
};
struct sfh_cmd_base {
union {
u32 ul;
struct {
u32 sensor_id : 4;
u32 cmd_id : 4;
u32 sub_cmd_id : 6;
u32 length : 12;
u32 rsvd : 5;
u32 intr_disable : 1;
} cmd;
};
};
struct sfh_cmd_response {
union {
u32 resp;
struct {
u32 response : 8;
u32 sensor_id : 4;
u32 cmd_id : 4;
u32 sub_cmd : 6;
u32 rsvd2 : 10;
} response;
};
};
struct sfh_platform_info {
union {
u32 pi;
struct {
u32 cust_id : 16;
u32 plat_id : 6;
u32 interface_id : 4;
u32 rsvd : 6;
} pinfo;
};
};
struct sfh_firmware_info {
union {
u32 fw_ver;
struct {
u32 minor_rev : 8;
u32 major_rev : 8;
u32 minor_ver : 8;
u32 major_ver : 8;
} fver;
};
};
struct sfh_sensor_list {
union {
u32 slist;
struct {
u32 sensors : 16;
u32 rsvd : 16;
} sl;
};
};
struct sfh_base_info {
union {
u32 sfh_base[24];
struct {
struct sfh_platform_info plat_info;
struct sfh_firmware_info fw_info;
struct sfh_sensor_list s_list;
} sbase;
};
};
struct sfh_common_data {
u64 timestamp;
u32 intr_cnt;
u32 featvalid : 16;
u32 rsvd : 13;
u32 sensor_state : 3;
};
struct sfh_float32 {
u32 x;
u32 y;
u32 z;
};
struct sfh_accel_data {
struct sfh_common_data commondata;
struct sfh_float32 acceldata;
u32 accelstatus;
};
struct sfh_gyro_data {
struct sfh_common_data commondata;
struct sfh_float32 gyrodata;
u32 result;
};
struct sfh_mag_data {
struct sfh_common_data commondata;
struct sfh_float32 magdata;
u32 accuracy;
};
struct sfh_als_data {
struct sfh_common_data commondata;
u16 lux;
};
struct hpd_status {
union {
struct {
u32 distance : 16;
u32 probablity : 8;
u32 presence : 2;
u32 rsvd : 5;
u32 state : 1;
} shpd;
u32 val;
};
};
void sfh_interface_init(struct amd_mp2_dev *mp2);
void amd_sfh1_1_set_desc_ops(struct amd_mp2_ops *mp2_ops);
#endif
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