Skip to content

Commit 1425247

Browse files
DanielOgorchockJiri Kosina
authored andcommitted
HID: nintendo: set controller uniq to MAC
This patch sets the input device's uniq identifier to the controller's MAC address. This is useful for future association between an IMU input device with the normal input device as well as associating the controller with any serial joy-con driver. Signed-off-by: Daniel J. Ogorchock <djogorchock@gmail.com> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
1 parent 012bd52 commit 1425247

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

drivers/hid/hid-nintendo.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,8 @@ struct joycon_ctlr {
326326
struct led_classdev home_led;
327327
enum joycon_ctlr_state ctlr_state;
328328
spinlock_t lock;
329+
u8 mac_addr[6];
330+
char *mac_addr_str;
329331

330332
/* The following members are used for synchronous sends/receives */
331333
enum joycon_msg_type msg_type;
@@ -1012,6 +1014,7 @@ static int joycon_input_create(struct joycon_ctlr *ctlr)
10121014
ctlr->input->id.vendor = hdev->vendor;
10131015
ctlr->input->id.product = hdev->product;
10141016
ctlr->input->id.version = hdev->version;
1017+
ctlr->input->uniq = ctlr->mac_addr_str;
10151018
ctlr->input->name = name;
10161019
input_set_drvdata(ctlr->input, ctlr);
10171020

@@ -1322,6 +1325,41 @@ static int joycon_power_supply_create(struct joycon_ctlr *ctlr)
13221325
return power_supply_powers(ctlr->battery, &hdev->dev);
13231326
}
13241327

1328+
static int joycon_read_mac(struct joycon_ctlr *ctlr)
1329+
{
1330+
int ret;
1331+
int i;
1332+
int j;
1333+
struct joycon_subcmd_request req = { 0 };
1334+
struct joycon_input_report *report;
1335+
1336+
req.subcmd_id = JC_SUBCMD_REQ_DEV_INFO;
1337+
ret = joycon_send_subcmd(ctlr, &req, 0, HZ);
1338+
if (ret) {
1339+
hid_err(ctlr->hdev, "Failed to get joycon info; ret=%d\n", ret);
1340+
return ret;
1341+
}
1342+
1343+
report = (struct joycon_input_report *)ctlr->input_buf;
1344+
1345+
for (i = 4, j = 0; j < 6; i++, j++)
1346+
ctlr->mac_addr[j] = report->reply.data[i];
1347+
1348+
ctlr->mac_addr_str = devm_kasprintf(&ctlr->hdev->dev, GFP_KERNEL,
1349+
"%02X:%02X:%02X:%02X:%02X:%02X",
1350+
ctlr->mac_addr[0],
1351+
ctlr->mac_addr[1],
1352+
ctlr->mac_addr[2],
1353+
ctlr->mac_addr[3],
1354+
ctlr->mac_addr[4],
1355+
ctlr->mac_addr[5]);
1356+
if (!ctlr->mac_addr_str)
1357+
return -ENOMEM;
1358+
hid_info(ctlr->hdev, "controller MAC = %s\n", ctlr->mac_addr_str);
1359+
1360+
return 0;
1361+
}
1362+
13251363
/* Common handler for parsing inputs */
13261364
static int joycon_ctlr_read_handler(struct joycon_ctlr *ctlr, u8 *data,
13271365
int size)
@@ -1498,6 +1536,13 @@ static int nintendo_hid_probe(struct hid_device *hdev,
14981536
goto err_mutex;
14991537
}
15001538

1539+
ret = joycon_read_mac(ctlr);
1540+
if (ret) {
1541+
hid_err(hdev, "Failed to retrieve controller MAC; ret=%d\n",
1542+
ret);
1543+
goto err_mutex;
1544+
}
1545+
15011546
mutex_unlock(&ctlr->output_mutex);
15021547

15031548
/* Initialize the leds */

0 commit comments

Comments
 (0)