diff options
Diffstat (limited to 'drivers/hid/i2c-hid/i2c-hid.c')
-rw-r--r-- | drivers/hid/i2c-hid/i2c-hid.c | 72 |
1 files changed, 45 insertions, 27 deletions
diff --git a/drivers/hid/i2c-hid/i2c-hid.c b/drivers/hid/i2c-hid/i2c-hid.c index d2e0eea2bf79..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 | ||
759 | static 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 | |||
782 | static struct hid_ll_driver i2c_hid_ll_driver = { | 760 | static 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 | ||
793 | static int i2c_hid_init_irq(struct i2c_client *client) | 770 | static int i2c_hid_init_irq(struct i2c_client *client) |
@@ -824,8 +801,8 @@ static int i2c_hid_fetch_hid_descriptor(struct i2c_hid *ihid) | |||
824 | * bytes 2-3 -> bcdVersion (has to be 1.00) */ | 801 | * bytes 2-3 -> bcdVersion (has to be 1.00) */ |
825 | ret = i2c_hid_command(client, &hid_descr_cmd, ihid->hdesc_buffer, 4); | 802 | ret = i2c_hid_command(client, &hid_descr_cmd, ihid->hdesc_buffer, 4); |
826 | 803 | ||
827 | i2c_hid_dbg(ihid, "%s, ihid->hdesc_buffer: %*ph\n", | 804 | i2c_hid_dbg(ihid, "%s, ihid->hdesc_buffer: %4ph\n", __func__, |
828 | __func__, 4, ihid->hdesc_buffer); | 805 | ihid->hdesc_buffer); |
829 | 806 | ||
830 | if (ret) { | 807 | if (ret) { |
831 | dev_err(&client->dev, | 808 | dev_err(&client->dev, |
@@ -934,6 +911,42 @@ static inline int i2c_hid_acpi_pdata(struct i2c_client *client, | |||
934 | } | 911 | } |
935 | #endif | 912 | #endif |
936 | 913 | ||
914 | #ifdef CONFIG_OF | ||
915 | static 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 | |||
937 | static const struct of_device_id i2c_hid_of_match[] = { | ||
938 | { .compatible = "hid-over-i2c" }, | ||
939 | {}, | ||
940 | }; | ||
941 | MODULE_DEVICE_TABLE(of, i2c_hid_of_match); | ||
942 | #else | ||
943 | static 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 | |||
937 | static int i2c_hid_probe(struct i2c_client *client, | 950 | static int i2c_hid_probe(struct i2c_client *client, |
938 | const struct i2c_device_id *dev_id) | 951 | const struct i2c_device_id *dev_id) |
939 | { | 952 | { |
@@ -955,7 +968,11 @@ static int i2c_hid_probe(struct i2c_client *client, | |||
955 | if (!ihid) | 968 | if (!ihid) |
956 | return -ENOMEM; | 969 | return -ENOMEM; |
957 | 970 | ||
958 | 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) { | ||
959 | ret = i2c_hid_acpi_pdata(client, &ihid->pdata); | 976 | ret = i2c_hid_acpi_pdata(client, &ihid->pdata); |
960 | if (ret) { | 977 | if (ret) { |
961 | dev_err(&client->dev, | 978 | dev_err(&client->dev, |
@@ -1096,6 +1113,7 @@ static struct i2c_driver i2c_hid_driver = { | |||
1096 | .owner = THIS_MODULE, | 1113 | .owner = THIS_MODULE, |
1097 | .pm = &i2c_hid_pm, | 1114 | .pm = &i2c_hid_pm, |
1098 | .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), | ||
1099 | }, | 1117 | }, |
1100 | 1118 | ||
1101 | .probe = i2c_hid_probe, | 1119 | .probe = i2c_hid_probe, |