Skip to content

Commit 8959f00

Browse files
author
Jiri Kosina
committed
Merge branch 'for-5.19/amd-sfh' into for-linus
- support for sensor discovery and code cleanups (Basavaraj Natikar)
2 parents fc4ef9d + 806fc35 commit 8959f00

File tree

8 files changed

+72
-16
lines changed

8 files changed

+72
-16
lines changed

drivers/hid/amd-sfh-hid/amd_sfh_client.c

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,24 @@ u32 amd_sfh_wait_for_response(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts)
141141
return sensor_sts;
142142
}
143143

144+
const char *get_sensor_name(int idx)
145+
{
146+
switch (idx) {
147+
case accel_idx:
148+
return "accelerometer";
149+
case gyro_idx:
150+
return "gyroscope";
151+
case mag_idx:
152+
return "magnetometer";
153+
case als_idx:
154+
return "ALS";
155+
case HPD_IDX:
156+
return "HPD";
157+
default:
158+
return "unknown sensor type";
159+
}
160+
}
161+
144162
int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
145163
{
146164
struct amd_input_data *in_data = &privdata->in_data;
@@ -219,13 +237,27 @@ int amd_sfh_hid_client_init(struct amd_mp2_dev *privdata)
219237
(privdata, cl_data->sensor_idx[i], SENSOR_DISABLED);
220238
if (status != SENSOR_ENABLED)
221239
cl_data->sensor_sts[i] = SENSOR_DISABLED;
222-
dev_dbg(dev, "sid 0x%x status 0x%x\n",
223-
cl_data->sensor_idx[i], cl_data->sensor_sts[i]);
240+
dev_dbg(dev, "sid 0x%x (%s) status 0x%x\n",
241+
cl_data->sensor_idx[i],
242+
get_sensor_name(cl_data->sensor_idx[i]),
243+
cl_data->sensor_sts[i]);
224244
goto cleanup;
225245
}
226246
}
227-
dev_dbg(dev, "sid 0x%x status 0x%x\n",
228-
cl_data->sensor_idx[i], cl_data->sensor_sts[i]);
247+
dev_dbg(dev, "sid 0x%x (%s) status 0x%x\n",
248+
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
249+
cl_data->sensor_sts[i]);
250+
}
251+
if (privdata->mp2_ops->discovery_status &&
252+
privdata->mp2_ops->discovery_status(privdata) == 0) {
253+
amd_sfh_hid_client_deinit(privdata);
254+
for (i = 0; i < cl_data->num_hid_devices; i++) {
255+
devm_kfree(dev, cl_data->feature_report[i]);
256+
devm_kfree(dev, in_data->input_report[i]);
257+
devm_kfree(dev, cl_data->report_descr[i]);
258+
}
259+
dev_warn(dev, "Failed to discover, sensors not enabled\n");
260+
return -EOPNOTSUPP;
229261
}
230262
schedule_delayed_work(&cl_data->work_buffer, msecs_to_jiffies(AMD_SFH_IDLE_LOOP));
231263
return 0;
@@ -257,8 +289,9 @@ int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata)
257289
(privdata, cl_data->sensor_idx[i], SENSOR_DISABLED);
258290
if (status != SENSOR_ENABLED)
259291
cl_data->sensor_sts[i] = SENSOR_DISABLED;
260-
dev_dbg(&privdata->pdev->dev, "stopping sid 0x%x status 0x%x\n",
261-
cl_data->sensor_idx[i], cl_data->sensor_sts[i]);
292+
dev_dbg(&privdata->pdev->dev, "stopping sid 0x%x (%s) status 0x%x\n",
293+
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
294+
cl_data->sensor_sts[i]);
262295
}
263296
}
264297

drivers/hid/amd-sfh-hid/amd_sfh_hid.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <linux/sched.h>
1313

1414
#include "amd_sfh_hid.h"
15+
#include "amd_sfh_pcie.h"
1516

1617
#define AMD_SFH_RESPONSE_TIMEOUT 1500
1718

@@ -120,6 +121,8 @@ static struct hid_ll_driver amdtp_hid_ll_driver = {
120121

121122
int amdtp_hid_probe(u32 cur_hid_dev, struct amdtp_cl_data *cli_data)
122123
{
124+
struct amd_mp2_dev *mp2 = container_of(cli_data->in_data, struct amd_mp2_dev, in_data);
125+
struct device *dev = &mp2->pdev->dev;
123126
struct hid_device *hid;
124127
struct amdtp_hid_data *hid_data;
125128
int rc;
@@ -141,10 +144,12 @@ int amdtp_hid_probe(u32 cur_hid_dev, struct amdtp_cl_data *cli_data)
141144

142145
hid->driver_data = hid_data;
143146
cli_data->hid_sensor_hubs[cur_hid_dev] = hid;
144-
hid->bus = BUS_AMD_AMDTP;
147+
strscpy(hid->phys, dev->driver ? dev->driver->name : dev_name(dev),
148+
sizeof(hid->phys));
149+
hid->bus = BUS_AMD_SFH;
145150
hid->vendor = AMD_SFH_HID_VENDOR;
146151
hid->product = AMD_SFH_HID_PRODUCT;
147-
snprintf(hid->name, sizeof(hid->name), "%s %04X:%04X", "hid-amdtp",
152+
snprintf(hid->name, sizeof(hid->name), "%s %04X:%04X", "hid-amdsfh",
148153
hid->vendor, hid->product);
149154

150155
rc = hid_add_device(hid);

drivers/hid/amd-sfh-hid/amd_sfh_hid.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#define AMDSFH_HID_H
1313

1414
#define MAX_HID_DEVICES 5
15-
#define BUS_AMD_AMDTP 0x20
1615
#define AMD_SFH_HID_VENDOR 0x1022
1716
#define AMD_SFH_HID_PRODUCT 0x0001
1817

drivers/hid/amd-sfh-hid/amd_sfh_pcie.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,12 @@ static int amd_sfh_irq_init_v2(struct amd_mp2_dev *privdata)
130130
return 0;
131131
}
132132

133+
static int amd_sfh_dis_sts_v2(struct amd_mp2_dev *privdata)
134+
{
135+
return (readl(privdata->mmio + AMD_P2C_MSG(1)) &
136+
SENSOR_DISCOVERY_STATUS_MASK) >> SENSOR_DISCOVERY_STATUS_SHIFT;
137+
}
138+
133139
void amd_start_sensor(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info)
134140
{
135141
union sfh_cmd_param cmd_param;
@@ -245,6 +251,7 @@ static const struct amd_mp2_ops amd_sfh_ops_v2 = {
245251
.response = amd_sfh_wait_response_v2,
246252
.clear_intr = amd_sfh_clear_intr_v2,
247253
.init_intr = amd_sfh_irq_init_v2,
254+
.discovery_status = amd_sfh_dis_sts_v2,
248255
};
249256

250257
static const struct amd_mp2_ops amd_sfh_ops = {
@@ -346,8 +353,9 @@ static int __maybe_unused amd_mp2_pci_resume(struct device *dev)
346353
(mp2, cl_data->sensor_idx[i], SENSOR_ENABLED);
347354
if (status == SENSOR_ENABLED)
348355
cl_data->sensor_sts[i] = SENSOR_ENABLED;
349-
dev_dbg(dev, "resume sid 0x%x status 0x%x\n",
350-
cl_data->sensor_idx[i], cl_data->sensor_sts[i]);
356+
dev_dbg(dev, "suspend sid 0x%x (%s) status 0x%x\n",
357+
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
358+
cl_data->sensor_sts[i]);
351359
}
352360
}
353361

@@ -371,8 +379,9 @@ static int __maybe_unused amd_mp2_pci_suspend(struct device *dev)
371379
(mp2, cl_data->sensor_idx[i], SENSOR_DISABLED);
372380
if (status != SENSOR_ENABLED)
373381
cl_data->sensor_sts[i] = SENSOR_DISABLED;
374-
dev_dbg(dev, "suspend sid 0x%x status 0x%x\n",
375-
cl_data->sensor_idx[i], cl_data->sensor_sts[i]);
382+
dev_dbg(dev, "suspend sid 0x%x (%s) status 0x%x\n",
383+
cl_data->sensor_idx[i], get_sensor_name(cl_data->sensor_idx[i]),
384+
cl_data->sensor_sts[i]);
376385
}
377386
}
378387

drivers/hid/amd-sfh-hid/amd_sfh_pcie.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939

4040
#define AMD_SFH_IDLE_LOOP 200
4141

42+
#define SENSOR_DISCOVERY_STATUS_MASK GENMASK(5, 3)
43+
#define SENSOR_DISCOVERY_STATUS_SHIFT 3
44+
4245
/* SFH Command register */
4346
union sfh_cmd_base {
4447
u32 ul;
@@ -135,6 +138,7 @@ int amd_sfh_hid_client_deinit(struct amd_mp2_dev *privdata);
135138
u32 amd_sfh_wait_for_response(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts);
136139
void amd_mp2_suspend(struct amd_mp2_dev *mp2);
137140
void amd_mp2_resume(struct amd_mp2_dev *mp2);
141+
const char *get_sensor_name(int idx);
138142

139143
struct amd_mp2_ops {
140144
void (*start)(struct amd_mp2_dev *privdata, struct amd_mp2_sensor_info info);
@@ -143,5 +147,6 @@ struct amd_mp2_ops {
143147
int (*response)(struct amd_mp2_dev *mp2, u8 sid, u32 sensor_sts);
144148
void (*clear_intr)(struct amd_mp2_dev *privdata);
145149
int (*init_intr)(struct amd_mp2_dev *privdata);
150+
int (*discovery_status)(struct amd_mp2_dev *privdata);
146151
};
147152
#endif

drivers/hid/amd-sfh-hid/hid_descriptor/amd_sfh_hid_report_desc.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ static const u8 accel3_report_descriptor[] = {
179179
0xC0 /* HID end collection */
180180
};
181181

182-
const u8 gyro3_report_descriptor[] = {
182+
static const u8 gyro3_report_descriptor[] = {
183183
0x05, 0x20, /* Usage page */
184184
0x09, 0x76, /* Motion type Gyro3D */
185185
0xA1, 0x00, /* HID Collection (Physical) */
@@ -340,7 +340,7 @@ const u8 gyro3_report_descriptor[] = {
340340
0xC0, /* HID end collection */
341341
};
342342

343-
const u8 comp3_report_descriptor[] = {
343+
static const u8 comp3_report_descriptor[] = {
344344
0x05, 0x20, /* Usage page */
345345
0x09, 0x83, /* Motion type Orientation compass 3D */
346346
0xA1, 0x00, /* HID Collection (Physical) */
@@ -512,7 +512,7 @@ const u8 comp3_report_descriptor[] = {
512512
0xC0 /* HID end collection */
513513
};
514514

515-
const u8 als_report_descriptor[] = {
515+
static const u8 als_report_descriptor[] = {
516516
0x05, 0x20, /* HID usage page sensor */
517517
0x09, 0x41, /* HID usage sensor type Ambientlight */
518518
0xA1, 0x00, /* HID Collection (Physical) */

drivers/hid/hid-core.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2222,6 +2222,10 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
22222222
case BUS_VIRTUAL:
22232223
bus = "VIRTUAL";
22242224
break;
2225+
case BUS_INTEL_ISHTP:
2226+
case BUS_AMD_SFH:
2227+
bus = "SENSOR HUB";
2228+
break;
22252229
default:
22262230
bus = "<UNKNOWN>";
22272231
}

include/uapi/linux/input.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ struct input_mask {
271271
#define BUS_RMI 0x1D
272272
#define BUS_CEC 0x1E
273273
#define BUS_INTEL_ISHTP 0x1F
274+
#define BUS_AMD_SFH 0x20
274275

275276
/*
276277
* MT_TOOL types

0 commit comments

Comments
 (0)