OSDN Git Service

HID: expose country code in sysfs
authorOlivier Gay <ogay@logitech.com>
Tue, 17 Feb 2015 13:00:03 +0000 (14:00 +0100)
committerJiri Kosina <jkosina@suse.cz>
Mon, 23 Feb 2015 15:17:32 +0000 (16:17 +0100)
This commit exposes in sysfs the HID country code that is stored in the country
member of hid_device structure. It identifies the country code of localized
hardware.

For example some keyboards use it to exhibit the language of the key layout. It
helps the upper layer to identify the localized hardware and setup the correct
language to use.

For USB HID devices the country code comes for the HID descriptor and for
Bluetooth HID devices it is the HIDCountryCode attribute from the SDP database.

Signed-off-by: Olivier Gay <ogay@logitech.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Documentation/ABI/testing/sysfs-driver-hid
drivers/hid/hid-core.c

index b6490e1..48942ca 100644 (file)
@@ -8,3 +8,13 @@ Description:   When read, this file returns the device's raw binary HID
                report descriptor.
                This file cannot be written.
 Users:         HIDAPI library (http://www.signal11.us/oss/hidapi)
+
+What:          For USB devices : /sys/bus/usb/devices/<busnum>-<devnum>:<config num>.<interface num>/<hid-bus>:<vendor-id>:<product-id>.<num>/country
+               For BT devices  : /sys/class/bluetooth/hci<addr>/<hid-bus>:<vendor-id>:<product-id>.<num>/country
+               Symlink         : /sys/class/hidraw/hidraw<num>/device/country
+Date:          February 2015
+KernelVersion: 3.19
+Contact:       Olivier Gay <ogay@logitech.com>
+Description:   When read, this file returns the hex integer value in ASCII
+               of the device's HID country code (e.g. 21 for US).
+               This file cannot be written.
index db4fb6e..4bae0f5 100644 (file)
@@ -1562,12 +1562,26 @@ read_report_descriptor(struct file *filp, struct kobject *kobj,
        return count;
 }
 
+static ssize_t
+show_country(struct device *dev, struct device_attribute *attr,
+               char *buf)
+{
+       struct hid_device *hdev = container_of(dev, struct hid_device, dev);
+
+       return sprintf(buf, "%02x\n", hdev->country & 0xff);
+}
+
 static struct bin_attribute dev_bin_attr_report_desc = {
        .attr = { .name = "report_descriptor", .mode = 0444 },
        .read = read_report_descriptor,
        .size = HID_MAX_DESCRIPTOR_SIZE,
 };
 
+static struct device_attribute dev_attr_country = {
+       .attr = { .name = "country", .mode = 0444 },
+       .show = show_country,
+};
+
 int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
 {
        static const char *types[] = { "Device", "Pointer", "Mouse", "Device",
@@ -1646,6 +1660,11 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask)
                bus = "<UNKNOWN>";
        }
 
+       ret = device_create_file(&hdev->dev, &dev_attr_country);
+       if (ret)
+               hid_warn(hdev,
+                        "can't create sysfs country code attribute err: %d\n", ret);
+
        ret = device_create_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
        if (ret)
                hid_warn(hdev,
@@ -1661,6 +1680,7 @@ EXPORT_SYMBOL_GPL(hid_connect);
 
 void hid_disconnect(struct hid_device *hdev)
 {
+       device_remove_file(&hdev->dev, &dev_attr_country);
        device_remove_bin_file(&hdev->dev, &dev_bin_attr_report_desc);
        if (hdev->claimed & HID_CLAIMED_INPUT)
                hidinput_disconnect(hdev);