From a585d41f79f13a4c81c98e16480a56af9068bb69 Mon Sep 17 00:00:00 2001 From: Jaikumar Ganesh Date: Tue, 20 Sep 2011 16:40:43 -0700 Subject: [PATCH] HID: Add input_register callback. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add input_register callback which gets called after hid_configure_usage is called for all the reports and before the input device is registered. This allows individual drivers to do extra work like input mapping just before device registration. Based on discussions with David Herrmann Change-Id: Idab6fb4f7b1e5e569bd0410967288717e9d34c98 Signed-off-by: Jaikumar Ganesh Changed to add return code to input_configured instead of adding input_register Signed-off-by: Arve Hjønnevåg --- drivers/hid/hid-input.c | 10 ++++++---- drivers/hid/hid-multitouch.c | 14 ++++++++++---- include/linux/hid.h | 4 ++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c index a713e6211419..811947d73703 100644 --- a/drivers/hid/hid-input.c +++ b/drivers/hid/hid-input.c @@ -1410,8 +1410,9 @@ int hidinput_connect(struct hid_device *hid, unsigned int force) * UGCI) cram a lot of unrelated inputs into the * same interface. */ hidinput->report = report; - if (drv->input_configured) - drv->input_configured(hid, hidinput); + if (drv->input_configured && + drv->input_configured(hid, hidinput)) + goto out_cleanup; if (input_register_device(hidinput->input)) goto out_cleanup; hidinput = NULL; @@ -1432,8 +1433,9 @@ int hidinput_connect(struct hid_device *hid, unsigned int force) } if (hidinput) { - if (drv->input_configured) - drv->input_configured(hid, hidinput); + if (drv->input_configured && + drv->input_configured(hid, hidinput)) + goto out_cleanup; if (input_register_device(hidinput->input)) goto out_cleanup; } diff --git a/drivers/hid/hid-multitouch.c b/drivers/hid/hid-multitouch.c index 69eae679780b..37aa2f9d711b 100644 --- a/drivers/hid/hid-multitouch.c +++ b/drivers/hid/hid-multitouch.c @@ -757,12 +757,13 @@ static void mt_touch_report(struct hid_device *hid, struct hid_report *report) mt_sync_frame(td, report->field[0]->hidinput->input); } -static void mt_touch_input_configured(struct hid_device *hdev, +static int mt_touch_input_configured(struct hid_device *hdev, struct hid_input *hi) { struct mt_device *td = hid_get_drvdata(hdev); struct mt_class *cls = &td->mtclass; struct input_dev *input = hi->input; + int ret; if (!td->maxcontacts) td->maxcontacts = MT_DEFAULT_MAXCONTACT; @@ -777,9 +778,12 @@ static void mt_touch_input_configured(struct hid_device *hdev, if (cls->quirks & MT_QUIRK_NOT_SEEN_MEANS_UP) td->mt_flags |= INPUT_MT_DROP_UNUSED; - input_mt_init_slots(input, td->maxcontacts, td->mt_flags); + ret = input_mt_init_slots(input, td->maxcontacts, td->mt_flags); + if (ret) + return ret; td->mt_flags = 0; + return 0; } static int mt_input_mapping(struct hid_device *hdev, struct hid_input *hi, @@ -912,14 +916,15 @@ static void mt_post_parse(struct mt_device *td) cls->quirks &= ~MT_QUIRK_CONTACT_CNT_ACCURATE; } -static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi) +static int mt_input_configured(struct hid_device *hdev, struct hid_input *hi) { struct mt_device *td = hid_get_drvdata(hdev); char *name; const char *suffix = NULL; + int ret = 0; if (hi->report->id == td->mt_report_id) - mt_touch_input_configured(hdev, hi); + ret = mt_touch_input_configured(hdev, hi); if (hi->report->field[0]->physical == HID_DG_STYLUS) { suffix = "Pen"; @@ -935,6 +940,7 @@ static void mt_input_configured(struct hid_device *hdev, struct hid_input *hi) hi->input->name = name; } } + return ret; } static int mt_probe(struct hid_device *hdev, const struct hid_device_id *id) diff --git a/include/linux/hid.h b/include/linux/hid.h index 31b9d299ef6c..c6dadc733748 100644 --- a/include/linux/hid.h +++ b/include/linux/hid.h @@ -655,8 +655,8 @@ struct hid_driver { int (*input_mapped)(struct hid_device *hdev, struct hid_input *hidinput, struct hid_field *field, struct hid_usage *usage, unsigned long **bit, int *max); - void (*input_configured)(struct hid_device *hdev, - struct hid_input *hidinput); + int (*input_configured)(struct hid_device *hdev, + struct hid_input *hidinput); void (*feature_mapping)(struct hid_device *hdev, struct hid_field *field, struct hid_usage *usage);