From: Simon Wood <simon@mungewell.org> To: linux-input@vger.kernel.org Cc: linux-kernel@vger.kernel.org, "Jiri Kosina" <jkosina@suse.cz>, Edwin <Edwin@Velds.nl>, "Michal Malý" <madcatxster@devoid-pointer.net>, "elias vanderstuyft" <elias.vds@gmail.com>, "Benjamin Tissoires" <benjamin.tissoires@redhat.com>, "Simon Wood" <simon@mungewell.org> Subject: [Patch-V2 4/6] HID: hid-logitech-hidpp: Add range sysfs for Logitech G920 Date: Thu, 12 Nov 2015 09:25:33 -0700 [thread overview] Message-ID: <1447345535-2912-5-git-send-email-simon@mungewell.org> (raw) In-Reply-To: <1447345535-2912-1-git-send-email-simon@mungewell.org> The G920 can adjust the amount of 'turn' it permits, this patch adds a sysfs file 'range' to control this. Signed-off-by: Simon Wood <simon@mungewell.org> --- drivers/hid/hid-logitech-hidpp.c | 140 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 139 insertions(+), 1 deletion(-) diff --git a/drivers/hid/hid-logitech-hidpp.c b/drivers/hid/hid-logitech-hidpp.c index 699a486..80ebd1c 100644 --- a/drivers/hid/hid-logitech-hidpp.c +++ b/drivers/hid/hid-logitech-hidpp.c @@ -1295,6 +1295,133 @@ static int k400_connect(struct hid_device *hdev, bool connected) return k400_disable_tap_to_click(hidpp); } +/* ------------------------------------------------------------------------- */ +/* Logitech G920 Driving Force Racing Wheel for Xbox One */ +/* ------------------------------------------------------------------------- */ + +#define HIDPP_PAGE_G920_FORCE_FEEDBACK 0x8123 + +/* Using session ID = 1 */ +#define CMD_G920_FORCE_GET_APERTURE 0x51 +#define CMD_G920_FORCE_SET_APERTURE 0x61 + +struct g920_private_data { + u8 force_feature; + u16 range; +}; + +#define to_hid_device(pdev) container_of(pdev, struct hid_device, dev) + +static ssize_t g920_range_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct hid_device *hid = to_hid_device(dev); + struct hidpp_device *hidpp = hid_get_drvdata(hid); + struct g920_private_data *pdata; + + pdata = hidpp->private_data; + if (!pdata) { + hid_err(hid, "Private driver data not found!\n"); + return -EINVAL; + } + + return scnprintf(buf, PAGE_SIZE, "%u\n", pdata->range); +} + +static ssize_t g920_range_store(struct device *dev, struct device_attribute *attr, + const char *buf, size_t count) +{ + struct hid_device *hid = to_hid_device(dev); + struct hidpp_device *hidpp = hid_get_drvdata(hid); + struct g920_private_data *pdata; + struct hidpp_report response; + u8 params[2]; + int ret; + u16 range = simple_strtoul(buf, NULL, 10); + + pdata = hidpp->private_data; + if (!pdata) { + hid_err(hid, "Private driver data not found!\n"); + return -EINVAL; + } + + if (range < 180) + range = 180; + else if (range > 900) + range = 900; + + params[0] = range >> 8; + params[1] = range & 0x00FF; + + ret = hidpp_send_fap_command_sync(hidpp, pdata->force_feature, + CMD_G920_FORCE_SET_APERTURE, params, 2, &response); + if (ret) + return ret; + + pdata->range = range; + return count; +} + +static DEVICE_ATTR(range, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH, g920_range_show, g920_range_store); + +static int g920_allocate(struct hid_device *hdev) +{ + struct hidpp_device *hidpp = hid_get_drvdata(hdev); + struct g920_private_data *pdata; + + pdata = devm_kzalloc(&hdev->dev, sizeof(struct g920_private_data), + GFP_KERNEL); + if (!pdata) + return -ENOMEM; + + hidpp->private_data = pdata; + + return 0; +} + +static int g920_get_config(struct hidpp_device *hidpp) +{ + struct g920_private_data *pdata = hidpp->private_data; + struct hidpp_report response; + u8 feature_type; + u8 feature_index; + int ret; + + pdata = hidpp->private_data; + if (!pdata) { + hid_err(hidpp->hid_dev, "Private driver data not found!\n"); + return -EINVAL; + } + + /* Find feature and store for later use */ + ret = hidpp_root_get_feature(hidpp, HIDPP_PAGE_G920_FORCE_FEEDBACK, + &feature_index, &feature_type); + if (ret) + return ret; + + pdata->force_feature = feature_index; + + /* Read current Range */ + ret = hidpp_send_fap_command_sync(hidpp, feature_index, + CMD_G920_FORCE_GET_APERTURE, NULL, 0, &response); + if (ret > 0) { + hid_err(hidpp->hid_dev, "%s: received protocol error 0x%02x\n", + __func__, ret); + return -EPROTO; + } + if (ret) + return ret; + + pdata->range = get_unaligned_be16(&response.fap.params[0]); + + /* Create sysfs interface */ + ret = device_create_file(&(hidpp->hid_dev->dev), &dev_attr_range); + if (ret) + hid_warn(hidpp->hid_dev, "Unable to create sysfs interface for \"range\", errno %d\n", ret); + + return 0; +} + /* -------------------------------------------------------------------------- */ /* Generic HID++ devices */ /* -------------------------------------------------------------------------- */ @@ -1595,6 +1722,10 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) ret = k400_allocate(hdev); if (ret) goto allocate_fail; + } else if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { + ret = g920_allocate(hdev); + if (ret) + goto allocate_fail; } INIT_WORK(&hidpp->work, delayed_work_cb); @@ -1648,6 +1779,10 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) ret = wtp_get_config(hidpp); if (ret) goto hid_hw_open_failed; + } else if (connected && (hidpp->quirks & HIDPP_QUIRK_CLASS_G920)) { + ret = g920_get_config(hidpp); + if (ret) + goto hid_hw_open_failed; } /* Block incoming packets */ @@ -1673,6 +1808,7 @@ static int hidpp_probe(struct hid_device *hdev, const struct hid_device_id *id) hid_hw_open_failed: hid_device_io_stop(hdev); if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { + device_remove_file(&hdev->dev, &dev_attr_range); hid_hw_close(hdev); hid_hw_stop(hdev); } @@ -1689,8 +1825,10 @@ static void hidpp_remove(struct hid_device *hdev) { struct hidpp_device *hidpp = hid_get_drvdata(hdev); - if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) + if (hidpp->quirks & HIDPP_QUIRK_CLASS_G920) { + device_remove_file(&hdev->dev, &dev_attr_range); hid_hw_close(hdev); + } hid_hw_stop(hdev); cancel_work_sync(&hidpp->work); mutex_destroy(&hidpp->send_mutex); -- 2.1.4
next prev parent reply other threads:[~2015-11-12 16:25 UTC|newest] Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-11-12 16:25 [Patch-V2 0/6] HID: Support for the Logitech G920 Wheel Simon Wood 2015-11-12 16:25 ` [Patch-V2 1/6] INPUT: xpad: Add minimal support for " Simon Wood 2015-11-19 13:50 ` Jiri Kosina 2015-11-19 18:31 ` Dmitry Torokhov 2015-11-19 18:35 ` Simon Wood 2015-11-19 23:19 ` Edwin 2015-12-10 1:23 ` Dmitry Torokhov 2015-12-10 1:39 ` Dmitry Torokhov 2015-12-10 17:08 ` Benjamin Tissoires 2015-12-10 18:40 ` Dmitry Torokhov 2016-01-04 9:55 ` Benjamin Tissoires 2016-01-04 12:43 ` madcatxster 2016-01-04 12:43 ` madcatxster [not found] ` <568ad0ae.ea3d320a.6acab.2b84SMTPIN_ADDED_MISSING@mx.google.com> 2016-01-05 1:01 ` Dmitry Torokhov 2016-01-06 14:36 ` Jiri Kosina 2016-01-07 1:47 ` Dmitry Torokhov 2016-01-07 4:25 ` Simon Wood 2016-01-07 22:50 ` Michal Malý 2016-01-07 22:53 ` Dmitry Torokhov 2016-01-07 22:53 ` Dmitry Torokhov 2016-01-07 23:05 ` Michal Malý 2016-01-07 23:05 ` Michal Malý 2016-01-08 9:11 ` Jiri Kosina 2015-12-13 12:50 ` Elias Vanderstuyft 2015-11-12 16:25 ` [Patch-V2 2/6] HID: hid-logitech-hidpp: Add support for very long packets Simon Wood 2015-11-12 16:25 ` [Patch-V2 3/6] HID: hid-logitech-hidpp: Add basic support for Logitech G920 Simon Wood 2015-11-19 11:18 ` Benjamin Tissoires 2015-11-12 16:25 ` Simon Wood [this message] 2015-11-12 16:25 ` [Patch-V2 5/6] HID: Add vendor specific usage pages " Simon Wood 2015-11-12 16:25 ` [Patch-V2 6/6] HID: hid-logitech-hidpp: G920 remove deadzones Simon Wood 2015-11-12 16:32 ` [Patch-V2 0/6] HID: Support for the Logitech G920 Wheel Simon Wood 2015-11-19 10:04 ` Jiri Kosina 2015-11-19 11:23 ` Benjamin Tissoires
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1447345535-2912-5-git-send-email-simon@mungewell.org \ --to=simon@mungewell.org \ --cc=Edwin@Velds.nl \ --cc=benjamin.tissoires@redhat.com \ --cc=elias.vds@gmail.com \ --cc=jkosina@suse.cz \ --cc=linux-input@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=madcatxster@devoid-pointer.net \ --subject='Re: [Patch-V2 4/6] HID: hid-logitech-hidpp: Add range sysfs for Logitech G920' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.