0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/export.h>
0009 #include <linux/hid.h>
0010 #include <linux/input/vivaldi-fmap.h>
0011 #include <linux/kernel.h>
0012 #include <linux/module.h>
0013 #include <linux/types.h>
0014
0015 #include "hid-vivaldi-common.h"
0016
0017 #define MIN_FN_ROW_KEY 1
0018 #define MAX_FN_ROW_KEY VIVALDI_MAX_FUNCTION_ROW_KEYS
0019 #define HID_VD_FN_ROW_PHYSMAP 0x00000001
0020 #define HID_USAGE_FN_ROW_PHYSMAP (HID_UP_GOOGLEVENDOR | HID_VD_FN_ROW_PHYSMAP)
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 void vivaldi_feature_mapping(struct hid_device *hdev,
0032 struct hid_field *field, struct hid_usage *usage)
0033 {
0034 struct vivaldi_data *data = hid_get_drvdata(hdev);
0035 struct hid_report *report = field->report;
0036 u8 *report_data, *buf;
0037 u32 report_len;
0038 unsigned int fn_key;
0039 int ret;
0040
0041 if (field->logical != HID_USAGE_FN_ROW_PHYSMAP ||
0042 (usage->hid & HID_USAGE_PAGE) != HID_UP_ORDINAL)
0043 return;
0044
0045 fn_key = usage->hid & HID_USAGE;
0046 if (fn_key < MIN_FN_ROW_KEY || fn_key > MAX_FN_ROW_KEY)
0047 return;
0048
0049 if (fn_key > data->num_function_row_keys)
0050 data->num_function_row_keys = fn_key;
0051
0052 report_data = buf = hid_alloc_report_buf(report, GFP_KERNEL);
0053 if (!report_data)
0054 return;
0055
0056 report_len = hid_report_len(report);
0057 if (!report->id) {
0058
0059
0060
0061
0062
0063
0064
0065
0066 report_len++;
0067 }
0068
0069 ret = hid_hw_raw_request(hdev, report->id, report_data,
0070 report_len, HID_FEATURE_REPORT,
0071 HID_REQ_GET_REPORT);
0072 if (ret < 0) {
0073 dev_warn(&hdev->dev, "failed to fetch feature %d\n",
0074 field->report->id);
0075 goto out;
0076 }
0077
0078 if (!report->id) {
0079
0080
0081
0082
0083 report_data++;
0084 report_len--;
0085 }
0086
0087 ret = hid_report_raw_event(hdev, HID_FEATURE_REPORT, report_data,
0088 report_len, 0);
0089 if (ret) {
0090 dev_warn(&hdev->dev, "failed to report feature %d\n",
0091 field->report->id);
0092 goto out;
0093 }
0094
0095 data->function_row_physmap[fn_key - MIN_FN_ROW_KEY] =
0096 field->value[usage->usage_index];
0097
0098 out:
0099 kfree(buf);
0100 }
0101 EXPORT_SYMBOL_GPL(vivaldi_feature_mapping);
0102
0103 static ssize_t function_row_physmap_show(struct device *dev,
0104 struct device_attribute *attr,
0105 char *buf)
0106 {
0107 struct hid_device *hdev = to_hid_device(dev);
0108 struct vivaldi_data *data = hid_get_drvdata(hdev);
0109
0110 return vivaldi_function_row_physmap_show(data, buf);
0111 }
0112
0113 static DEVICE_ATTR_RO(function_row_physmap);
0114 static struct attribute *vivaldi_sysfs_attrs[] = {
0115 &dev_attr_function_row_physmap.attr,
0116 NULL
0117 };
0118
0119 static const struct attribute_group vivaldi_attribute_group = {
0120 .attrs = vivaldi_sysfs_attrs,
0121 };
0122
0123
0124
0125
0126
0127
0128 int vivaldi_input_configured(struct hid_device *hdev,
0129 struct hid_input *hidinput)
0130 {
0131 struct vivaldi_data *data = hid_get_drvdata(hdev);
0132
0133 if (!data->num_function_row_keys)
0134 return 0;
0135
0136 return devm_device_add_group(&hdev->dev, &vivaldi_attribute_group);
0137 }
0138 EXPORT_SYMBOL_GPL(vivaldi_input_configured);
0139
0140 MODULE_LICENSE("GPL");