diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_client.c b/drivers/hid/amd-sfh-hid/amd_sfh_client.c index e3b3db514c91..e9ccdad66d12 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_client.c +++ b/drivers/hid/amd-sfh-hid/amd_sfh_client.c @@ -70,6 +70,8 @@ static void amd_sfh_work(struct work_struct *work) struct amd_input_data *in_data = cli_data->in_data; struct request_list *req_node; u8 current_index, sensor_index; + struct amd_mp2_ops *mp2_ops; + struct amd_mp2_dev *mp2; u8 report_id, node_type; u8 report_size = 0; @@ -81,9 +83,11 @@ static void amd_sfh_work(struct work_struct *work) node_type = req_node->report_type; 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) { - report_size = get_feature_report(sensor_index, report_id, - cli_data->feature_report[current_index]); + report_size = mp2_ops->get_feat_rep(sensor_index, report_id, + cli_data->feature_report[current_index]); if (report_size) hid_input_report(cli_data->hid_sensor_hubs[current_index], cli_data->report_type[current_index], @@ -92,7 +96,7 @@ static void amd_sfh_work(struct work_struct *work) pr_err("AMDSFH: Invalid report size\n"); } 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) hid_input_report(cli_data->hid_sensor_hubs[current_index], cli_data->report_type[current_index], @@ -109,13 +113,15 @@ static 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 amd_input_data *in_data = cli_data->in_data; + struct amd_mp2_dev *mp2; u8 report_size; int i; for (i = 0; i < cli_data->num_hid_devices; i++) { if (cli_data->sensor_sts[i] == SENSOR_ENABLED) { - report_size = get_input_report - (i, cli_data->sensor_idx[i], cli_data->report_id[i], in_data); + mp2 = container_of(in_data, struct amd_mp2_dev, 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, in_data->input_report[i], report_size, 0); } @@ -153,6 +159,7 @@ int amd_sfh_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; struct device *dev; @@ -163,6 +170,7 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) req_list = &cl_data->req_list; dev = &privdata->pdev->dev; + amd_sfh_set_desc_ops(mp2_ops); cl_data->num_hid_devices = amd_mp2_get_sensor_num(privdata, &cl_data->sensor_idx[0]); @@ -179,17 +187,17 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) 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] = 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]) { rc = -EINVAL; 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) { rc = -EINVAL; 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) { rc = -EINVAL; goto cleanup; @@ -214,17 +222,17 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata) rc = -ENOMEM; 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) return rc; - privdata->mp2_ops->start(privdata, info); + mp2_ops->start(privdata, info); status = amd_sfh_wait_for_response (privdata, cl_data->sensor_idx[i], SENSOR_ENABLED); if (status == SENSOR_ENABLED) { cl_data->sensor_sts[i] = SENSOR_ENABLED; rc = amdtp_hid_probe(cl_data->cur_hid_dev, cl_data); 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 (privdata, cl_data->sensor_idx[i], SENSOR_DISABLED); if (status != SENSOR_ENABLED) @@ -240,8 +248,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_sts[i]); } - if (privdata->mp2_ops->discovery_status && - privdata->mp2_ops->discovery_status(privdata) == 0) { + if (mp2_ops->discovery_status && mp2_ops->discovery_status(privdata) == 0) { amd_sfh_hid_client_deinit(privdata); for (i = 0; i < cl_data->num_hid_devices; i++) { devm_kfree(dev, cl_data->feature_report[i]); diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_common.h b/drivers/hid/amd-sfh-hid/amd_sfh_common.h index 40da53d5efd0..d2a72ab64ebf 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_common.h +++ b/drivers/hid/amd-sfh-hid/amd_sfh_common.h @@ -40,7 +40,7 @@ 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_mp2_ops *mp2_ops; struct amd_input_data in_data; /* mp2 active control status */ u32 mp2_acs; @@ -54,6 +54,11 @@ struct amd_mp2_ops { void (*clear_intr)(struct amd_mp2_dev *privdata); int (*init_intr)(struct amd_mp2_dev *privdata); int (*discovery_status)(struct amd_mp2_dev *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); }; #endif diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_hid.h b/drivers/hid/amd-sfh-hid/amd_sfh_hid.h index ecdd2f48cfb8..3754fb423e3a 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_hid.h +++ b/drivers/hid/amd-sfh-hid/amd_sfh_hid.h @@ -79,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); void amd_sfh_set_report(struct hid_device *hid, int report_id, int report_type); 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 diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c index dadc491bbf6b..f169b4413abb 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c +++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.c @@ -244,7 +244,7 @@ static void amd_mp2_pci_remove(void *privdata) 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, .stop = amd_stop_sensor_v2, .stop_all = amd_stop_all_sensor_v2, @@ -254,7 +254,7 @@ static const struct amd_mp2_ops amd_sfh_ops_v2 = { .discovery_status = amd_sfh_dis_sts_v2, }; -static const struct amd_mp2_ops amd_sfh_ops = { +static struct amd_mp2_ops amd_sfh_ops = { .start = amd_start_sensor, .stop = amd_stop_sensor, .stop_all = amd_stop_all_sensors, diff --git a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h index 2feac14f5d3c..71c114acdd2b 100644 --- a/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h +++ b/drivers/hid/amd-sfh-hid/amd_sfh_pcie.h @@ -108,5 +108,6 @@ 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); const char *get_sensor_name(int idx); +void amd_sfh_set_desc_ops(struct amd_mp2_ops *mp2_ops); #endif diff --git a/drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_desc.c b/drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_desc.c index 76095bd53c65..f9a8c02d5a7b 100644 --- a/drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_desc.c +++ b/drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_desc.c @@ -29,7 +29,7 @@ #define HID_USAGE_SENSOR_EVENT_DATA_UPDATED_ENUM 0x04 #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) { case accel_idx: /* accel */ @@ -63,7 +63,7 @@ int get_report_descriptor(int sensor_idx, u8 *rep_desc) 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) { case accel_idx: @@ -133,7 +133,7 @@ static void get_common_features(struct common_feature_property *common, int repo 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 gyro_feature_report gyro_feature; @@ -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; } -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); 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_ } 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; +} diff --git a/drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_desc.h b/drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_desc.h index 70b1b7abe2c6..ebd55675eb62 100644 --- a/drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_desc.h +++ b/drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_desc.h @@ -111,7 +111,4 @@ struct hpd_input_report { u8 human_presence; } __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