aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/i2c-hid/i2c-hid.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hid/i2c-hid/i2c-hid.c')
-rw-r--r--drivers/hid/i2c-hid/i2c-hid.c73
1 files changed, 46 insertions, 27 deletions
diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c
index 3cb7d966da9e..c1336193b04b 100644
--- a/drivers/hid/i2c-hid/i2c-hid.c
+++ b/drivers/hid/i2c-hid/i2c-hid.c
@@ -35,6 +35,7 @@
35#include <linux/hid.h> 35#include <linux/hid.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/acpi.h> 37#include <linux/acpi.h>
38#include <linux/of.h>
38 39
39#include <linux/i2c/i2c-hid.h> 40#include <linux/i2c/i2c-hid.h>
40 41
@@ -756,29 +757,6 @@ static int i2c_hid_power(struct hid_device *hid, int lvl)
756 return ret; 757 return ret;
757} 758}
758 759
759static int i2c_hid_hidinput_input_event(struct input_dev *dev,
760 unsigned int type, unsigned int code, int value)
761{
762 struct hid_device *hid = input_get_drvdata(dev);
763 struct hid_field *field;
764 int offset;
765
766 if (type == EV_FF)
767 return input_ff_event(dev, type, code, value);
768
769 if (type != EV_LED)
770 return -1;
771
772 offset = hidinput_find_field(hid, type, code, &field);
773
774 if (offset == -1) {
775 hid_warn(dev, "event field not found\n");
776 return -1;
777 }
778
779 return hid_set_field(field, offset, value);
780}
781
782static struct hid_ll_driver i2c_hid_ll_driver = { 760static struct hid_ll_driver i2c_hid_ll_driver = {
783 .parse = i2c_hid_parse, 761 .parse = i2c_hid_parse,
784 .start = i2c_hid_start, 762 .start = i2c_hid_start,
@@ -787,7 +765,6 @@ static struct hid_ll_driver i2c_hid_ll_driver = {
787 .close = i2c_hid_close, 765 .close = i2c_hid_close,
788 .power = i2c_hid_power, 766 .power = i2c_hid_power,
789 .request = i2c_hid_request, 767 .request = i2c_hid_request,
790 .hidinput_input_event = i2c_hid_hidinput_input_event,
791}; 768};
792 769
793static int i2c_hid_init_irq(struct i2c_client *client) 770static int i2c_hid_init_irq(struct i2c_client *client)
@@ -897,8 +874,9 @@ static int i2c_hid_acpi_pdata(struct i2c_client *client,
897 params[1].integer.value = 1; 874 params[1].integer.value = 1;
898 params[2].type = ACPI_TYPE_INTEGER; 875 params[2].type = ACPI_TYPE_INTEGER;
899 params[2].integer.value = 1; /* HID function */ 876 params[2].integer.value = 1; /* HID function */
900 params[3].type = ACPI_TYPE_INTEGER; 877 params[3].type = ACPI_TYPE_PACKAGE;
901 params[3].integer.value = 0; 878 params[3].package.count = 0;
879 params[3].package.elements = NULL;
902 880
903 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_DSM", &input, &buf))) { 881 if (ACPI_FAILURE(acpi_evaluate_object(handle, "_DSM", &input, &buf))) {
904 dev_err(&client->dev, "device _DSM execution failed\n"); 882 dev_err(&client->dev, "device _DSM execution failed\n");
@@ -933,6 +911,42 @@ static inline int i2c_hid_acpi_pdata(struct i2c_client *client,
933} 911}
934#endif 912#endif
935 913
914#ifdef CONFIG_OF
915static int i2c_hid_of_probe(struct i2c_client *client,
916 struct i2c_hid_platform_data *pdata)
917{
918 struct device *dev = &client->dev;
919 u32 val;
920 int ret;
921
922 ret = of_property_read_u32(dev->of_node, "hid-descr-addr", &val);
923 if (ret) {
924 dev_err(&client->dev, "HID register address not provided\n");
925 return -ENODEV;
926 }
927 if (val >> 16) {
928 dev_err(&client->dev, "Bad HID register address: 0x%08x\n",
929 val);
930 return -EINVAL;
931 }
932 pdata->hid_descriptor_address = val;
933
934 return 0;
935}
936
937static const struct of_device_id i2c_hid_of_match[] = {
938 { .compatible = "hid-over-i2c" },
939 {},
940};
941MODULE_DEVICE_TABLE(of, i2c_hid_of_match);
942#else
943static inline int i2c_hid_of_probe(struct i2c_client *client,
944 struct i2c_hid_platform_data *pdata)
945{
946 return -ENODEV;
947}
948#endif
949
936static int i2c_hid_probe(struct i2c_client *client, 950static int i2c_hid_probe(struct i2c_client *client,
937 const struct i2c_device_id *dev_id) 951 const struct i2c_device_id *dev_id)
938{ 952{
@@ -954,7 +968,11 @@ static int i2c_hid_probe(struct i2c_client *client,
954 if (!ihid) 968 if (!ihid)
955 return -ENOMEM; 969 return -ENOMEM;
956 970
957 if (!platform_data) { 971 if (client->dev.of_node) {
972 ret = i2c_hid_of_probe(client, &ihid->pdata);
973 if (ret)
974 goto err;
975 } else if (!platform_data) {
958 ret = i2c_hid_acpi_pdata(client, &ihid->pdata); 976 ret = i2c_hid_acpi_pdata(client, &ihid->pdata);
959 if (ret) { 977 if (ret) {
960 dev_err(&client->dev, 978 dev_err(&client->dev,
@@ -1095,6 +1113,7 @@ static struct i2c_driver i2c_hid_driver = {
1095 .owner = THIS_MODULE, 1113 .owner = THIS_MODULE,
1096 .pm = &i2c_hid_pm, 1114 .pm = &i2c_hid_pm,
1097 .acpi_match_table = ACPI_PTR(i2c_hid_acpi_match), 1115 .acpi_match_table = ACPI_PTR(i2c_hid_acpi_match),
1116 .of_match_table = of_match_ptr(i2c_hid_of_match),
1098 }, 1117 },
1099 1118
1100 .probe = i2c_hid_probe, 1119 .probe = i2c_hid_probe,